pekster Posted May 8, 2004 Share Posted May 8, 2004 (edited) My goal is to have several input boxes in a GUI and check every X amount of time to make sure the user's entry is valid. If not, I have some code to run. My problem is that I cannot manage to get the testing of the input box to work. Here is what I tried: #include <GuiConstants.au3> Opt("GuiCoordMode", 2) Opt("GuiNotifyMode", 1);I think this is needed to register the input as a notify??? GuiCreate("GUI Text", 200, 200) GuiSetCoord(0, 0, 50, 25) $input1 = GuiSetControl("input", "0", -1, -1) $input1_N = GuiSetControlNotify() GuiSetControlEx(-1, $GUI_FOCUS) GuiShow() While 1 Sleep(250) $n = GuiMsg(0) If $n = -3 Then;user closed window Exit ElseIf $n = $input1_N Then;user changed input1 text $r = GuiRead($input1) $r = Number($r) If $r < 0 or $r > 50 Then GuiWrite($input1, $GUI_FOCUS, "0") MsgBox(0, "Error", "Number must be between 0 and 50") EndIf EndIf WEnd The "$n = $input1_N" condition never appears to be true, even if I enter data. Is there a way to trip the notify condition in this case, or is there a faster method with a different command? Edited to correct a minor spelling mistake Edited May 8, 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...
pekster Posted May 9, 2004 Author Share Posted May 9, 2004 (edited) I have come up with a workaround that checks each pass for a change in the entry field. It's not really a solution to the problem, but it acomplishes the task. Replace the while loop above with the following code: $data1 = "0" While 1 Sleep(250) $n = GuiMsg(0) If $n = -3 Then Exit;user closed window If $data1 <> GuiRead($input1) Then;check for data change $data1 = GuiRead($input1) If not StringIsDigit($data1) Then;some of entry is not a digit GuiWrite($input1, $GUI_FOCUS, "0") $data1 = "0" MsgBox(0, "Error", "Entry must be a number") ElseIf $data1 < 0 or $data1 > 50 Then;entry out of range GuiWrite($input1, $GUI_FOCUS, "0") $data1 = "0" MsgBox(0, "Error", "Entry must be a number between 0 and 50") EndIf EndIf WEnd If someone does know how to make an input field give a notify on change, I am still interested to know how this is done. Edited to correct a minor code mistake Edited May 9, 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...
CyberSlug Posted May 9, 2004 Share Posted May 9, 2004 Notification for edit and input controls is rather buggy.... (Note to jpm, you are working on this, right? ) For example, I have a GUI that contains Input and Button controls. I change an input, and nothing is triggered. Then I click a button, I and I get Input message notification. I click the button again, and receive a button notification.... Other ideas (untested) for workarounds:Global $psuedoMessage = 0 HotKeySet("{Enter}", "psuedoNotify") Func psuedoNotify() $psuedoMessage = $input1_N EndFunc ; part your script goes here.... ElseIf $psuedoMessage = 1 Then $psuedoMessage = 0 ;....... Ack.... I see already this will not work with multiple controls. We really need a way to determine what control has focus. You can use ControlCommand/ControlFocus fucntions, but you need to map their classNN results to Gui reference numbers...... Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
pekster Posted May 9, 2004 Author Share Posted May 9, 2004 For now it sounds eaisier to do what I've done. I'll probably make that into a function of sorts so I can just do 'If <inputs changed> Then <validate them>' or something like that. Not a huge problem, but I was wondering why my notification didn't appear to work. A big thanks to all those developing the GUI portion of AutoIt 3.0.102+. So far I love what I see. [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...
Valik Posted May 9, 2004 Share Posted May 9, 2004 Question... (Mainly to you, CS) what's stopping you from using AdLib to poll the input box for changes? Then you can set a flag that's checked in your message loop, or better yet, see about sending ControlClick to a hidden, but highly uniquely named button (Avoids the classnameNN bit) which will put a real message in your loop. Link to comment Share on other sites More sharing options...
scriptkitty Posted May 9, 2004 Share Posted May 9, 2004 try this code, and watch the timer stop: AdlibEnable ("timer") sleep(2000) GUICreate("My GUI") ; will create a dialog box that when displayed is centered GUIWaitClose() ; will display an empty dialog box func timer() tooltip(@sec,0,0) endfunc AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
Valik Posted May 9, 2004 Share Posted May 9, 2004 Any time I do anything with a GUI, I ALWAYS use GuiNotifyMode=1 and write my own message pump using GuiMsg(0), so my GUI's never block. Also, looking at the original poster's code, they are also using that same method, so I don't see why it can't be polled with AdLib (Or even in the message loop) as GuiMsg(0) polls and doesn't block at all. Link to comment Share on other sites More sharing options...
scriptkitty Posted May 9, 2004 Share Posted May 9, 2004 (edited) Doh, I forgot about that!! edit.. seems AutoIt pauses until a GUI responce comes back no matter what setting I do though. I thought GUinotify would work different. Going to have to test a few things. Edited May 9, 2004 by scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
pekster Posted May 9, 2004 Author Share Posted May 9, 2004 The problem is that it won't work. I put a MsgBox(0, "condition reached", "") command right after the conditional '$n = $input1_N' statement from my original code, and it was never displayed. Even Opt("GuiNotifyMode", 1) didn't fix that. [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...
CyberSlug Posted May 9, 2004 Share Posted May 9, 2004 Question... (Mainly to you, CS) what's stopping you from using AdLib to poll the input box for changes? Then you can set a flag that's checked in your message loop, or better yet, see about sending ControlClick to a hidden, but highly uniquely named button (Avoids the classnameNN bit) which will put a real message in your loop. I will have to try this However, even with Opt(GUINotifyMode,0) I still usually get an input/edit notification the first time I click a button .... Is this a bug? Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! 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