Jump to content

= Vs ==


Recommended Posts

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? :whistle:

We have enough youth. How about a fountain of SMART?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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** :whistle:

We have enough youth. How about a fountain of SMART?

Link to comment
Share on other sites

$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 by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

$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 :whistle:

We have enough youth. How about a fountain of SMART?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

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. :whistle:

We have enough youth. How about a fountain of SMART?

Link to comment
Share on other sites

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 ( B) ) function called In() is available .. right? .. :whistle:

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

Genius, Trids! I would have suggested checking StringLen($var) = 3 or whatever :evil::angry:

Your proposed In-syntax is messy. Two quote marks + one comma = a lot of baggage. :whistle:

However, I still would like your proposed Select Case, Better(?) syntax B)

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

  • 2 weeks later...

:whistle: Shucks .. thanks sluggie!

As for the In() function: I have to confess B) , 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 :lmao: ). But thanks for your kind support - I guess it's you and me against the world!

<< .. let's attack! :evil::angry: >>

Edited by trids
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...