ne0trace Posted July 30, 2008 Share Posted July 30, 2008 Hello Autoiter, I would like to write a script which creates users in our Business Software. Right now I am in the process of writing, but one thing that comes to my mind is that nobody should use the default or blank values. It makes no sense to create a user with the a blank value as last name. So how can I avoid this? - check for blanks - but only on certain fields (some can be left blank) Thanx you Felix expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.12.1 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <GUIConstantsEx.au3> GUICreate("PXM Directory", 400, 300) GUICtrlCreateLabel("Please select your option.", 10, 10) GUICtrlCreateLabel("First Name", 10, 55) GUICtrlCreateLabel("Last Name", 10, 85) GUICtrlCreateLabel("Strasse + Nr.", 10, 115) GUICtrlCreateLabel("PLZ", 10, 145) GUICtrlCreateLabel("Mobile Nr.", 10, 175) GUICtrlCreateLabel("Stundensatz", 10, 205) $Firstname = GUICtrlCreateInput("First Name", 100, 50, 200) $Lastname = GUICtrlCreateInput("Last Name", 100, 80) $Street = GUICtrlCreateInput("Strasse + Nr.", 100, 110) $PLZ = GUICtrlCreateInput("PLZ", 100, 140) $MobileNo = GUICtrlCreateInput("Mobile Nr.", 100, 170) $Stdsatz = GUICtrlCreateInput("Stundensatz", 100, 200) $Start = GUICtrlCreateButton("Start", 150, 250, 130) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $Start Case $msg = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd ;Login Run("C:\Dokumente und Einstellungen\user\Desktop\4D_Client_2003_6\4DClient.exe") WinWaitActive("Anmeldung an 4D Server") Send("{space}") WinWaitActive("Benutzer anmelden") Send("^+{TAB 2}") Send("{down}") Send("{TAB}") Send("autoit") Send("{TAB}") ;Input Box $passwd = InputBox("Security Check", "Enter your password.", "", "*") If @error = 1 Then Exit EndIf Send($passwd) Send("{enter}") ;User anlegen WinWaitActive("4D Client") Sleep(1000) Send("^m") Sleep(1000) Send("^n") Link to comment Share on other sites More sharing options...
Kerros Posted July 30, 2008 Share Posted July 30, 2008 You will need to check for valid data on the fields you want to make sure that there is data for.. something like If GUICtrlRead($Firstname) <> "First Name" Or '' Then MsgBox(0,'Valid data','Looks good enough to enter') Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance. Link to comment Share on other sites More sharing options...
Kerros Posted July 30, 2008 Share Posted July 30, 2008 (edited) I was looking through the code a bit more, and your Start button and Exit button are not going to work... Try this, it's using OnEventMode expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.12.1 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1); OnEvent mode GUICreate("PXM Directory", 400, 300) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") GUICtrlCreateLabel("Please select your option.", 10, 10) GUICtrlCreateLabel("First Name", 10, 55) GUICtrlCreateLabel("Last Name", 10, 85) GUICtrlCreateLabel("Strasse + Nr.", 10, 115) GUICtrlCreateLabel("PLZ", 10, 145) GUICtrlCreateLabel("Mobile Nr.", 10, 175) GUICtrlCreateLabel("Stundensatz", 10, 205) $Firstname = GUICtrlCreateInput("First Name", 100, 50, 200) $Lastname = GUICtrlCreateInput("Last Name", 100, 80) $Street = GUICtrlCreateInput("Strasse + Nr.", 100, 110) $PLZ = GUICtrlCreateInput("PLZ", 100, 140) $MobileNo = GUICtrlCreateInput("Mobile Nr.", 100, 170) $Stdsatz = GUICtrlCreateInput("Stundensatz", 100, 200) $Start = GUICtrlCreateButton("Start", 150, 250, 130) GUICtrlSetOnEvent(-1,"_InputData") GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $Start EndSelect WEnd Func _InputData() If GUICtrlRead($Firstname) <> "First Name" Or '' Then MsgBox(0,'Valid data','Looks good enough to enter') else MsgBox(0,'Invalid data','Try something else') return endif ;Login Run("C:\Dokumente und Einstellungen\user\Desktop\4D_Client_2003_6\4DClient.exe") WinWaitActive("Anmeldung an 4D Server") Send("{space}") WinWaitActive("Benutzer anmelden") Send("^+{TAB 2}") Send("{down}") Send("{TAB}") Send("autoit") Send("{TAB}") ;Input Box $passwd = InputBox("Security Check", "Enter your password.", "", "*") If @error = 1 Then Exit EndIf Send($passwd) Send("{enter}") ;User anlegen WinWaitActive("4D Client") Sleep(1000) Send("^m") Sleep(1000) Send("^n") EndFunc Func SpecialEvents() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE Exit Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE Case @GUI_CtrlId = $GUI_EVENT_RESTORE EndSelect EndFunc ;==>SpecialEvents Edited July 30, 2008 by Kerros Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance. Link to comment Share on other sites More sharing options...
ne0trace Posted July 31, 2008 Author Share Posted July 31, 2008 Hello Kerros, thank you for your help. I somehow expected to have it done line-by-line. As I mentioned before, the script is nowhere to be finish. But thank you for helping me with the buttons. I am still so worried about the fact that I want to control a program that is written in 4D which doesn't seem to use ControlIDs for their windows. I am not the biggest fan of pushing keyboard buttons to create users. I will try the code in about 2h when I will arrive at work. Thank you again Link to comment Share on other sites More sharing options...
ne0trace Posted August 2, 2008 Author Share Posted August 2, 2008 Hello Kerros, I used your edits on the script and it works great. Except for the Start button. To be honest I could not get it working so far. What it doesn't do is close the gui and continue with the script. Looks like this part needs to be refined a little further: Select Case $msg = $Start EndSelect What do you have to put in here to give the button a proper function? thank you Felix Link to comment Share on other sites More sharing options...
ne0trace Posted August 4, 2008 Author Share Posted August 4, 2008 No idea so far? Felix Link to comment Share on other sites More sharing options...
Kerros Posted August 4, 2008 Share Posted August 4, 2008 Felix When I press the Start Button from the code that I put in the above post, I get a message box with either Valid data or Invalid data. If you are getting the message box the start button is working. Are you getting the Message box? If you are not getting the message box, make sure that the code you are working with is what I posted above. I didn't have the GUI hide when continuing the script, to hide the GUI just place GUISetState(@SW_HIDE) after the message box, where the ;login comment is. Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance. Link to comment Share on other sites More sharing options...
ne0trace Posted August 4, 2008 Author Share Posted August 4, 2008 Hello Kerros, the MessageBox works perfect. But when I try to put together a real world example out of your great MessageBox, nothing happens. I tried a lot of approaches and always returned to your example. Right now it mostly looks like this: expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.12.1 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1); OnEvent mode GUICreate("PXM Directory", 400, 300) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") GUICtrlCreateLabel("Please select your option.", 10, 10) GUICtrlCreateLabel("First Name", 10, 55) GUICtrlCreateLabel("Last Name", 10, 85) GUICtrlCreateLabel("Strasse + Nr.", 10, 115) GUICtrlCreateLabel("PLZ", 10, 145) GUICtrlCreateLabel("Mobile Nr.", 10, 175) GUICtrlCreateLabel("Stundensatz", 10, 205) $Firstname = GUICtrlCreateInput("First Name", 100, 50, 200) $Lastname = GUICtrlCreateInput("Last Name", 100, 80) $Street = GUICtrlCreateInput("Strasse + Nr.", 100, 110) $PLZ = GUICtrlCreateInput("PLZ", 100, 140) $MobileNo = GUICtrlCreateInput("Mobile Nr.", 100, 170) $Stdsatz = GUICtrlCreateInput("Stundensatz", 100, 200) $Start = GUICtrlCreateButton("Start", 150, 250, 130) GUICtrlSetOnEvent(-1,"_InputData") GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $Start EndSelect WEnd Func _InputData() If GUICtrlRead($Firstname) <> "First Name" Or '' Then MsgBox(0,'Valid data','Looks good enough to enter') else ;MsgBox(0,'Invalid data','Try something else') return endif ;Login Run("C:\Dokumente und Einstellungen\user\Desktop\4D_Client_2003_6\4DClient.exe") WinWaitActive("Anmeldung an 4D Server") Send("{space}") WinWaitActive("Benutzer anmelden") Send("^+{TAB 2}") Send("{down}") Send("{TAB}") Send("autoit") Send("{TAB}") ;Input Box $passwd = InputBox("Security Check", "Enter your password.", "", "*") If @error = 1 Then Exit EndIf Send($passwd) Send("{enter}") ;User anlegen WinWaitActive("4D Client") Sleep(1000) Send("^m") Sleep(1000) Send("^n") EndFunc Func SpecialEvents() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE Exit Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE Case @GUI_CtrlId = $GUI_EVENT_RESTORE EndSelect EndFunc ;==>SpecialEvents Felix Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted August 4, 2008 Share Posted August 4, 2008 You shouldn't mix OnEvent mode and MessageLoop mode. Decide on 1 and use that. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Kerros Posted August 4, 2008 Share Posted August 4, 2008 Try this expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.12.1 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #AutoIt3Wrapper_Run_Debug_Mode=Y #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> Opt("GUIOnEventMode", 1); OnEvent mode GUICreate("PXM Directory", 400, 300) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") GUICtrlCreateLabel("Please select your option.", 10, 10) GUICtrlCreateLabel("First Name", 10, 55) GUICtrlCreateLabel("Last Name", 10, 85) GUICtrlCreateLabel("Strasse + Nr.", 10, 115) GUICtrlCreateLabel("PLZ", 10, 145) GUICtrlCreateLabel("Mobile Nr.", 10, 175) GUICtrlCreateLabel("Stundensatz", 10, 205) $Firstname = GUICtrlCreateInput("First Name", 100, 50, 200) $Lastname = GUICtrlCreateInput("Last Name", 100, 80) $Street = GUICtrlCreateInput("Strasse + Nr.", 100, 110) $PLZ = GUICtrlCreateInput("PLZ", 100, 140) $MobileNo = GUICtrlCreateInput("Mobile Nr.", 100, 170) $Stdsatz = GUICtrlCreateInput("Stundensatz", 100, 200) $Start = GUICtrlCreateButton("Start", 150, 250, 130, 40, $BS_DEFPUSHBUTTON) GUICtrlSetOnEvent(-1,"_InputData") GUISetState(@SW_SHOW) While 1 sleep(100) WEnd Func _InputData() If GUICtrlRead($Firstname) <> "First Name" Or '' Then ;~ MsgBox(0,'Valid data','Looks good enough to enter') GUISetState(@SW_HIDE) else MsgBox(0,'Invalid data','Try something else') return endif ;Login Run("C:\Dokumente und Einstellungen\user\Desktop\4D_Client_2003_6\4DClient.exe") If @error <> 0 Then MsgBox(48,'4DClient Error','Unable to start 4D Client') Exit EndIf WinWaitActive("Anmeldung an 4D Server") Send("{space}") WinWaitActive("Benutzer anmelden") Send("^+{TAB 2}") Send("{down}") Send("{TAB}") Send("autoit") Send("{TAB}") ;Input Box $passwd = InputBox("Security Check", "Enter your password.", "", "*") If @error = 1 Then Exit EndIf Send($passwd) Send("{enter}") ;User anlegen WinWaitActive("4D Client") Sleep(1000) Send("^m") Sleep(1000) Send("^n") EndFunc Func SpecialEvents() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE Exit Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE Case @GUI_CtrlId = $GUI_EVENT_RESTORE EndSelect EndFunc;==>SpecialEvents I put the debug mode at the top, and also only had the message box if there was invalid data for the first name. The only thing that is being validated at this point is the first name, you would need to check the rest of the fields for valid data as well. Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance. Link to comment Share on other sites More sharing options...
ne0trace Posted August 5, 2008 Author Share Posted August 5, 2008 The Debug Mode!!! Exactly what I've been looking for. Thank you Felix 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