StungStang Posted June 8, 2011 Share Posted June 8, 2011 I have write a script to compare 2 number. If the first number is higher than the second *Do What You Want*, but if the first number is smaller than the second *Do not continue".All work good, but if i have n1 = 100 and n2= x (where x is any number smaller than 100)It's say to me that n2 is high than first!See an example foto :As you can see 100 is higher than 3, but for autoit not This is the code :#include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1_1 = GUICreate("Number Compare", 194, 113, 454, 418) $Label2 = GUICtrlCreateLabel("First:", 8, 48, 31, 17) $FirstNumber = GUICtrlCreateInput("", 56, 48, 41, 21) $Label3 = GUICtrlCreateLabel("Second:", 112, 48, 27, 17) $SecondNumber = GUICtrlCreateInput("", 144, 48, 33, 21) $Compare = GUICtrlCreateButton("Compare", 64, 80, 75, 25, $WS_GROUP) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Compare If GUICtrlRead($FirstNumber) > GUICtrlRead($SecondNumber) Then MsgBox (0,"Ok","Your first number is higher than second") Else MsgBox (0,"Error","First number should be higher than second!") EndIf EndSwitch WEndWhere is the error? Hi! Link to comment Share on other sites More sharing options...
iamtheky Posted June 8, 2011 Share Posted June 8, 2011 (edited) you are evaluating strings, when you want to perform the action on numbers Case $Compare $numFirst = GUICtrlRead($FirstNumber) $numSecond = GUICtrlRead($SecondNumber) If number($numFirst) > number($numSecond) Then MsgBox (0,"Ok","Your first number is higher than second") Else MsgBox (0,"Error","First number should be higher than second!") EndIf Edited June 8, 2011 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
water Posted June 8, 2011 Share Posted June 8, 2011 (edited) Bug? No! According to the help file GUICtrlRead returns "The text entered". Which means a string is returned. If you compare string "100" with string "3" then the latter is "higher". Convert the strings to numbers and then do the compare : If Number(GUICtrlRead($FirstNumber)) > Number(GUICtrlRead($SecondNumber)) Then ... Make sure that the user enters valid numeric data. Edited June 8, 2011 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
StungStang Posted June 8, 2011 Author Share Posted June 8, 2011 Ok, thanks... Yes i set the imputbox as number only... There is a way to set the range of number that the user can write (0 to 100)? Thanks Link to comment Share on other sites More sharing options...
water Posted June 8, 2011 Share Posted June 8, 2011 There is a way to set the range of number that the user can write (0 to 100)?No, you have to check it yourself. You can only limit the number of characters a user can enter with GUICtrlSetLimit. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
StungStang Posted June 8, 2011 Author Share Posted June 8, 2011 Ok...no realtime check Thanks Link to comment Share on other sites More sharing options...
JoHanatCent Posted June 9, 2011 Share Posted June 9, 2011 (edited) Ok...no realtime check Thanks O you can check! See comments in script:(Just a demo) expandcollapse popup#include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $number[2] $Form1_1 = GUICreate('Number Compare', 194, 113, 454, 418) $label1 = GUICtrlCreateLabel('- - - - - - - - - - - - - - - - - - - - - - - - - - - - -', 10, 10, 174, 27) $Label2 = GUICtrlCreateLabel('First:', 8, 48, 31, 17) $number[0] = GUICtrlCreateInput('0', 56, 48, 41, 21, $ES_NUMBER);<<<< ==== This helps GUICtrlSetLimit(-1, 3);<<<< ==== Limit to Maximum three Characters $Label3 = GUICtrlCreateLabel('Second:', 110, 48, 27, 17) $number[1] = GUICtrlCreateInput('0', 144, 48, 33, 21, $ES_NUMBER);<<<< ==== This helps GUICtrlSetLimit(-1, 3, 1) $Compare = GUICtrlCreateButton('Compare', 64, 80, 75, 25, $WS_GROUP) GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND");<<< === See "Help" for detail === >>> GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $Compare If Number(GUICtrlRead($number[0])) > Number(GUICtrlRead($number[1])) Then MsgBox(0, 'Ok', 'Your first number is higher than second') Else MsgBox(0, 'Error', 'First number should be higher than second!') EndIf Case $number[0], $number[1] If Number(GUICtrlRead($number[0])) > 100 Or Number(GUICtrlRead($number[0])) < 1 Then MsgBox(0, 'Attention:', 'Remember' & @CRLF & 'Only numbers between one and One Hundered allowed', 1) GUICtrlSetData($number[0], '') GUICtrlSetData($number[1], '') GUICtrlSetData($label1, 'Only numbers between 1 and 100 allowed!!!') WinActivate("Number") Else GUICtrlSetData($label1, '') EndIf EndSwitch WEnd Func MY_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam);<<< === See "Help" for detail === >>> Local $iCode = BitShift($wParam, 16) If $iCode = $EN_CHANGE Then For $i = 0 To 1 If Number(GUICtrlRead($number[$i])) > 100 Then MsgBox(0, 'Attention:', 'Only numbers between one and One Hundered allowed', 1) GUICtrlSetData($number[$i], '') GUICtrlSetData($label1, 'Only numbers between 1 and 100 allowed!!!') EndIf GUICtrlSetData($label1, '') Next EndIf EndFunc ;==>MY_WM_COMMAND Added some coments! Edited June 9, 2011 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