Jump to content

lame question... 0<>'b'


oren
 Share

Recommended Posts

I have a array and I have a loop that go on all the array objects..

Now each time have have something that is no "b" in the array I do something..

But its seems that I can not compare numbers with stings..

this does not write

if 0<>"b" Then
    ConsoleWrite("haevy metal")
EndIf
While 1
    WEnd

Any Idea how do I do it..

How to I get that 0 <> "b" , the real code is

for $i = 0 to 100

if $array[$i]<>"b" Then
    UpdateTable()
EndIf
next

The array contain letters and numbers,

Thank you.

Edited by oren
Link to comment
Share on other sites

We'll need more information such as the contents of the array or just the whole rest of the code.

Edited by jaberwocky6669
Link to comment
Share on other sites

Are you saying that if there is no letter "b" in the (array) element element do something? If so, why not do

If Not StringInStr($array[$i], 'b') Then
If $Array[$i] begins with a non-digit, mathematically it's value is zero ("joules1000" mathematically is zero); if it begins with a digit, it's value is read until the first non-digit exists ("1000joules" mathematically is one thousand). Be aware that "0joulespersecond" mathematically returns zero, since math stops on the letter "j" and the only number(s) before that are zero. Periods or dots do not count in the digit reading

Edited by Varian
Link to comment
Share on other sites

Oren,

1. You should probably verify if your $array is actually an array = IsArray().

2. Try _ArrayDisplay() your $array to see if you have actually your data in there

3. The field $array[$i], you want to know if the letter 'b' is in the text like a SQL: WHERE a_field LIKE '%b%' ? then try Varian's solution StringInStr() .

[font="Lucida Sans Unicode"]M a k. a v e L ![/font]

Link to comment
Share on other sites

Wow ..

How lame am I , Its seems like I did not explained myself currectly

The array contain only letters and number..

well I'll just give a example..

array[8]=["a",0,0,"b",0,0,"a",0]
for $i=0 to 7
if $array[$i]<>"b" then
update($i)
endif
next

I need this to work

when a cell in the array does not contain the letter "b" I need it to do something..

The array only contain number or single letters so a cell can not contain the letter "b" with another letter

Thank you

Edited by oren
Link to comment
Share on other sites

Well its working...

Thank you,

I wonder why a simple <> does not work

Why 0<>'b' give false?.

Read my earlier post about the mathematics of strings. If you compare a string to a number with a math operator, you convert the string to a number. "b" mathematically equals zero, so if 0<>'b' literally means if 0<>0, which is FALSE! In the future, this would work:
If String($Array[$i]) <> String("b") Then
You really don't need the "String()" around the "b" in this example, but this is how you would do a String Comparison. Basically, AutoIT cannot compare apples to oranges. You have to convert apples to oranges or convert oranges to apples.

EDIT: FYI, you could also use "==" to do a string compare, but you would need to add an ELSE statement for your needs

Local $Array[8] = ["a", 0, 0, "b", 0, 0, "a", 0]
For $i = 0 To 7
    If $Array[$i] == "b" Then
        MsgBox(32, 'Element ' & $i & ' is equal to "b"', $Array[$i])
    Else
        MsgBox(32, 'Element ' & $i & ' is different from "b"', $Array[$i])
    EndIf
Next
"==" does a string comparison exactly! So If "b" == "B" is false, since there case is different.

Check the Help File for "Language Reference - Operators"

Edited by Varian
Link to comment
Share on other sites

Local $array[8] = ["a", "0", "0", "b", "0", "0", "a", "0"]

For $i = 0 To 7
    If $array[$i] <> "b" Then
        update($i)
    EndIf
Next


Func update($a)
    MsgBox(1, " Yes it is", "Update this ==>" & $array[$a], 2)

EndFunc   ;==>update
Well its working...

It works in the 0th and 7th elements (the "a" values), but all the "0" values are False. If that is what the OP wanted, then great. But my understanding was that he wanted all non "b" values to run the update function.
Link to comment
Share on other sites

It works in the 0th and 7th elements (the "a" values), but all the "0" values are False. If that is what the OP wanted, then great. But my understanding was that he wanted all non "b" values to run the update function.

All the non "b" values are working as long as the Zero values are enclosed in Quotes C.
Link to comment
Share on other sites

Read my earlier post about the mathematics of strings. If you compare a string to a number with a math operator, you convert the string to a number. "b" mathematically equals zero, so if 0<>'b' literally means if 0<>0, which is FALSE! In the future, this would work:

If String($Array[$i]) <> String("b") Then
You really don't need the "String()" around the "b" in this example, but this is how you would do a String Comparison. Basically, AutoIT cannot compare apples to oranges. You have to convert apples to oranges or convert oranges to apples.

EDIT: FYI, you could also use "==" to do a string compare, but you would need to add an ELSE statement for your needs

Local $Array[8] = ["a", 0, 0, "b", 0, 0, "a", 0]
For $i = 0 To 7
    If $Array[$i] == "b" Then
        MsgBox(32, 'Element ' & $i & ' is equal to "b"', $Array[$i])
    Else
        MsgBox(32, 'Element ' & $i & ' is different from "b"', $Array[$i])
    EndIf
Next
"==" does a string comparison exactly! So If "b" == "B" is false, since there case is different.

Check the Help File for "Language Reference - Operators"

Thank you

P.S

the 0 can not be "0" But its a nice idea thank you.

Link to comment
Share on other sites

P.S

the 0 can not be "0" But its a nice idea thank you.

If you read carefully what Varian tried to say you don't have a choice.

Do you have an example of the data you want to use because there is always ways to convert what ever is coming in to the right format for comparison purposes.

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