patiii Posted April 28, 2011 Share Posted April 28, 2011 Hello people I'm new in this forum and I really need help maybe someone could help me with my script #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 391, 180, 192, 124) $Input1 = GUICtrlCreateInput("xkoordinatevon", 24, 32, 89, 21) $Input2 = GUICtrlCreateInput("xkoordinatebis", 208, 37, 89, 21) $Input3 = GUICtrlCreateInput("ykoordinatevon", 23, 132, 89, 21) $Input4 = GUICtrlCreateInput("ykoordinatebis", 212, 135, 89, 21) $xkoordinatevonbutton = GUICtrlCreateButton("eingeben", 136, 32, 49, 25) $xkoordinatebisbutton = GUICtrlCreateButton("eingeben", 318, 34, 49, 25) $ykoordinatevonbutton = GUICtrlCreateButton("eingeben", 137, 129, 49, 25) $ykoordinatebisbutton = GUICtrlCreateButton("eingeben", 317, 133, 49, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $xkoordinatevonbutton $integer1= GUICtrlRead($Input1) Case $xkoordinatebisbutton $integer2 = GUICtrlRead($Input2) Case $ykoordinatevonbutton $integer3 = GUICtrlRead($Input3) Case $ykoordinatebisbutton $integer4 = GUICtrlRead($Input4) EndSwitch WEnd If $integer1 = "" then Exit If $integer1< 0 then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') If $integer1 < 0 then Exit If $integer1 > 1439 then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') If $integer1 > 1439 then Exit If $integer2 = "" then Exit If $integer2 < 0 then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') If $integer2 < 0 then Exit If $integer2 > 1439 then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') If $integer2 > 1439 then Exit If $integer3 = "" then Exit If $integer3 < 0 then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') If $integer3 < 0 then Exit If $integer3 > 899 then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') If $integer3 > 899 then Exit If $integer4 = "" then Exit If $integer4 < 0 then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') If $integer4 < 0 then Exit If $integer4 > 899 then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') If $integer4 > 899 then Exit this is my script now but when I press the button for example with -1 the programm does not close like it should be why?what is the problem I have please help me patiii Link to comment Share on other sites More sharing options...
hannes08 Posted April 28, 2011 Share Posted April 28, 2011 Hi patiii, If you use "Exit" after Switch $nMsg Case $GUI_EVENT_CLOSE Exit your program will close and not do what you have coded below the WEnd. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
patiii Posted April 28, 2011 Author Share Posted April 28, 2011 hi, thank you that you want to help me but i did not unterstand you where do i have to write the exit??maybe you could give me the right script so I can check with my patiii Link to comment Share on other sites More sharing options...
bwochinski Posted April 28, 2011 Share Posted April 28, 2011 (edited) Based upon what I see in the script, I think this is more or less what you're trying to accomplish... expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 391, 180, 192, 124) $Input1 = GUICtrlCreateInput("xkoordinatevon", 24, 32, 89, 21) $Input2 = GUICtrlCreateInput("xkoordinatebis", 208, 37, 89, 21) $Input3 = GUICtrlCreateInput("ykoordinatevon", 23, 132, 89, 21) $Input4 = GUICtrlCreateInput("ykoordinatebis", 212, 135, 89, 21) $xkoordinatevonbutton = GUICtrlCreateButton("eingeben", 136, 32, 49, 25) $xkoordinatebisbutton = GUICtrlCreateButton("eingeben", 318, 34, 49, 25) $ykoordinatevonbutton = GUICtrlCreateButton("eingeben", 137, 129, 49, 25) $ykoordinatebisbutton = GUICtrlCreateButton("eingeben", 317, 133, 49, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $integer1, $integer2, $integer3, $integer4 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $xkoordinatevonbutton $integer1= GUICtrlRead($Input1) _xVon() ;<<<<< CALLING FUNCTION Case $xkoordinatebisbutton $integer2 = GUICtrlRead($Input2) _xBis() ;<<<<< CALLING FUNCTION Case $ykoordinatevonbutton $integer3 = GUICtrlRead($Input3) _yVon() ;<<<<< CALLING FUNCTION Case $ykoordinatebisbutton $integer4 = GUICtrlRead($Input4) _yBis() ;<<<<< CALLING FUNCTION EndSwitch WEnd Func _xVon() If $integer1 = "" Then Exit ElseIf $integer1 < 0 Then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') Exit ElseIf $integer1 > 1439 Then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') Exit EndIf EndFunc Func _xBis() If $integer2 = "" Then Exit ElseIf $integer2 < 0 Then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') Exit ElseIf $integer2 > 1439 Then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') Exit EndIf EndFunc Func _yVon() If $integer3 = "" Then Exit ElseIf $integer3 < 0 Then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') Exit ElseIf $integer3 > 899 Then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') Exit EndIf EndFunc Func _yBis() If $integer4 = "" Then Exit ElseIf $integer4 < 0 Then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') Exit ElseIf $integer4 > 899 Then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') Exit EndIf EndFunc As the code is now, you could combine those 4 functions into a single error check function, but I think you may want each button to do something different, so I left them separate. Edited April 28, 2011 by bwochinski Link to comment Share on other sites More sharing options...
patiii Posted April 28, 2011 Author Share Posted April 28, 2011 (edited) hi, yeah that's great thank you very much i hope i can do the rest on my own but really thanks for the help but i have one question what does this Global and then $integer1... means? because i also want to understand the script patiii Edited April 28, 2011 by patiii Link to comment Share on other sites More sharing options...
hannes08 Posted April 28, 2011 Share Posted April 28, 2011 You can define variables in global or local scope. Local means that they are only available in a function (between Func and EndFunc). Global variables can be used both in normal code and function code. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
bwochinski Posted April 28, 2011 Share Posted April 28, 2011 (edited) I used the "Global" line to declare those variables as being global in scope. I wanted to make sure that when they are referred to in the functions ( _xVon() for example ) they aren't treated as local scope variables (existing only within that function). When this happens you can get annoying and difficult bugs in your program.Many people prefer to set the Opt("MustDeclareVars",1) option at the top of every script to prevent this kind of thing from being an issue. It forces you to specify scope for variables before you can use them.EDIT: Hannes explains more concisely Edited April 28, 2011 by bwochinski Link to comment Share on other sites More sharing options...
patiii Posted April 28, 2011 Author Share Posted April 28, 2011 okay thank you but I have got the next probelm.. I try to do a programm but I'm a beginner in autoit... so my next problem I want that the box with the buttons and the inputboxes closes when somebody tipped in 4 integer as the koordinates... so that this will start $c = InputBox('Anzahl der Wiederholungen','Bitte geben sie eine Anzahl ein!') $a = 0 Do MouseClick ("left" ,264,152) sleep(1000) MouseClick ("left" ,264,152) sleep(600) MouseClick ("left" ,264,152) MouseMove($integer1,$integer3) sleep(500) mousedown("left") MouseMove($integer2,$integer4) mouseup("left") Send ("{DEL}") Mouseclick("left" ,299,213) $a = $a + 1 Until $a = $c when the programm has got the values...(i know it's not a good code but for the beginning it's okay for me I#m sure it can be better solved) but i don't know how to close the box patiii thanks for help Link to comment Share on other sites More sharing options...
bwochinski Posted April 28, 2011 Share Posted April 28, 2011 (edited) Easiest way is to just put in GUISetState(@SW_HIDE, $Form1) where you want the main window to disappear. Make sure to either exit the script, or re-display the window once your processing is done. Without the window the user isn't left with a friendly way to exit. Edited April 28, 2011 by bwochinski Link to comment Share on other sites More sharing options...
hannes08 Posted April 28, 2011 Share Posted April 28, 2011 1. Create a new button (e.g. "Go") 2. Assign a new function as its action like the other four 3. As first action in the Function do a GuiSetState(@SW_HIDE, $Form1) 4. Place your code in the function 5. At the end of your Function do a GuiSetState(@SW_SHOW, $Form1) Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
patiii Posted April 28, 2011 Author Share Posted April 28, 2011 (edited) yeah ok but how can i say that the window should be hidden when the 4 values are given?so after somebody tipped in the 4 numbers the window should close and then it should go on with the script normally patiii EDIT:sorry I didn't see your post hannes so like this?? i get an error in the go func #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 391, 180, 192, 124) $Input1 = GUICtrlCreateInput("xkoordinatevon", 24, 32, 89, 21) $Input2 = GUICtrlCreateInput("xkoordinatebis", 208, 37, 89, 21) $Input3 = GUICtrlCreateInput("ykoordinatevon", 23, 132, 89, 21) $Input4 = GUICtrlCreateInput("ykoordinatebis", 212, 135, 89, 21) $xkoordinatevonbutton = GUICtrlCreateButton("eingeben", 136, 32, 49, 25) $xkoordinatebisbutton = GUICtrlCreateButton("eingeben", 318, 34, 49, 25) $ykoordinatevonbutton = GUICtrlCreateButton("eingeben", 137, 129, 49, 25) $ykoordinatebisbutton = GUICtrlCreateButton("eingeben", 317, 133, 49, 25) $Go = GUICtrlCreateButton("Go", 120, 75, 50, 50) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $integer1, $integer2, $integer3, $integer4 ,$Go While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $xkoordinatevonbutton $integer1= GUICtrlRead($Input1) _xVon() ;<<<<< CALLING FUNCTION Case $xkoordinatebisbutton $integer2 = GUICtrlRead($Input2) _xBis() ;<<<<< CALLING FUNCTION Case $ykoordinatevonbutton $integer3 = GUICtrlRead($Input3) _yVon() ;<<<<< CALLING FUNCTION Case $ykoordinatebisbutton $integer4 = GUICtrlRead($Input4) _yBis() ;<<<<< CALLING FUNCTION Case $Go _Go() EndSwitch WEnd Func _Go () EDIT:sorry i forgott () but still error If $Go Then GuiSetState(@SW_HIDE, $Form1) Func _xVon() If $integer1 = "" Then Exit ElseIf $integer1 < 0 Then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') Exit ElseIf $integer1 > 1439 Then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') Exit EndIf EndFunc Func _xBis() If $integer2 = "" Then Exit ElseIf $integer2 < 0 Then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') Exit ElseIf $integer2 > 1439 Then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') Exit EndIf EndFunc Func _yVon() If $integer3 = "" Then Exit ElseIf $integer3 < 0 Then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') Exit ElseIf $integer3 > 899 Then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') Exit EndIf EndFunc Func _yBis() If $integer4 = "" Then Exit ElseIf $integer4 < 0 Then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') Exit ElseIf $integer4 > 899 Then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') Exit EndIf EndFunc GUISetState(@SW_HIDE, $Form1) $c = InputBox('Anzahl der Wiederholungen','Bitte geben sie eine Anzahl ein!') $a = 0 Do MouseClick ("left" ,264,152) sleep(1000) MouseClick ("left" ,264,152) sleep(600) MouseClick ("left" ,264,152) MouseMove($integer1,$integer3) sleep(500) mousedown("left") MouseMove($integer2,$integer4) mouseup("left") Send ("{DEL}") Mouseclick("left" ,299,213) $a = $a + 1 Until $a = $c GuiSetState(@SW_SHOW, $Form1) PS:Hannes I#m from germany maybe complicated things you could explain in german Edited April 28, 2011 by patiii Link to comment Share on other sites More sharing options...
patiii Posted April 28, 2011 Author Share Posted April 28, 2011 hi, now I tried it a bit and now i have got Func _Go() If _Go()Then GuiSetState(@SW_HIDE, $Form1) EndIf Endfunc as thwe function of go .. the window is hidden but he does not do the rest of the script pls help me patiii Link to comment Share on other sites More sharing options...
bwochinski Posted April 28, 2011 Share Posted April 28, 2011 (edited) Here Patiii, Main issue was that you were trying to put the _Go() function around all of the other functions, which is not allowed. It just needs to be a separate function. To do the same error checking when pressing "GO" I modified the error checking functions down to a single one, as I mentioned earlier. That function is now called at the beginning of the _Go() function for each of the integer values. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 391, 180, 192, 124) $Input1 = GUICtrlCreateInput("xkoordinatevon", 24, 32, 89, 21) $Input2 = GUICtrlCreateInput("xkoordinatebis", 208, 37, 89, 21) $Input3 = GUICtrlCreateInput("ykoordinatevon", 23, 132, 89, 21) $Input4 = GUICtrlCreateInput("ykoordinatebis", 212, 135, 89, 21) $xkoordinatevonbutton = GUICtrlCreateButton("eingeben", 136, 32, 49, 25) $xkoordinatebisbutton = GUICtrlCreateButton("eingeben", 318, 34, 49, 25) $ykoordinatevonbutton = GUICtrlCreateButton("eingeben", 137, 129, 49, 25) $ykoordinatebisbutton = GUICtrlCreateButton("eingeben", 317, 133, 49, 25) $Go = GUICtrlCreateButton("Go", 120, 75, 50, 50) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $integer1, $integer2, $integer3, $integer4 ,$Go While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $xkoordinatevonbutton $integer1= GUICtrlRead($Input1) _checkInt($integer1, 1439) Case $xkoordinatebisbutton $integer2 = GUICtrlRead($Input2) _checkInt($integer2, 1439) Case $ykoordinatevonbutton $integer3 = GUICtrlRead($Input3) _checkInt($integer3, 899) Case $ykoordinatebisbutton $integer4 = GUICtrlRead($Input4) _checkInt($integer4, 899) Case $Go _Go() EndSwitch WEnd Func _Go() $integer1= GUICtrlRead($Input1) $integer2 = GUICtrlRead($Input2) $integer3 = GUICtrlRead($Input3) $integer4 = GUICtrlRead($Input4) If _checkInt($integer1, 1439) Then Return 1 If _checkInt($integer2, 1439) Then Return 1 If _checkInt($integer3, 899) Then Return 1 If _checkInt($integer4, 899) Then Return 1 $c = InputBox('Anzahl der Wiederholungen','Bitte geben sie eine Anzahl ein!') If $c == "" Then Return 1 GuiSetState(@SW_HIDE, $Form1) For $a = 0 To $c MouseClick ("left" ,264,152) sleep(1000) MouseClick ("left" ,264,152) sleep(600) MouseClick ("left" ,264,152) MouseMove($integer1,$integer3) sleep(500) mousedown("left") MouseMove($integer2,$integer4) mouseup("left") Send ("{DEL}") Mouseclick("left" ,299,213) Next GuiSetState(@SW_SHOW, $Form1) Return 0 EndFunc Func _checkInt($int, $max) If $int == "" Or $int < 0 Or $int > $max Then MsgBox(0,'Fehler!','Der eingegebene Wert ist nicht zulässig!') Return 1 Else Return 0 EndIf EndFunc Edited April 30, 2011 by bwochinski Link to comment Share on other sites More sharing options...
hannes08 Posted April 28, 2011 Share Posted April 28, 2011 Hi patiii,I suggest you to do an AutoIT tutorial for a beginning. Here's a good one to start: Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
patiii Posted April 28, 2011 Author Share Posted April 28, 2011 hi, yeah thanks it's working perfect but i'm trying to do this programm to lern more about autoit... so ich would like to understand ech step why did you change so many things? why don't wie have the function _ybis etc but instead this _checkint and what does _checkint do? would be nice if you answer patiii PS:if I could give here thanks I would give you 1000 but here is no thanks button Link to comment Share on other sites More sharing options...
hannes08 Posted April 28, 2011 Share Posted April 28, 2011 Hi patiii, bwochinski changed this because it is better to avoid redundant code. That means he merged the functions _yBis etc. into one that has parameters, so he can use it more often. So _checkint recieves two parameters, a value ($int) and a maximum value ($max). If $int == "" Or $int < 0 Or $int > $max Then Simply checks whether $int is not empty or smaller than 0 or bigger than $max. I'd still recommend to read a tutorial so you can get used to how coding / programming works. ;-) Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
patiii Posted April 28, 2011 Author Share Posted April 28, 2011 yeah ok i think so too but then i will search for a german so i will understand it better but thanks for the help Link to comment Share on other sites More sharing options...
hannes08 Posted April 28, 2011 Share Posted April 28, 2011 Autoit.de TUTORIAL Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
patiii Posted April 29, 2011 Author Share Posted April 29, 2011 yeah i think the whole thing is a bit more clear for me but i have 2 more questions... where did you write that when $max is bigger then 1499 that the error comes? you just wrote $max but i can't see where you wrote wehat $max is and the same with the return where did you wrote that it get's an error when it returns 1 and no error when it returns 0 thank you Link to comment Share on other sites More sharing options...
bwochinski Posted April 30, 2011 Share Posted April 30, 2011 The $max variable is specified as a paramater that must be provided whenever the _checkInt() function is called on the line below:Func _checkInt($int, $max)You can see that it takes 2 parameters, the first one is stored in $int, and the second in $max.Then if you look where I call the function, you can see the paramters that are provided:If _checkInt($integer1, 1439) Then Return 1 If _checkInt($integer2, 1439) Then Return 1 If _checkInt($integer3, 899) Then Return 1 If _checkInt($integer4, 899) Then Return 1each of the 4 "$integer" variables are passed in turn as the first parameter, along with their max allowed value as the second parameter. NOTE: --------------------When I originally posted this code above, I accidentally put the 2nd parameters in quotes, making them strings. Adding some error checking in the _checkInt() function would be a good idea to catch problems like this. As the function currently stands, make sure to remove any quotes from around the second parameter or the comparison will not work correctly.--------------------As for specifying that the return of 1 is an error, that is why I put each call to the _checkInt() function in an "If ... Then ..." statement. When the function returns a 1, that statement is evaluated as true, and so whatever code is in the If statement gets run - in this case, just returning so the rest of the code in the _GO() function isn't executed. I even have it return a 1 again, to denote an error, even though it isn't used right now. You can get fancier as you have more error checking and return different numbers for different errors, just like a built-in AutoIt function does, to allow for determining why there was an error. Then you can have your code respond in a more intuitive way to those errors, either automatically adjusting for them, or notifying the user exactly what the problem was.That was more than I intended to type... but hope it all helps somewhat. 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