sykes Posted March 9, 2004 Posted March 9, 2004 I gots a coupla kweshuns ... OK ... I know this has been answered allready, but what is the difference between using = and == in comparison statements? And... Is there a way to have 0043 and 43 be recognized as the same numerically without stripping the 00's out? We have enough youth. How about a fountain of SMART?
Administrators Jon Posted March 9, 2004 Administrators Posted March 9, 2004 == forces a case sensitive string comparision. $a = "0043" $b = "43" If Number($a) = Number($b) Then MsgBox(0, "", "Equal")
sykes Posted March 9, 2004 Author Posted March 9, 2004 Thanks Jon One more thing ... Is it possible to use something like this: If $var = "012" or "145" or "023" Then <Do Something> Just need to know how to compare more than one value in the same line of code Thanks again We have enough youth. How about a fountain of SMART?
Administrators Jon Posted March 9, 2004 Administrators Posted March 9, 2004 If $var = "012" or $var = "145" or $var = "023" Then <Do Something>
sykes Posted March 9, 2004 Author Posted March 9, 2004 At the risk of becoming a pest, can I place these numeric values in an array and do the comparison that way? Would it decrease any lines of code or take just as much either way? **Exiting Pest mode** We have enough youth. How about a fountain of SMART?
scriptkitty Posted March 9, 2004 Posted March 9, 2004 (edited) $test=Stringsplit("012,145,023",",") $var=12 $go="" for $i=1 to $test[0] If $var = $test[$i] Then $go="Y" next if $go="Y" then msgbox(1,"","worked");<do something> I have a few more lines than it would take, but example is easy to read I hope. I use a bunch of Functions, so although it might not take up less lines, it may be a lot easier to debug and might look like: $test=Stringsplit("012,145,023",",") $var=12 For $i=1 to $test[0] If $var = $test[$i] Then dosomething() next Func dosomething() MsgBox(1,"Something","wicked this way comes..",5) EndFunc If you had say 700 variables it would save a lot of time, and I have done this. I had two lists and did a comparision. (one from a local file, and the other from a web file) Edited March 10, 2004 by scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers.
sykes Posted March 10, 2004 Author Posted March 10, 2004 $test=Stringsplit("012,145,023",",") $var=12 $go="" for $i=1 to $test[0] If $var = $test[$i] Then $go="Y" next if $go="Y" then msgbox(1,"","worked");<do something>Thats the ticket ... exactly what i need. Now all i have to do is add a loop and I think this will work perfectly. Thanks Jon and Scriptkitty We have enough youth. How about a fountain of SMART?
sykes Posted March 10, 2004 Author Posted March 10, 2004 OK ... I just can't seem to shut up tonight. LOL Here's a question I can't remember seeing... Can an array contain other arrays? We have enough youth. How about a fountain of SMART?
scriptkitty Posted March 10, 2004 Posted March 10, 2004 (edited) Not really, ;test $bill=StringSplit("4,5,6",",") dim $notreally[2] $notreally[0]=4 $notreally[1]=$bill MsgBox(1,"not really",$notreally[1]) doesn't really prove anything, but. A better question would be why? Remember Arrays do not have to only be single. Dim $array[2][3][4] For $i=0 To 1 For $y=0 To 2 For $x=0 To 3 $array[$i][$y][$x]=$i&"/"&$y&"/"&$x Next Next Next For $i=0 To 1 For $y=0 To 2 For $x=0 To 3 MsgBox(1,$i&" "&$y&" "&$x,$array[$i][$y][$x]) Next Next Next Edited March 10, 2004 by scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers.
CyberSlug Posted March 10, 2004 Posted March 10, 2004 What about something like: If StringInStr("012,145,023" , $var) Then <Do Something> Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
scriptkitty Posted March 10, 2004 Posted March 10, 2004 I would have suggested, but what if: $var=2 If StringInStr("012,145,023" , $var) Then Do Something() AutoIt3, the MACGYVER Pocket Knife for computers.
sykes Posted March 10, 2004 Author Posted March 10, 2004 I was able to throw the values into a array and use StringInStr to make it work with minimal code. It works fine since the values i will need to be comparing are always 3 digits. Thanks again to all for your input. We have enough youth. How about a fountain of SMART?
trids Posted March 10, 2004 Posted March 10, 2004 I would have suggested, but what if: $var=2 If StringInStr("012,145,023" , $var) Then Do Something()A good way to avoid this is to include delimiters in your target .. If StringInStr(":012:145:023:" , ":" & $var & ":") Then Do Something() Of course .. this is all just a temporary workaround until the built-in / intrinsic / inbuilt ( ) function called In() is available .. right? .. Eg:;Searching for a String value If $var In ("012","145","023", $sX, StringMid($sY, $nA, 3) ) Then DoSomething() Endif ;Searching for a Numeric value If $var In (12,145,23, $nX, Number(StringMid($sY, $nA, 3)) ) Then DoSomething() Endif
CyberSlug Posted March 10, 2004 Posted March 10, 2004 Genius, Trids! I would have suggested checking StringLen($var) = 3 or whatever Your proposed In-syntax is messy. Two quote marks + one comma = a lot of baggage. However, I still would like your proposed Select Case, Better(?) syntax Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
trids Posted March 19, 2004 Posted March 19, 2004 (edited) Shucks .. thanks sluggie! As for the In() function: I have to confess , I borrowed the idea from SQL syntax. But it's not so messy if you think about it: the parameters are simply a list of values separated by commas. If a value is a literal string, then it gets quoted. See .. not so burdensome?The enhanced Select Case is also borrowed (this time from VB ). But thanks for your kind support - I guess it's you and me against the world!<< .. let's attack! >> Edited March 19, 2004 by trids
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