joeloyzaga Posted August 2, 2009 Share Posted August 2, 2009 I'm using the example _LoginBox and I'm a newbie (feels like I will be forever) and I'd like to add an input box before the username/ password prompt. I am sure I can display a new gui box with the values received and also to the include 2 checkboxes but I wonder how to add the input box with the example script? can you explain please? the code is below expandcollapse popupOpt("GUICoordMode", " 2") $ret = _GUICreateLogin("Enter Credentials", "Enter the username and password", -1, -1, -1, -1, -1, 100000) If @error Then MsgBox(0, "Error", "Error Returned: " & $ret & @CRLF & "Error Code: " & @error & @CRLF & "Extended: " & @extended) Else MsgBox(0, "Credentails Returned", "Username: " & $ret[0] & @CRLF & "Password: " & $ret[1]) EndIf ;=============================================================================== ; Function Name: _GUICreateLogin() ; Description: Create a basic login box with Username, Password, and a prompt. ; Syntax: ; Parameter(s): $hTitle - The title of the Form ; $hPrompt - The text prompt for the user [Optional] (maximum of 2 lines) ; $bBlank - The password or username can be blank. [optional] ; Default = False (Blanks are not allowed) ; $hWidth - Width of the form [optional] - default = 250 ; $hHeight - Height of the form [optional] - default = 130 ; $hLeft - X position [optional] - default = centered ; $hTop - Y position [optional] - default = centered ; $Timeout - The timeout of the form [optional - default = 0 (no timeout) ; $ShowError - Prompts are displayed to the user with timeout [optional] ; Requirement(s): None ; Return Value(s): Success - Returns an array of 2 elements where ; [0] = UserName ; [1] = Password ; Failure - Sets @Error to 1 and ; @Extended - 1 = Cancel/Exit Button Pressed ; - 2 = Timed out ; Author(s): Brett Francis (exodus.is.me@hotmail.com) ; Modification(s): GeoSoft ; Note(s): If $hPrompt is blank then the GUI height will be reduced by 30 ; Example(s): ;=============================================================================== Func _GUICreateLogin($hTitle, $hPrompt = "", $bBlank = False, $hWidth = -1, $hHeight = -1, $hLeft = -1, $hTop = -1, $timeout = 0, $ShowError = 0) If Not $hTitle Then $hTitle = "Login" $iGCM = Opt("GUICoordMode", 2);; Get the current value of GUICoordMode and set it to 2 If StringRegExp($bBlank, "(?i)\s|default|-1") Then $bBlank = False If StringRegExp($hWidth, "(?i)\s|default|-1") Then $hWidth = 250 If StringRegExp($hHeight, "(?i)\s|default|-1") Then $hHeight = 130 If StringRegExp($hLeft, "(?i)\s|default|-1") Then $hLeft = (@DesktopWidth / 2) - ($hWidth / 2) If StringRegExp($hTop, "(?i)\s|default|-1") Then $hTop = (@DesktopHeight / 2) - ($hHeight / 2) If Not $hPrompt Then $hHeight -= 30;If $hPrompt is blank then resize the GUI. Local $retarr[2] = ["", ""], $Time = 0 Local $gui = GUICreate($hTitle, $hWidth, $hHeight, $hLeft, $hTop) GUISetCoord(4, 0) If $hPrompt Then Local $Lbl_Prompt = GUICtrlCreateLabel($hPrompt, -1, 4, 201, 30) Local $Lbl_User = GUICtrlCreateLabel("Username:", -1, 4, 64, 17);44, 64, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") Local $username = GUICtrlCreateInput('', 8, -1, $hWidth - 81, 21) GUICtrlCreateLabel("Password:", -($hWidth - 8), 4, 65, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") Local $password = GUICtrlCreateInput('', 8, -1, $hWidth - 81, 21, 32);, $ES_PASSWORD) GUISetCoord(($hWidth / 2) - 85, $hHeight - 34) Local $Btn_OK = GUICtrlCreateButton("&OK", -1, -1, 75, 25) Local $Btn_Cancel = GUICtrlCreateButton("&Cancel", 20, -1, 75, 25) GUICtrlSetState($Btn_OK, 512) GUISetState() If $timeout Then $Time = TimerInit() While 1 $Msg = GUIGetMsg() Local $sUser = GUICtrlRead($username) Local $sPass = GUICtrlRead($password) If ($Time And TimerDiff($Time) >= $timeout) And ($sUser = "" And $sPass = "") Then $Status = 2 ExitLoop EndIf Select Case $Msg = -3 $Status = 0 ExitLoop Case $Msg = $Btn_OK If $bBlank And ($sUser = "" Or $sPass = "") Then $Status = 1 ExitLoop Else If $sUser <> "" And $sPass <> "" Then $Status = 1 ExitLoop Else Select Case $sUser = "" And $sPass = "" If $ShowError = 1 Then MsgBox(16, "Error!", "Username and Password cannot be blank!") Case $sPass = "" If $ShowError = 1 Then MsgBox(16, "Error!", "Password cannot be blank!") GUICtrlSetState($password, 256) Case $sUser = "" If $ShowError = 1 Then MsgBox(16, "Error!", "Username cannot be blank!") GUICtrlSetState($username, 256) EndSelect EndIf EndIf Case $Msg = $Btn_Cancel $Status = 0 ExitLoop Case $timeout And TimerDiff($Time) >= $timeout; And $timeout If $bBlank And ($sUser = "" Or $sPass = "") Then $Status = 2 ExitLoop Else ;$time = TimerInit() Select Case $sUser = "" And $sPass = "" If $timeout Then $Time = TimerInit() If $ShowError = 1 Then MsgBox(16, "Error!", "Username and Password cannot be blank!") Case $sPass = "" If $timeout Then $Time = TimerInit() If $ShowError = 1 Then MsgBox(16, "Error!", "Password cannot be blank!") GUICtrlSetState($password, 256) EndIf Case $sUser = "" $Time = TimerInit() If $ShowError = 1 Then MsgBox(16, "Error!", "Username cannot be blank!") GUICtrlSetState($username, 256) EndIf ;Case ($Timeout AND TimerDiff($time) >= $timeout) AND ($sUser = "" OR $sPass = "") ;$status = 2 ;ExitLoop Case Else If $sUser <> "" And $sPass <> "" Then $Status = 3 ;If $Timeout AND TimerDiff($time) >= $timeout Then $Status = 2 ExitLoop EndIf EndSelect EndIf EndSelect WEnd Local $eMsg = "" Switch $Status Case 0, 2 $err = 1;0 $ext = 1;Cancel/Exit Button Pressed $eMsg = "Cancel/Exit Button Pressed" If $Status = 2 Then $ext = 2;Timed Out If $ext = 2 Then $eMsg = "Timed Out" Case Else;1, 3 $retarr[0] = $sUser $retarr[1] = $sPass $err = 0;1 $ext = 0 If $Status = 3 Then $ext = 1;Username Fields Not Blank, Timeout reached EndSwitch GUIDelete($gui) Opt("GUICoordMode", $iGCM);Reset the GUICoordMode to what it started as. If $eMsg Then Return SetError($err, $ext, $eMsg) Return $retarr EndFunc ;==>_GUICreateLogin Link to comment Share on other sites More sharing options...
GEOSoft Posted August 2, 2009 Share Posted August 2, 2009 See InputBox() in the help file and put it before the line$ret = _GUICreateLogin("Enter Credentials", "Enter the username and password", -1, -1, -1, -1, -1, 100000) George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
joeloyzaga Posted August 3, 2009 Author Share Posted August 3, 2009 See InputBox() in the help file and put it before the lineCan't I modify the _GUICreateLogin function to include the input box? Link to comment Share on other sites More sharing options...
BrettF Posted August 3, 2009 Share Posted August 3, 2009 Just create your own GUI... >_ Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
joeloyzaga Posted August 3, 2009 Author Share Posted August 3, 2009 (edited) thats an option but it would be a better solution to work with the one already there? And it would help me learn how this is done as I'm a newbie Edited August 3, 2009 by joeloyzaga Link to comment Share on other sites More sharing options...
joeloyzaga Posted August 3, 2009 Author Share Posted August 3, 2009 Ok Brettf, I tried, got some errors that I dont understand expandcollapse popup;region Script Settings ;<scriptSettings xmlns="http://tempuri.org/ScriptSettings.xsd"> ; <scriptPackager> ; <process>autoit3.exe</process> ; <arguments /> ; <extractdir>%TEMP%</extractdir> ; <files /> ; <usedefaulticon>true</usedefaulticon> ; <showinsystray>false</showinsystray> ; <altcreds>false</altcreds> ; <efs>true</efs> ; <ntfs>true</ntfs> ; <local>false</local> ; <abortonfail>true</abortonfail> ; <product /> ; <version>1.0.0.1</version> ; <versionstring /> ; <comments /> ; <includeinterpreter>false</includeinterpreter> ; <forcecomregistration>false</forcecomregistration> ; <consolemode>false</consolemode> ; <EnableChangelog>false</EnableChangelog> ; <AutoBackup>false</AutoBackup> ; <snapinforce>false</snapinforce> ; <snapinshowprogress>false</snapinshowprogress> ; <snapinautoadd>0</snapinautoadd> ; <snapinpermanentpath /> ; </ScriptPackager> ;</ScriptSettings> ;endregion #include <ButtonConstants.au3> #include <GUIConstantsEx.au3>; #include <EditConstants.au3> ProgressOn("Load Program", "Open Program", "0%"); Just to let more beautiful For $i = 10 To 100 Step 10 Sleep(100) ProgressSet($i, $i & "%") Next ProgressSet(100, "Full Load", "Complete") Sleep(100) ProgressOff() Global $tdc, $qcServer, $qcHostName, $qcPort, $qcProject Global $qcDomain, $qcUser, $qcPassword Global $USERNAME, $PASSWORD, $CONNECTIONURL $Form1 = GUICreate("Login", 400, 250, -1, -1); begining of Login $connectionurllabel = GUICtrlCreateLabel("Connection URL:", 8, 202, 150, 17) $CONNECTIONURL = GUICtrlCreateInput("http://qualitycenter.test.det.nsw.edu.au:8080/qcbin/", 65, 204, 280, 21) $PASSWORD = GUICtrlCreateInput("", 65, 167, 220, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL)) $ButtonOk = GUICtrlCreateButton("&OK", 200, 220, 75, 25, 0) $ButtonCancel = GUICtrlCreateButton("&Cancel", 280, 220, 75, 25, 0) $passwordlabel = GUICtrlCreateLabel("Password:", 8, 172, 50, 17) $usernamelabel = GUICtrlCreateLabel("Username:", 8, 143, 52, 17) $USERNAME = GUICtrlCreateInput("", 65, 144, 220, 21) GUICtrlCreateGroup('',10,2,380,100) GUICtrlCreateLabel('',30,10,340,18) GUICtrlSetColor(-1, 0x0012FF) GUICtrlSetFont(-1,12,400) GUICtrlCreateLabel('HP Export_without HTML',30,28,340,18) GUICtrlSetFont(-1,12,400) #GUICtrlCreateLabel('',30,46,340,18) GUICtrlSetFont(-1,12,400) #GUICtrlCreateLabel('To open the program',30,64,340,18) GUICtrlSetFont(-1,12,400) #GUICtrlCreateLabel('Team gOHc Thank you for your choice',30,82,340,18) GUICtrlSetFont(-1,12,400) GUICtrlCreateGroup('',-99,-99,1,1) GUICtrlSetBkColor(-1,0x000000) GUISetState(@SW_SHOW) While 1 $MSG = GUIGetMsg() Switch $MSG Case $ButtonOk If VerifyLogin(GUICtrlRead($USERNAME),GUICtrlRead($PASSWORD)) = 1 Then GUIDelete($Form1) MsgBox(-1, " ", "Login Succ..") $qcHostName = "qualitycenter.test.det.nsw.edu.au" $qcPort = "8080" ConsoleWrite($USERNAME) $qcServer = "http://" & $qcHostName & ":" & $qcPort & "/qcbin" $qcUser = $USERNAME $qcPassword = $PASSWORD ConsoleWrite($CONNECTIONURL) $qcServer = $CONNECTIONURL $qcDomain = "DEFAULT" $qcProject = "AUTOMATION" Global $tdc = ObjCreate("TDApiOle80.TDConnection") $tdc.InitConnectionEx($qcServer) consoleWrite($tdc.ServerName) $tdc.Login($qcUser, $qcPassword) RunP() Else MsgBox(-1,"Error"," Username incorrect, Enter new username") EndIf Case -3 Exit Case $ButtonCancel Exit EndSwitch WEnd Func VerifyLogin($USERNAME,$PASSWORD) If $USERNAME = "Scitest015" And $PASSWORD = "Password1" Then ConsoleWrite($USERNAME) Return 1 Else Return 0 EndIf EndFunc; End login Func Runp() ;Your Code begining here EndFunc Func onautoitexit() Exit EndFunc ;==>onautoitexit Link to comment Share on other sites More sharing options...
somdcomputerguy Posted August 3, 2009 Share Posted August 3, 2009 Use Function GUICtrlCreateInput before this line Local $username = GUICtrlCreateInput('', 8, -1, $hWidth - 81, 21) - Bruce /*somdcomputerguy */Â If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
joeloyzaga Posted August 3, 2009 Author Share Posted August 3, 2009 Use Function GUICtrlCreateInput before this line Local $username = GUICtrlCreateInput('', 8, -1, $hWidth - 81, 21) where? aren't I doing this call already? Link to comment Share on other sites More sharing options...
somdcomputerguy Posted August 3, 2009 Share Posted August 3, 2009 You must've posted your code while I was making my previous post, so I didn't see that. - Bruce /*somdcomputerguy */Â If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
joeloyzaga Posted August 4, 2009 Author Share Posted August 4, 2009 I now get this and even if its still an error - its at least doing something - can anyone help? >"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "K:\Autoit-workarea\login.au3" scitest0154K:\Autoit-workarea\login.au3 (99) : ==> The requested action with this object has failed.: $tdc.InitConnectionEx($qcServer) $tdc.InitConnectionEx($qcServer)^ ERROR >Exit code: 1 Time: 36.737 expandcollapse popup;region Script Settings ;<scriptSettings xmlns="http://tempuri.org/ScriptSettings.xsd"> ; <scriptPackager> ; <process>autoit3.exe</process> ; <arguments /> ; <extractdir>%TEMP%</extractdir> ; <files /> ; <usedefaulticon>true</usedefaulticon> ; <showinsystray>false</showinsystray> ; <altcreds>false</altcreds> ; <efs>true</efs> ; <ntfs>true</ntfs> ; <local>false</local> ; <abortonfail>true</abortonfail> ; <product /> ; <version>1.0.0.1</version> ; <versionstring /> ; <comments /> ; <includeinterpreter>false</includeinterpreter> ; <forcecomregistration>false</forcecomregistration> ; <consolemode>false</consolemode> ; <EnableChangelog>false</EnableChangelog> ; <AutoBackup>false</AutoBackup> ; <snapinforce>false</snapinforce> ; <snapinshowprogress>false</snapinshowprogress> ; <snapinautoadd>0</snapinautoadd> ; <snapinpermanentpath /> ; </ScriptPackager> ;</ScriptSettings> ;endregion #include <ButtonConstants.au3> #include <GUIConstantsEx.au3>; #include <EditConstants.au3> ProgressOn("Load Program", "Open Program", "0%"); Just to let more beautiful For $i = 10 To 100 Step 10 Sleep(100) ProgressSet($i, $i & "%") Next ProgressSet(100, "Full Load", "Complete") Sleep(100) ProgressOff() Global $tdc, $qcServer, $qcHostName, $qcPort, $qcProject Global $qcDomain, $qcUser, $qcPassword Global $USERNAME, $PASSWORD, $CONNECTIONURL $Form1 = GUICreate("Login", 400, 350, -1, -1); begining of Login $connectionurllabel = GUICtrlCreateLabel("Connection URL:", 8, 202, 150, 17) $CONNECTIONURL = GUICtrlCreateInput("http://qualitycenter.test.det.nsw.edu.au:8080/qcbin/", 65, 204, 280, 21) $PASSWORD = GUICtrlCreateInput("", 65, 167, 220, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL)) $ButtonOk = GUICtrlCreateButton("&OK", 200, 260, 75, 25, 0) $ButtonCancel = GUICtrlCreateButton("&Cancel", 280, 260, 75, 25, 0) $passwordlabel = GUICtrlCreateLabel("Password:", 8, 172, 50, 17) $usernamelabel = GUICtrlCreateLabel("Username:", 8, 143, 52, 17) $USERNAME = GUICtrlCreateInput("", 65, 144, 220, 21) GUICtrlCreateGroup('',10,2,380,100) GUICtrlCreateLabel('',30,10,340,18) GUICtrlSetColor(-1, 0x0012FF) GUICtrlSetFont(-1,12,400) GUICtrlCreateLabel('HP Export_without HTML',30,28,340,18) GUICtrlSetFont(-1,12,400) #GUICtrlCreateLabel('',30,46,340,18) GUICtrlSetFont(-1,12,400) #GUICtrlCreateLabel('To open the program',30,64,340,18) GUICtrlSetFont(-1,12,400) #GUICtrlCreateLabel('Team gOHc Thank you for your choice',30,82,340,18) GUICtrlSetFont(-1,12,400) GUICtrlCreateGroup('',-99,-99,1,1) GUICtrlSetBkColor(-1,0x000000) GUISetState(@SW_SHOW) While 1 $MSG = GUIGetMsg() Switch $MSG Case $ButtonOk If VerifyLogin(GUICtrlRead($USERNAME),GUICtrlRead($PASSWORD)) = 1 Then GUIDelete($Form1) MsgBox(-1, " ", "Login Succ..") $qcHostName = "qualitycenter.test.det.nsw.edu.au" $qcPort = "8080" ;ConsoleWrite($USERNAME) ;ConsoleWrite("USERNAME:") $qcServer = "http://" & $qcHostName & ":" & $qcPort & "/qcbin" $qcUser = $USERNAME $qcPassword = $PASSWORD ConsoleWrite($CONNECTIONURL) $qcServer = $CONNECTIONURL $qcDomain = "DEFAULT" $qcProject = "AUTOMATION" ;MsgBox(-1,"Error",$USERNAME) Global $tdc = ObjCreate("TDApiOle80.TDConnection") $tdc.InitConnectionEx($qcServer) $tdc.Login($qcUser, $qcPassword) consoleWrite($tdc.ServerName) RunP() Else MsgBox(-1,"Error"," Username incorrect, Enter new username") EndIf Case -3 Exit Case $ButtonCancel Exit EndSwitch WEnd Func VerifyLogin($USERNAME,$PASSWORD) If $USERNAME = "Scitest015" And $PASSWORD = "Password1" Then ConsoleWrite($USERNAME) Return 1 Else Return 0 EndIf EndFunc; End login Func Runp() ;Your Code begining here EndFunc Func onautoitexit() Exit EndFunc ;==>onautoitexit Link to comment Share on other sites More sharing options...
joeloyzaga Posted August 6, 2009 Author Share Posted August 6, 2009 if I use the actual ahrd coded string values then the initconnection works - but not when i use the variable I use to retrieve the value $qcHostName = "qualitycenter.test.det.nsw.edu.au" $qcPort = "8080" ;ConsoleWrite($USERNAME) ;ConsoleWrite("USERNAME:") $qcServer = "http://" & $qcHostName & ":" & $qcPort & "/qcbin" $qcServer = "http://qualitycenter.test.det.nsw.edu.au:8080/qcbin/" $qcUser = $USERNAME $qcPassword = $PASSWORD ConsoleWrite($CONNECTIONURL) $qcServer = $CONNECTIONURL $qcDomain = "DEFAULT" $qcProject = "AUTOMATION" ;MsgBox(-1,"Error",$USERNAME) Global $tdc = ObjCreate("TDApiOle80.TDConnection") $tdc.InitConnectionEx("http://qualitycenter.test.det.nsw.edu.au:8080/qcbin/") $tdc.InitConnectionEx($qcServer) Link to comment Share on other sites More sharing options...
GEOSoft Posted August 6, 2009 Share Posted August 6, 2009 Try using one of these ; $qcServer = Chr(34) & "http://" & $qcHostName & ":" & $qcPort & "/qcbin" & Chr(34) ;;or $qcServer = '"http://' & $qcHostName & ":" & $qcPort & '/qcbin"' ; George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
joeloyzaga Posted August 6, 2009 Author Share Posted August 6, 2009 Try using one of these ; $qcServer = Chr(34) & "http://" & $qcHostName & ":" & $qcPort & "/qcbin" & Chr(34) ;;or $qcServer = '"http://' & $qcHostName & ":" & $qcPort & '/qcbin"' ; tried it and got an error - attached I also have to use the $USERNAME, $PASSWORD variables and they don't contain values - could you explain this to me so I don't keep asking???????????? 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