Sign in to follow this  
Followers 0
DreamVB

My Switch is returning wrong help

6 posts in this topic

I am trying to use a switch statement to compare chars eg A-Z so if a vaild chat such as A is sent then it will returm true, say you pass something like ÿ it will return false but it seems to return true. very odd like

Func IsInSet($char)
    Switch StringUpper($char)
        Case "A" To "Z", "a" To "z"
            Return 1
        Case Else
            Return 0
    EndSwitch
EndFunc   ;==>IsInSet

MsgBox(1, "", IsInSet("ÿ")) ; This seems to return 1 even tho it not even in the set why?

On Error Resume Pulling Hair Out.

Share this post


Link to post
Share on other sites



That looks like a bug with the Switch statement in this case. I advise you post a ticket.

In the meantime you can simply use this:

MsgBox(1, "", StringRegExp("ÿ", "[[:alpha:]]"))
1 person likes this

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

hi Thanks for the reply I did however find another way around using the values of the chars and seems to work.

Func IsInSet($char)
    Switch Asc(StringUpper($char))
        Case 48 To 57
            Return 1
        Case 65 To 90
            Return 1
        case 32
            Return 1
        Case Else
            Return False
    EndSwitch
EndFunc   ;==>IsInSet

MsgBox(1,"",IsInSet("ÿ"))

On Error Resume Pulling Hair Out.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I think that the Switch statement is to be used with "numeric" values, expecially if you use the range parameter <value> To <Value>
in fact the documentation says <Value> an not <expression> when referring to the range.
it seems that the use of "Strings" it works as well, only if you compare a single <expression> in the Switch construct and not using the "To" parameter as range separator.
In case of the need to compare ranges you could transform "A" to "Z" in numeric values, for example Asc("A") to Asc("Z") and in this way it works.

Func IsInSet($char)
    Switch Asc(StringUpper($char))
        Case Asc("A") To Asc("Z"), Asc("a") To Asc("z")
            Return 1
        Case Else
            Return 0
    EndSwitch
EndFunc   ;==>IsInSet

MsgBox(1, "", IsInSet("ÿ")) ; This seems to return 1 even tho it not even in the set why
Edited by Chimp
1 person likes this

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Beware that by using Asc() instead of AscW() you force a conversion to ANSI. That could silently bite you hard.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Why are you checking the range of lowercase letters when you have already converted the character to uppercase? Am I missing something?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0