nbala75 Posted February 21, 2011 Share Posted February 21, 2011 $A=50.2 (derived from webpage) $B=50.20 (derived from an excel sheet) It doesnt work when i say: If $A=$B then Msgbox(0,"","Equal") Endif It doesnt work when i declare like this also: $A=Number(50.2) $B=Number(50.20) If $A=$B then Msgbox(0,"","Equal") Endif It works when i do something like this: $A=Number((50.2)&"0") $B=Number(50.20) If $A=$B then Msgbox(0,"","Equal") Endif Apparently it took a long time for me to isolate this problem.....can some learned explain to me what is the funda behind this? Link to comment Share on other sites More sharing options...
GEOSoft Posted February 21, 2011 Share Posted February 21, 2011 Even that is doing it the hard way. You forced $a to be the same as $b and you are using a string comparison. There are a few ways to skin this cat, here are but 2 of them $a = 50.2 $b = 50.20 MsgBox(0, "TEST", "Using Mod(): " & Mod($a, $b) & @CRLF & "Using Subtraction: " & $a - $b & @CRLF) In either case a return value of 0 means they are equal. so your code would go something like this $a = 50.2 $b = 50.20 $bRtn = False If NOT Mod($a, $b) Then $bRtn = True EndIf MsgBox(0, "Result", $bRtn) George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 21, 2011 Moderators Share Posted February 21, 2011 nbala75,You get the data as strings so it is not surprising that they are not equal in the first test as AutoIt looks at them as strings.In the second test you have the wrong syntax for Number - go and look in the Help file how you should do it. Here is the proper way to test that data:; Compare as strings - this will fail because they are not identical $A = "50.2" $B = "50.20" If $A = $B Then MsgBox(0, "String", "Equal") EndIf ; Convert those strings to numbers - this will work as the values are the same $A = Number($A) $B = Number($B) If $A = $B Then MsgBox(0, "Number", "Equal") EndIf ; Use the correct syntax to convert strings to numbers - this will work as the values are the same $A = Number("50.2") $B = Number("50.20") If $A = $B Then MsgBox(0, "Number string", "Equal") EndIfBasically if you want to compare numerical values you need to get the variables into number format using Number correctly. All clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
GEOSoft Posted February 21, 2011 Share Posted February 21, 2011 All clear? M23Sure it is but Mod is just so simple; no conversions to do since it assumes a numerical input. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
nbala75 Posted February 21, 2011 Author Share Posted February 21, 2011 (edited) In the second test you have the wrong syntax for Number - go and look in the Help file how you should do it. M23I might have given it wrongly here. But when i tried to covert that as Number (as per help file notations), it never worked...But tell me one thing...in so many other places, i never used to convert it into Number or String for proper comparisons (unlike other languages), it failed here at this instance only.I also remember to have read somewhere that for using $A=$B, we need not convert it into Number formats...not sure where i read in help file Edited February 21, 2011 by nbala75 Link to comment Share on other sites More sharing options...
nbala75 Posted February 21, 2011 Author Share Posted February 21, 2011 Sure it is but Mod is just so simple; no conversions to do since it assumes a numerical input.Sure, thanx, will use Mods henceforth for these types Link to comment Share on other sites More sharing options...
JoHanatCent Posted February 22, 2011 Share Posted February 22, 2011 (edited) Sure, thanx, will use Mods henceforth for these types R U Sure? $a = 100.4;<<< = Per accident you can find this !!!!!!!!! $b = 50.20 $bRtn = False If NOT Mod($a, $b) Then $bRtn = True EndIf MsgBox(0, "Result1", $bRtn) ; === Where as === If Number($a) = Number($b) Then MsgBox(0, 'Result', 'True', 5) Else MsgBox(0, 'Result', 'False', 7) EndIf Added ; === Where As === Edited February 22, 2011 by JoHanatCent Link to comment Share on other sites More sharing options...
Malkey Posted February 22, 2011 Share Posted February 22, 2011 Sure, thanx, will use Mods henceforth for these types And another reason not to use Mod($a, $a) is:- When $b = 1, the result is always True. Also when $b = 0 and $a = 0 a Microsoft error is generated on my xp. ; When $b = 1, Result is always True. $a = 2 $b = 1 MsgBox(0, "Result", Mod($a, $b) = 0) ; Error, send Microsoft an error report or not. (using xp OP) $a = 0 $b = 0 MsgBox(0, "Result", Mod($a, $b) = 0) Link to comment Share on other sites More sharing options...
JoHanatCent Posted February 22, 2011 Share Posted February 22, 2011 When $b = 1, Result is always True.Error, send Microsoft an error report or not. (using xp OP)True. Mod is a division sum so If one divide A by 1 you should get back APlease don't send Mocrosoft an Error report because dividing A by 0=Zero is suppose to give us an error! Link to comment Share on other sites More sharing options...
nbala75 Posted February 22, 2011 Author Share Posted February 22, 2011 (edited) Iam pretty screwed up now The things which were working just right earlier are not working now...i think i really messed up the Number(" ") things here and there. Tell me, can i not use String=String? Or shud i use only StringCompare ?? This is just sucking my time.. :idiot: Edited February 22, 2011 by nbala75 Link to comment Share on other sites More sharing options...
nbala75 Posted February 22, 2011 Author Share Posted February 22, 2011 JoHanatCent and Malkey....thanx Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 22, 2011 Moderators Share Posted February 22, 2011 nbala75, Just do as I suggested in my post a long way above and you will get the correct results. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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