dash007 Posted March 9, 2005 Share Posted March 9, 2005 Hi all, Only just heard of Autoit and think its marvellous. I am not good at coding, but had success in writing some executables. However below is a piece of a code I find I am having problems. 1) In the below example, how can I have bullets instead of asterisk when entering password? Bullets look better. 2) In the line "$Input_1 = GuiCtrlCreateInput("0", 10, 20, 150, 20, $ES_NUMBER)" how can you restrict the input numbers to 12. I don't want people to enter more than 12 digits. 3) When you run the below script and enter password 'test', you will be given three buttons to choose from. When you select the Test button and choose YES in the dialog box that popsup, it popsup another dialog box asking for user input. This is where I have the problem. I can input data into this box, but the OK and Cancel or cross mark don't work. The only way to force this dialogbox to quit is via the system tray and rightclicking to EXIT. Please assist... CODE $bLoop = 1 While $bLoop = 1 $passwd = InputBox("test", " Please enter password:", "", "*") If @error = 1 Then Exit Else If $passwd <> "test" Then MsgBox(4096, "Error", "Wrong Password!") Else $bLoop = 0 EndIf EndIf WEnd ; -------------------------------------------------------------- #include <GUIConstants.au3> Opt("GUIOnEventMode",1) GUICreate("Test", 265, 65) $Button_1 = GuiCtrlCreateButton("test", 10, 22, 80, 24) GUICtrlSetOnEvent($Button_1,"OnB1") $Button_2 = GuiCtrlCreateButton("Calculator", 100, 22, 80, 24) GUICtrlSetOnEvent($Button_2,"OnB2") $ExitID = GUICtrlCreateButton("Exit", 190, 22, 80, 24) GUICtrlSetOnEvent($ExitID,"OnExit") GUISetOnEvent($GUI_EVENT_CLOSE,"OnExit") GUISetState() ; display the GUI While 1 Sleep (1000) WEnd ;--------------- Functions --------------- Func OnB1() If FileExists("C:\test\test.txt") Then $file = FileOpen("C:\test\test.txt", 0) $line = FileReadLine($file ,2) $answer = MsgBox(4, "test:", "File found, do you want to edit this?") Else $answer = MsgBox(4, "test:", "File not found do you wish to continue?") EndIf If $answer = 7 Then Exit EndIf #include <GuiConstants.au3> If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000 GuiCreate("test", 171, 85, (@DesktopWidth-171)/2, (@DesktopHeight-85)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) $Input_1 = GuiCtrlCreateInput("0", 10, 20, 150, 20, $ES_NUMBER) GUICtrlSetState(-1,$GUI_FOCUS) $ok = GuiCtrlCreateButton("OK", 10, 54, 70, 20) $cancel = GuiCtrlCreateButton("Cancel", 90, 54, 70, 20) GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $cancel Exit Case $msg = $ok msgbox(0, "test", "Data changed to:" & @CRLF & GuiCtrlRead($Input_1)) ExitLoop Case Else EndSelect WEnd If FileExists("C:\test\test.txt") Then Else DirCreate("C:\test") EndIf $file = FileOpen("C:\test\test.txt", 2) If $file = -1 Then MsgBox(0, "Error", "Unable to open file") Exit EndIf FileWriteLine($file, "Data=" & GuiCtrlRead($Input_1)) EndFunc ;---------------------------------------------------------- Func OnB2() RUN("calc.exe") EndFunc ;------------------------------------------------------------ Func OnExit() Exit EndFunc ;--------------------------END CODE------------------------------------------ Link to comment Share on other sites More sharing options...
Andre Posted March 9, 2005 Share Posted March 9, 2005 Hi, For question 1. Here is the answer. $passwd = InputBox("test", " Please enter password:", "", chr(149)) Andre What about Windows without using AutoIt ?It would be the same as driving a car without an steering Wheel! Link to comment Share on other sites More sharing options...
dash007 Posted March 9, 2005 Author Share Posted March 9, 2005 Hi,For question 1.Here is the answer.$passwd = InputBox("test", " Please enter password:", "", chr(149))Andre<{POST_SNAPBACK}>Thank you Andre, that worked beautifully... Now waiting for the answers to my second and third question. Link to comment Share on other sites More sharing options...
layer Posted March 9, 2005 Share Posted March 9, 2005 for question two, GUICtrlSetLimit($Input_1, 12) FootbaG Link to comment Share on other sites More sharing options...
Nutster Posted March 9, 2005 Share Posted March 9, 2005 (edited) for question two,GUICtrlSetLimit($Input_1, 12)<{POST_SNAPBACK}>Or back to InputBox:$passwd = InputBox("test", " Please enter password:", "", chr(149) & "M12")The "M12" at the end of the password character field tell InputBox that input is Manditory and limit input to 12 characters.Edit: Fix speeling errors. Edited March 9, 2005 by Nutster David NuttallNuttall Computer Consulting An Aquarius born during the Age of Aquarius AutoIt allows me to re-invent the wheel so much faster. I'm off to write a wizard, a wonderful wizard of odd... Link to comment Share on other sites More sharing options...
dash007 Posted March 9, 2005 Author Share Posted March 9, 2005 Nutster and Layer, thank you so much for your suggestions. For now I have used Layer's suggestion in my code and it works fine. I also tried Nutster's suggestion as I needed it in other scripts and that too works fine. Now that the cosmetic changes are out of the way (question 1 and 2), I am hoping for an an answer to my third and most important question as my script is not completely functional. When you copy the part of the offending code to another script as a standalone it works fine (see the code below). It does exactly what its supposed to do and quits correctly too. However when this code is copied to the overallcode (see the firstpartof this thread), it doesn't do what its supposed to do. The input box doesn't submit to OK or Cancel. Please help. The offending code that works as a standalone is as below: CODE: If FileExists("C:\test\test.txt") Then $file = FileOpen("C:\test\test.txt", 0) $line = FileReadLine($file ,2) $answer = MsgBox(4, "test:", "File found, do you want to edit this?") Else $answer = MsgBox(4, "test:", "File not found do you wish to continue?") EndIf If $answer = 7 Then Exit EndIf #include <GuiConstants.au3> If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000 GuiCreate("test", 171, 85, (@DesktopWidth-171)/2, (@DesktopHeight-85)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) $Input_1 = GuiCtrlCreateInput("0", 10, 20, 150, 20, $ES_NUMBER) GUICtrlSetLimit($Input_1, 12) GUICtrlSetState(-1,$GUI_FOCUS) $ok = GuiCtrlCreateButton("OK", 10, 54, 70, 20) $cancel = GuiCtrlCreateButton("Cancel", 90, 54, 70, 20) GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $cancel Exit Case $msg = $ok msgbox(0, "test", "Data changed to:" & @CRLF & GuiCtrlRead($Input_1)) ExitLoop Case Else EndSelect WEnd If FileExists("C:\test\test.txt") Then Else DirCreate("C:\test") EndIf $file = FileOpen("C:\test\test.txt", 2) If $file = -1 Then MsgBox(0, "Error", "Unable to open file") Exit EndIf FileWriteLine($file, "Data=" & GuiCtrlRead($Input_1)) ;------end code------------------ 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