BornExtreme Posted June 24, 2004 Share Posted June 24, 2004 GuiCreate ("Setting Page",356,332)Do $i=0 GuiSetControl ("label", "Please enter two numbers to random from", 10,10) $x =GUIRead (GuiSetControl ("input", "", 10,30,40,20)) GuiSetControl ("label", "to", 65,32) $y = GUIRead (GuiSetControl ("input", "", 100,30,40,20)) GuiSetControl ("label", "How many sites would you like to use?", 10,60,200,20) $sites_num = GUIRead (GuiSetControl ("input", "", 10,75,40,20)) GuiSetControl ("label", "Please list the sites that you want to use", 10,100,200,20) $sites_adresses = GuiSetControl ("edit", "", 10,120,330,170) GUISetControl ("button", "OK", 160,300, 60,20 ) GuiShow () GUIWaitClose () $check=StringIsDigit ($x) if $check==0 Then MsgBox ( 0, "Error","First Number - Please enter a whole number" ) $i=$i+1 EndIf $check=StringIsDigit ($y) if $check==0 Then MsgBox ( 0, "Error","Second Number - Please enter a whole number" ) $i=$i+1 EndIfUntil $i==0GUIDelete ( )the GUI works and it show him but when i put letters on one of 2 first boxes it doesn't give me an error message Link to comment Share on other sites More sharing options...
pekster Posted June 24, 2004 Share Posted June 24, 2004 (edited) Your problem is that you are not testing the values of the input boxes after the GUI has closed. In fact, you are teting the values of the strings as soon as you create the GUI. This means that both $x and $y are equal to "" (an empty string.) The return value of the StringIsDigit function is 1 when you give it a blank string. This means that your test will never be true, and you will never catch the mistake by the user.To solve your problem, do your GuiRead calls after your GuiWaitClose call, so that you get the data that the user entered, and not the default value.Furthermore, why not use the ES_NUMBER GUI control style so that the user can only enter numbers to begin with? Like this:#include <GuiConstants.au3> GuiCreate("Example", 100, 50) $input = GuiSetControl("input", "", 0, 0, 100, 20, $ES_NUMBER) GuiSetControl("button", "Exit Example", 0, 30, 100, 20) GuiShow() GuiWaitClose()Typo fixed Edited June 24, 2004 by pekster [font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes. Link to comment Share on other sites More sharing options...
BornExtreme Posted June 24, 2004 Author Share Posted June 24, 2004 thanks you very much, it my first time... i have another problam now.i tried to check if the first number smaller then the second one.#include <GuiConstants.au3>GuiCreate ("Setting Page",356,332)Do $i=0 GuiSetControl ("label", "Please enter two numbers to random from", 10,10,200,20) $x =GuiSetControl ("input", "", 10,30,40,20, $ES_NUMBER) GuiSetControl ("label", "to", 65,32) $y = GuiSetControl ("input", "", 100,30,40,20, $ES_NUMBER) GuiSetControl ("label", "How many sites would you like to use?", 10,60,200,20) $sites_num = GUIRead (GuiSetControl ("input", "", 10,75,40,20, $ES_NUMBER)) GuiSetControl ("label", "Please list the sites that you want to use", 10,100,200,20) $sites_adresses = GuiSetControl ("edit", "", 10,120,330,170) GUISetControl ("button", "OK", 160,300, 60,20 ) GuiShow () GUIWaitClose () $x=GUIRead ($x) $y=GUIRead ($y) if $y<=$x Then MsgBox ( 0, "Error", "The second number must be bigger then the first one." ) $i=$i+1 EndIfUntil $i==0GUIDelete ( )in the first time it works but if i put the second number smaller then the first number couple of times it doesnt work even when the first number smaller the the second number.it show the error msg so i know it going into the "if" but why?thanks very much to all helpers! Link to comment Share on other sites More sharing options...
pekster Posted June 24, 2004 Share Posted June 24, 2004 This occurs because the return of the input boxes is a string, and not a number. A simple solution would be to wrap the GuiRead commands around a Number function, like this: $x=Number(GUIRead ($x)) $y=Number(GUIRead ($y)) This method forces the strings to become numbers. The reason your conditional test was always returning true was because the strings evaluated to the numerical value of 0, and 0 is less than or equal to 0. Forcing them to become numbers solves this. [font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes. Link to comment Share on other sites More sharing options...
BornExtreme Posted June 24, 2004 Author Share Posted June 24, 2004 thanks for the reply, i tried it but it didnt help.. thanks for trying... please if anyone have another solution write it here. Link to comment Share on other sites More sharing options...
Josbe Posted June 24, 2004 Share Posted June 24, 2004 thanks for the reply, i tried it but it didnt help.. thanks for trying... please if anyone have another solution write it here.Try replacing with this: If $x <= $y Then AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta Link to comment Share on other sites More sharing options...
Developers Jos Posted June 24, 2004 Developers Share Posted June 24, 2004 (edited) It is because you are looping and adding everytime a new control on top of the old one. You could delete all and recreate like this: #include <GuiConstants.au3> Do GUICreate("Setting Page", 356, 332) $I = 0 GUISetControl("label", "Please enter two numbers to random from", 10, 10, 200, 20) $X = GUISetControl("input", "", 10, 30, 40, 20, $ES_NUMBER) GUISetControl("label", "to", 65, 32) $Y = GUISetControl("input", "", 100, 30, 40, 20, $ES_NUMBER) GUISetControl("label", "How many sites would you like to use?", 10, 60, 200, 20) $SITES_NUM = GUIRead(GUISetControl("input", "", 10, 75, 40, 20, $ES_NUMBER)) GUISetControl("label", "Please list the sites that you want to use", 10, 100, 200, 20) $SITES_ADRESSES = GUISetControl("edit", "", 10, 120, 330, 170) GUISetControl("button", "OK", 160, 300, 60, 20) GUIShow() GUIWaitClose() $X = GUIRead($X) $Y = GUIRead($Y) If $Y <= $X Then MsgBox(0, "Error", "The second number must be bigger then the first one.") $I = $I + 1 EndIf GUIDelete() Until $I == 0 or only build the gui once and keep on checking till the right values are filled in: #include <GuiConstants.au3> Opt ("GUINotifyMode", 1) GUICreate("Setting Page", 356, 332) $I = 0 GUISetControl("label", "Please enter two numbers to random from", 10, 10, 200, 20) $X = GUISetControl("input", "", 10, 30, 40, 20, $ES_NUMBER) GUISetControl("label", "to", 65, 32) $Y = GUISetControl("input", "", 100, 30, 40, 20, $ES_NUMBER) GUISetControl("label", "How many sites would you like to use?", 10, 60, 200, 20) $SITES_NUM = GUIRead(GUISetControl("input", "", 10, 75, 40, 20, $ES_NUMBER)) GUISetControl("label", "Please list the sites that you want to use", 10, 100, 200, 20) $SITES_ADRESSES = GUISetControl("edit", "", 10, 120, 330, 170) $H_OK=GUISetControl("button", "OK", 160, 300, 60, 20) GUISetControlNotify($H_OK, 2) GUIShow() While 1 $rc = GUIMsg() if $rc = -3 then exit; X clicked at the right top If GUIRead() = $H_OK Then If GUIRead($Y) <= GUIRead($X) Then MsgBox(0, "Error", "The second number must be bigger then the first one.") Else ExitLoop EndIf EndIf Wend GUIDelete() Edited June 24, 2004 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
BornExtreme Posted June 26, 2004 Author Share Posted June 26, 2004 I used JdeB first solution and it works!!! thanks alot!!! 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