oren Posted September 21, 2010 Share Posted September 21, 2010 (edited) 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 September 21, 2010 by oren Link to comment Share on other sites More sharing options...
jaberwacky Posted September 21, 2010 Share Posted September 21, 2010 (edited) We'll need more information such as the contents of the array or just the whole rest of the code. Edited September 21, 2010 by jaberwocky6669 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
Varian Posted September 21, 2010 Share Posted September 21, 2010 (edited) Are you saying that if there is no letter "b" in the (array) element element do something? If so, why not doIf Not StringInStr($array[$i], 'b') ThenIf $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 September 21, 2010 by Varian Link to comment Share on other sites More sharing options...
M a k a v e l ! Posted September 21, 2010 Share Posted September 21, 2010 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 there3. 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 More sharing options...
oren Posted September 21, 2010 Author Share Posted September 21, 2010 (edited) 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 September 21, 2010 by oren Link to comment Share on other sites More sharing options...
M a k a v e l ! Posted September 21, 2010 Share Posted September 21, 2010 Did you try Varian's solution : If Not StringInStr($array[$i], 'b') Then ??? [font="Lucida Sans Unicode"]M a k. a v e L ![/font] Link to comment Share on other sites More sharing options...
oren Posted September 21, 2010 Author Share Posted September 21, 2010 (edited) Did you try Varian's solution : If Not StringInStr($array[$i], 'b') Then ??? Well its working... Thank you, I wonder why a simple <> does not work Why 0<>'b' give false?. Edited September 21, 2010 by oren Link to comment Share on other sites More sharing options...
Varian Posted September 21, 2010 Share Posted September 21, 2010 (edited) 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") ThenYou 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 needsLocal $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 September 21, 2010 by Varian Link to comment Share on other sites More sharing options...
JoHanatCent Posted September 21, 2010 Share Posted September 21, 2010 (edited) 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 ;==>updateWell its working... Edited September 21, 2010 by JoHanatCent Link to comment Share on other sites More sharing options...
Varian Posted September 21, 2010 Share Posted September 21, 2010 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 ;==>updateWell 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 More sharing options...
JoHanatCent Posted September 21, 2010 Share Posted September 21, 2010 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 More sharing options...
Varian Posted September 21, 2010 Share Posted September 21, 2010 All the non "b" values are working as long as the Zero values are enclosed in Quotes C.That is correct, because they are now Strings...originally that was not the case. Link to comment Share on other sites More sharing options...
oren Posted September 21, 2010 Author Share Posted September 21, 2010 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") ThenYou 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 needsLocal $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 More sharing options...
JoHanatCent Posted September 21, 2010 Share Posted September 21, 2010 (edited) 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 September 21, 2010 by JoHanatCent 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