Uten Posted June 12, 2006 Posted June 12, 2006 According to the help file I'm to use Switch like this: Switch <exp[b][/b]ression> Case <value> [To <value>] [,<value> [To <value>] ...] statement1 ... [Case <value> [To <value>] [,<value> [To <value>] ...] statement2 ...] [Case Else statementN ...] EndSwitchoÝ÷ Ù8b²×¬µÊzÈhÂËajÙ¢Æ)àéz»Û-®)à²)ÂjÇ¡ë'¢Úek*.¶X¤yìiyË^u«¢+Ù ½¹Í½±]É¥Ñ ÅÕ½ÐíÕѽ%ÑYÉÍ¥½¸èôÅÕ½ÐìµÀìÕѽ%ÑYÉÍ¥½¸µÀì1¤)QÍÑMÝ¥Ñ ÅÕ½ÐìÅÕ½Ðì¤)QÍÑMÝ¥Ñ À¤)QÍÑMÝ¥Ñ ÅÕ½Ðí= This is my result running the code (NOTICE how TestSwitch("FOO") fails): >"Z:\scite\..\autoit3tools\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /beta /ErrorStdOut /in "Z:\Code\autoit\au3\foo.au3" /autoit3dir "Z:\scite\..\autoit-v3.1.1.126" /UserParams >Running AU3Check params: from:Z:\autoit3tools\au3check\ +>AU3Check ended.rc:0 >Running:(3.1.1.126):Z:\scite\..\autoit-v3.1.1.126\autoit3.exe "Z:\Code\autoit\au3\foo.au3" @AutoItVersion:=3.1.1.126 $ret:= $ret:= $ret:= $ret:=TEST +>AutoIT3.exe ended.rc:0 >Exit code: 0 Time: 3.938 Did I misunderstand Switch usage or have I done anything else wrong? Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling
Xenobiologist Posted June 12, 2006 Posted June 12, 2006 HI, does it generally work with letters??? (No mix, just letters) I thought, it will only work with digits. So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
Uten Posted June 12, 2006 Author Posted June 12, 2006 I have reached the same conclusion. The confusing thing is that "" and 0 is evaluated equally. But I think that is a feature of the language. Thanks. Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling
GaryFrost Posted June 12, 2006 Posted June 12, 2006 try converting the test to a string for the comparison otherwise you'll have all kinds of problems ConsoleWrite("@AutoItVersion:=" & @AutoItVersion & @LF) TestSwitch("") TestSwitch(0) TestSwitch("FOO") TestSwitch(1) TestSwitch(2) exit func TestSwitch($msg) Local $ret Switch String($msg) Case "0", "" $ret = "Empty" case "1", "TEST" $ret = "TEST" case "2", "FOO" $ret = "FOO" case Else $ret = "UNKNOW" EndSwitch ConsoleWrite('$ret:=' & $ret & @LF) EndFunc SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
Valuater Posted June 12, 2006 Posted June 12, 2006 I read the help file as "Value".... thus, "foo" has a value of 0 here is how i would handle the sictch ConsoleWrite("@AutoItVersion:=" & @AutoItVersion & @LF) TestSwitch("") TestSwitch(0) TestSwitch("FOO") TestSwitch(1) TestSwitch(7) TestSwitch(11) TestSwitch("Not there") Exit Func TestSwitch($msg = "") Local $ret Select Case $msg == "" $ret = "NADA" Case $msg == "FOO" $ret = "TEST-1" Case $msg == 0 Or $msg > 0 Switch $msg Case 0 $ret = "No Value" Case 1 $ret = "TEST-2" Case 2,3,4,5 to 10 $ret = "FOO Number" Case Else $ret = "UNKNOW" EndSwitch Case Else MsgBox(0, "", "No preceding case was true!") EndSelect ConsoleWrite('$ret:=' & $ret & @LF) EndFunc ;==>TestSwitch 8)
Uten Posted June 12, 2006 Author Posted June 12, 2006 OK, I'm satisfied Thanks to @gafrost for showing that you can use strings in the test parameter as long as they are all strings. I could swear I had used strings before so I got really puzzled when my mixed thing did not work out. Thanks to @valuater for providing a mixed sample using Select for strings and Switch for numeric parameters. Thanks to all of you Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now