AutID Posted August 7, 2013 Share Posted August 7, 2013 Hello, $1 = "Q" $2 = "W" $3 = "Y" $4 = "U" $5 = "S" $c = "Y" Is there a way to compare $c with these variables and find which one is the right one without having to use an if/elseif/endif statement??? I tried a stringinstr but not much success. https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
kylomas Posted August 7, 2013 Share Posted August 7, 2013 AutId, Here is one way: $1 = "Q" $2 = "W" $3 = "Y" $4 = "U" $5 = "S" $c = "Y" for $1 = 1 to 5 if eval($1) = $c then consolewrite('$' & $1 & ' is equal' & @lf) next However, if you are interested in storing values for later lookup there are much better techniques than individual variables. If you explain a little about what you are doing you will receive a better answer. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
AZJIO Posted August 7, 2013 Share Posted August 7, 2013 (edited) StringCompare AutID, Your script doesn't show, than "if/elseif/endif" is bad $1 = "Q" $2 = "W" $3 = "Y" $4 = "U" $5 = "S" $c = "Y" If $1 = "Q" And $2 = "W" And $3 = "Y" And $4 = "U" And $5 = "S" Then MsgBox(0, ';)', 'Yes') Edited August 7, 2013 by AZJIO My other projects or all Link to comment Share on other sites More sharing options...
jchd Posted August 7, 2013 Share Posted August 7, 2013 kylomas, What if $c is "Q"? AZJIO, AutID wants to compare $c to $1 to $5. What is your example doing, exactly? AutID, It would be easier to use an array: #Include <Array.au3> Local $Values[5] = ["Q", "W", "Y", "U", "S"] Local $c = "Y" Local $Index = _ArraySearch($Values, $c) If $index >= 0 Then ConsoleWrite("$c was found in $Values at index " & $index & @LF) Else ConsoleWrite("$c was not found in $Values" & @LF) EndIf You can also use Select...Case...EndSelect. 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
kylomas Posted August 7, 2013 Share Posted August 7, 2013 @jchd - Ha! How stupid, I overwrite the value of $1...thanks. However, if you are interested in storing values for later lookup there are much better techniques than individual variables. If you explain a little about what you are doing you will receive a better answer. This stands however. You used an array but it could also be a string. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Gianni Posted August 7, 2013 Share Posted August 7, 2013 OP has explicitly requested "without having to use an if / elseif / endif statement"maybe he meant something like this (no command IF it's required) $1 = "Q" $2 = "W" $3 = "Y" $4 = "U" $5 = "S" $c = "Y" dim $oracle[2] = ["not equal","equal"] for $1 = 1 to 5 ConsoleWrite("$" & $1 & " " & $oracle[(eval($1) == $c)] & " $c" & @crlf) next bye Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
BrewManNH Posted August 7, 2013 Share Posted August 7, 2013 @PincoPanco, you have a bug in your script. This will prevent your script from comparing $c to $1 so if $c = "Q", the script displays all as "not equal". $1 = "Q" $2 = "W" $3 = "Y" $4 = "U" $5 = "S" $c = "Y" dim $oracle[2] = ["not equal","equal"] for $1 = 1 to 5 ; <<<<<<<<<<<<<<<<<<<<< you're reusing the variable $1 ConsoleWrite("$" & $1 & " " & $oracle[(eval($1) == $c)] & " $c" & @crlf) next Gianni 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Gianni Posted August 7, 2013 Share Posted August 7, 2013 opsBrewManNH you're rightI modified kylomas's example from post >#2 without changing the loop variableusing a different loop variable name works well $1 = "Q" $2 = "W" $3 = "Y" $4 = "U" $5 = "Y" $c = "Q" dim $oracle[2] = ["not equal","equal"] for $X = 1 to 5 ConsoleWrite("$" & $X & " " & $oracle[(eval($X) == $c)] & " $c" & @crlf) next Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
AutID Posted August 7, 2013 Author Share Posted August 7, 2013 kylomas, What if $c is "Q"? AZJIO, AutID wants to compare $c to $1 to $5. What is your example doing, exactly? AutID, It would be easier to use an array: #Include <Array.au3> Local $Values[5] = ["Q", "W", "Y", "U", "S"] Local $c = "Y" Local $Index = _ArraySearch($Values, $c) If $index >= 0 Then ConsoleWrite("$c was found in $Values at index " & $index & @LF) Else ConsoleWrite("$c was not found in $Values" & @LF) EndIf You can also use Select...Case...EndSelect. Tu es le seul qui a compris I came up with this after jchd's sample. #Include <Array.au3> $1 = "Q" $2 = "W" $3 = "Y" $4 = "U" $5 = "S" Local $Values[5] = [$1, $2, $3, $4, $5] Local $c = "Y" Local $Index = _ArraySearch($Values, $c) ConsoleWrite($Values[$index] & @LF) https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
BrewManNH Posted August 8, 2013 Share Posted August 8, 2013 I thought you wanted to avoid using If/ElseIf/Else? _ArraySearch is loaded with them. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
AutID Posted August 8, 2013 Author Share Posted August 8, 2013 I thought you wanted to avoid using If/ElseIf/Else? _ArraySearch is loaded with them. They are not in my script though https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
BrewManNH Posted August 9, 2013 Share Posted August 9, 2013 Actually, yes they are, they aren't in what you wrote, but they're definitely in your script. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
AutID Posted August 9, 2013 Author Share Posted August 9, 2013 Actually, yes they are, they aren't in what you wrote, but they're definitely in your script. You know what I mean... https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
Gianni Posted August 9, 2013 Share Posted August 9, 2013 I agree with BrewManNH That _ArraySearch is full of "IF" (you do not see them only because they hid behind #Include <Array.au3> and what will happens to your code if "Y" are more than 1, or even worse, none? well, allowing the use of #include <Array.au3>, can you manage that cases? (without the "IF" statement ofcourse) if you need a tip as well ask Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Edano Posted August 9, 2013 Share Posted August 9, 2013 (edited) wow, is this still hot or a competition ??? . $1 = "Q" $2 = "W" $3 = "Y" $4 = "U" $5 = "S" $c = "Y" $string=$1&$2&$3&$4&$5 MsgBox(0,"",StringInStr($string,$c)) . E. Edit: of course, using includes is cheating. you could include every au3 script you want, even self written. this is cheating Edited August 9, 2013 by Edano [color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font] Link to comment Share on other sites More sharing options...
Edano Posted August 9, 2013 Share Posted August 9, 2013 (edited) and if you want casesense and occurence, take this: . $1 = "Q" $2 = "W" $3 = "Y" $4 = "U" $5 = "S" $6 = "Y" $c = "Y" $i=0 $string=$1&$2&$3&$4&$5&$6 Do $i+=1 $ret=StringInStr($string,$c,1,$i) MsgBox(0,"",$ret) Until $ret=0 MsgBox(0,"",StringTrimRight("no (more)",7*($i=0))&" '"&$c&"' found.") . no "if" Edit: Bool is not "If" Edited August 9, 2013 by Edano [color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font] Link to comment Share on other sites More sharing options...
Gianni Posted August 9, 2013 Share Posted August 9, 2013 and if you want casesense and occurence, take this: . $1 = "Q" $2 = "W" $3 = "Y" $4 = "U" $5 = "S" $6 = "Y" $c = "Y" $i=0 $string=$1&$2&$3&$4&$5&$6 Do $i+=1 $ret=StringInStr($string,$c,1,$i) MsgBox(0,"",$ret) Until $ret=0 MsgBox(0,"",StringTrimRight("no (more)",6*($i=0))&" '"&$c&"' found.") . no "if" Edit: Bool is not "If" it finds one more, even if there are not Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Edano Posted August 9, 2013 Share Posted August 9, 2013 nonono, zero is defined as failure ! [color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font] Link to comment Share on other sites More sharing options...
Gianni Posted August 9, 2013 Share Posted August 9, 2013 better without the view of that failure.... Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Edano Posted August 9, 2013 Share Posted August 9, 2013 (edited) $1 = "Q" $2 = "W" $3 = "Y" $4 = "U" $5 = "S" $6 = "Y" $c = "Y" $i=0 $string=$1&$2&$3&$4&$5&$6 Do $i+=1 $ret=StringInStr($string,$c,1,$i) MsgBox(0,"",StringReplace($ret,"0","that's all")) Until $ret=0 MsgBox(0,"",StringTrimRight("no (more)",7*($i=0))&" '"&$c&"' found.") Edited August 9, 2013 by Edano [color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font] Link to comment Share on other sites More sharing options...
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