Source language: Translate to:

Need a "Case Sensitive" option for the IF command

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Need a "Case Sensitive" option for the IF command

Postby Enigman » Tue Mar 27, 2012 9:02 am

I would rejoice if we could have a case sensitive option for the IF and IFEx commands. In the following code:
Code: Select all
SetVar "[Char]" "A"

IfEx "[Char] = [#34]A[#34]"
     AlertBox "" "Cap is True"
EndIf

IfEx "[Char] = [#34]a[#34]"
     AlertBox "" "Lower is True"
EndIf

... both If blocks evaluate True no matter what case [Char] is. Right now the only way I can do a case sensitive evaluation is to use the SearchStr command with case sensitive turned on. Then I have to do something like:
Code: Select all
SetVar "[String]" "ABCDEFGH"
SetVar "[Char]" "a"

SearchStr "[Char]" "[String]" "[Offset]" "CaseSensitive"

IfEx "[Offset] > 0"
     AlertBox "" "Cap is True"
EndIf

IfEx "[Offset] = 0"
     AlertBox "" "Lower is True"
EndIf

Certainly not foolproof in all implementations. I would much rather see the ability to do this:
Code: Select all
SetVar "[Char]" "A"

IfEx "[Char] = A" "CaseSensitive"
     AlertBox "" "Cap is True"
EndIf

IfEx "[Char] = a" "CaseSensitive"
     AlertBox "" "Lower is True"
EndIf

... and have it evaluate true to only the correct case.

It would also be nice to be able to have the DefineVar command be able to specify that a given array or variable name is case sensitive. For example, when one is trying to load an array with ascii numbers for characters it is logical to assign the array names like "[CharValue[Char]]" to be equal to the ascii number for a [Char]. If I do that then [CharValuea] and [CharValueA] are equivalent with the lowercase version being the default. This could be avoided with a variable name that is known to the system as being case sensitive.

All of the above could also be achieved with a publication specific option that says that all variable names and string comparisons are case sensitive.
User avatar
Enigman
 
Posts: 314
Joined: Tue Apr 12, 2005 3:57 pm
Location: Foothill Ranch, CA

Postby dec » Tue Mar 27, 2012 9:16 am

Hi,

Why not you "normalize" your statements? In other words, made something like in this code:

Code: Select all

StrLower "[Char]" "[Char]"

If "[Char]" "=" "a"
  .Act here
EndIf


StrUpper "[Char]" "[Char]"

If "[Char]" "=" "A"
  .Act here
EndIf


So, if you look for "lower strings", you can convert the first term in the "If" to lower case. If you look for "upper strings", you cna convert the first item to upper case. Also you can convert the two "if" elements to one "lower" or "upper".

I'am not sure if can understand (and explain) very well, but I never view in any language a "case sensitive IF", but view many times how the terms of the "IF" are converted to lower or upper case in order to make some comparisons.

Hope this can help you in some manner. ;)
.
Enhance your NeoBook applications!
.
58 plugins, 1131 actions and 233 samples
.
NeoPlugins website: www.neoplugins.com
.
User avatar
dec
 
Posts: 1663
Joined: Wed Nov 16, 2005 12:48 am
Location: Spain

Postby Enigman » Tue Mar 27, 2012 9:45 am

I think understand what you are describing, but that amounts to forcing the case of the character to suit the If block. I need it the other way around. I need the IF to correctly react to the case of the [Char] variable without me shoving it to upper or lower. In my app I am reading character values and reacting to what they actually are.

In your code example, both IF blocks would evaluate true since
Code: Select all
If "[Char]" "=" "a"

and

If "[Char]" "=" "A"

...both mean the same thing. No matter the case of [Char], both IFs would be true.

I never view in any language a "case sensitive IF"

That's because in other languages the entire syntax is case sensitive by default. Those IFs used different operators for string comparisons. You use "=" for numeric comparisons and "==" for string comparisons against a literal string or variable. Variable names of "AlphaChar" and "alphachar" are two different names and treated separately, just as literal strings of "Alpha" and "alpha" are treated as two different strings. Not so in NB.

NB has had its IF simplified for ease of use along with variable names. Case sensitivity has been taken out to make things easier. The trouble is, when you start doing more complex things with NB, you sometimes need that case sensitivity back for variables and comparisons. That's why it reappeared for SearchStr I assume. I would like to see the options I described to re-enable case sensitivity for variables and IF comparisons.
User avatar
Enigman
 
Posts: 314
Joined: Tue Apr 12, 2005 3:57 pm
Location: Foothill Ranch, CA

Postby dpayer » Tue Mar 27, 2012 10:19 am

I don't have time at the moment to write a vb script for this but if you feel inclined, here are some resources to do that.

You can evaluate a character or a string into its ascii number equivalent. Here is someone who did that here:

http://forums.aspfree.com/code-bank-54/ ... 41267.html

You could also output his string with a & "," & inserted between the new character and the previously coded characters and then you would have a list separated by commas. (also you could convert them to hex then they are all 2 digit).

Once you use this function against a string, the resultant string of numbers will show a difference between "A" (ascii=65) and "a" (ascii = 97).

Here is a ascii code table:
http://ascii.cl/htmlcodes.htm

Here are some tutorials on VB scripting that apply:
http://www.w3schools.com/vbscript/func_asc.asp
http://www.w3schools.com/vbscript/vbscr ... ctions.asp

You could create a function that would let you compare:
Code: Select all
call  "comparefunction" [%1] [%2]


Where %1 / %2 are the two string variables

David P.
Last edited by dpayer on Tue Mar 27, 2012 11:01 am, edited 1 time in total.
User avatar
dpayer
 
Posts: 1383
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Postby Enigman » Tue Mar 27, 2012 10:39 am

Thanks dpayer,

I have already developed the algorithm I need in NB to get ascii numbers without failures due to case changes. Because of the case insensitive nature of the IF command I had to do it another way using the SearchStr command to determine case (as shown above). Then I use one of two different arrays to extract the ascii number in unpadded form, one for upper case A thru Z and one for the full ascii set. That way I first change to the correct array based on the sample character case, then do a direct array lookup.

Using arrays is much faster in execution than using two huge strings to examine and cut out pieces.

I started the "wish list" thread here for the sake of future implementations of this requirement and for other NB users. It would have been so much easier to develop an ascii lookup with more case sensitive commands.

Thanks again.
User avatar
Enigman
 
Posts: 314
Joined: Tue Apr 12, 2005 3:57 pm
Location: Foothill Ranch, CA

Postby Neosoft Support » Tue Mar 27, 2012 10:47 am

This will work:

Code: Select all
SetVar "[Char]" "A"

If "![Char]" "=" "!A"
     AlertBox "" "Cap is True"
EndIf

If "![Char]" "=" "!a"
     AlertBox "" "Lower is True"
EndIf
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5603
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 1 guest