Jump to content

My Switch is returning wrong help


DreamVB
 Share

Go to solution Solved by Gianni,

Recommended Posts

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.

Link to comment
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:]]"))

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)

Link to comment
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.

Link to comment
Share on other sites

  • Solution

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

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
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)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...