Sign in to follow this  
Followers 0
Obviator

I can't make GUICtrlRead() as i expect

3 posts in this topic

Here's a quick thing that i just can't make work correctly. Put a screen up to capture a user's input. Force that input to lowercase and put it in a variable to replace at a certain place in a third file. My problem is that i cannot get the user's input to tell me anything other than "3." i HAVE to be doing something wrong but darned if i can spot it.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ###
Form=f:\vuwin60\form1.kxf
Local $Form1, $txtInput, $btnOK, $btnCancel, $Label1
 
$Form1 = GUICreate("Enter User ID", 335, 90, -1, -1)  ;343, 140);, $WS_SYSMENU)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
 
$txtInput = GUICtrlCreateInput("", 256, 16, 65, 21)
;GUICtrlSetOnEvent(-1, "txtInputChange")
 
$Label1 = GUICtrlCreateLabel("Please input your IWIMS User ID:", 8, 16, 232, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
;GUICtrlSetOnEvent(-1, "Label1Click")
 
$btnOK = GUICtrlCreateButton("&Ok", 32, 48, 100, 30, $BS_NOTIFY)
;GUICtrlSetResizing(-1, $GUI_DOCKHCENTER+$GUI_DOCKVCENTER+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
GUICtrlSetOnEvent(-1, "btnOKClick")
 
$btnCancel = GUICtrlCreateButton("&Cancel", 200, 48, 100, 30, $BS_NOTIFY)
;GUICtrlSetResizing(-1, $GUI_DOCKHCENTER+$GUI_DOCKVCENTER+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
 
GUICtrlSetOnEvent(-1, "btnCancelClick")
 
GUISetState(@SW_SHOW)
 
#EndRegion ### END Koda GUI section ###
 
While 1
     Sleep(100)
WEnd
 
Func btnCancelClick()
     Exit
EndFunc
 
Func btnOKClick()
     GUICtrlRead($txtInput)
     ConsoleWrite($txtInput & @crlf & StringLen($txtInput) & @CRLF)
     Exit
EndFunc
 
Func Form1Close()
     Exit
EndFunc

Can someone please straighten me out here? i expect the lowercase of whatever the user types in, not just "3."

Thanks,

Dave

Share this post


Link to post
Share on other sites



You aren't displaying the text in the input, you're displaying the control ID for the input.

Func btnOKClick()
     $Temp = GUICtrlRead($txtInput)
     ConsoleWrite($Temp & @crlf & StringLen($Temp) & @CRLF)
     Exit
EndFunc
1 person likes this

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Thanks BrewManNH! Another case of "do what i mean, not what i say" programming!

Dave

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • fopetesl
      By fopetesl
      One statement of GUICtrlRead() fails. Result is always "Long/Short" in written file.
      The other GUICtrlRead() calls work as expected
      Func GetScanSettings() ; Read User Input for scan Local $collectusername, $collectlot, $collectsample $UserFile = "Sample.dat" ; Global $UserFile = save this scan's parameters $datafile = FileOpen($UserFile) If( $datafile <> -1) Then $collectusername = FileReadLine($datafile, 1) EndIf FileClose($datafile) ; now open a new 'clean' file.. $datafile = FileOpen($UserFile,$FO_OVERWRITE ) ;Create GUI $Main = GUICreate('Enter Sample Detail', 500, 500) Opt("GUICoordMode",1) If( $collectusername <> "") Then $username = GUICtrlCreateInput($collectusername,100,20,100,20) Else $username = GUICtrlCreateInput('',100,20,100,20) EndIf $usernamelabel = GUICtrlCreateLabel('Username',30,22) $FileName = GUICtrlCreateInput("",100,45,100,0) $FileNamelabel = GUICtrlCreateLabel('File Name',30,47) $BatchNum = GUICtrlCreateInput("",100,65,100,0) $BatchNumlabel = GUICtrlCreateLabel('Lot',30,72) $SampleNum = GUICtrlCreateInput("",100,85,100,0) $SampleNumlabel = GUICtrlCreateLabel('Sample',30,97) $SampleLS = GUICtrlCreateInput("",100,105,100,0) $SampleNumLS = GUICtrlCreateLabel('Long/Short',30,117) $Button_1 = GUICtrlCreateButton ("OK", 190, 170, 0, 0, 0x0001) GUISetState (); Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() ; complete data entries Select Case $msg = $Button_1 $collectusername = GUICtrlRead($username) WinSetState('Collect Username','',@SW_HIDE) $collectfilename = GUICtrlRead($FileName) $collectlot = GUICtrlRead($BatchNum) $collectsample = GUICtrlRead($SampleNum) $collectLS = GUICtrlRead($SampleNumLS) ; Do ; $collectLS = GUICtrlRead($SampleNumLS) ; If $collectLS <> 'Long' And $collectLS <> 'Short' Then ; Soundplay("Windows XP Error.wav", 1) ; $collectLS = "" ; EndIf ; Until $collectLS = 'Long' Or $collectLS = 'Short' ExitLoop EndSelect Wend GUIDelete($Main) FileWrite($datafile,$collectusername & @CRLF & $collectfilename & @CRLF & $collectlot _ & @CRLF & $collectsample & @CRLF & 'Long' & @CRLF ) ; $collectLS & @CRLF) FileClose($datafile) EndFunc ;<=== GetScanSettings ================== I also tried to force user to enter either 'Short' or 'Long' but I got that wrong also
      The final FileWrite() edited so I do have a correct result.
      sample.dat
      Pete FilenamePete Num1 Samp2 Long/Short  
    • 232showtime
      By 232showtime
      im getting strange output in array display,$split_[1] is not properly aligned to other arrays and why guictrlsetdata is not writting any data if i put comma(,) at the end of the text in $Input1???
       
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> #Region ### START Koda GUI section ### Form=C:\Users\user\Desktop\Script\StringSplit.kxf $Form1 = GUICreate("Form1", 623, 449, 192, 114) $Input1 = GUICtrlCreateInput("50UGITQ421X, 50UGITQ422X, 50UGITQ423X, 50UGITQ427X, 50UGITQ431X, 50UGITQ435X, 50UGITQ436X, 50UGITQ437X, 50UGITQ441X, 50UGITQ445X, 50UGITQ449X, 50UGITQ453X, 50UGITQ454X, 50UGITQ455X, 50UGITQ459X", 24, 16, 553, 21) $Split = GUICtrlCreateButton("Split", 24, 48, 75, 25) $List1 = GUICtrlCreateList("", 24, 96, 553, 97) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Split $read = GUICtrlRead($Input1) $split_ = StringSplit($read, ",") $Max = UBound($split_, 1) For $i = 1 To UBound($split_) - 1 ConsoleWrite($split_[$i] & @CRLF) ;~ ControlSetText($Form1, "", $List1, $split_[$i]) GUICtrlSetData($List1, $split_[$i]) ;~ GUICtrlSetData($List1, $split_[$i]) ;~ GUICtrlSetData($List1, $i) Next _ArrayDisplay($split_) EndSwitch WEnd  
    • 232showtime
      By 232showtime
      Hello World!!!, please I need help I wanted to read the GUICreateInput, I don't know whats wrong with my script.
       
      #include <GUIConstantsEx.au3> #include <GUIListView.au3> #include <GUIListViewEx.au3> GUICreate("My GUI", 300, 100) GUISetState(@SW_SHOW) Local $sInput = GUICtrlCreateInput("", 150, 50, 50, 20) Local $sRead = GUICtrlRead($sInput,0) Local $sAdd = GUICtrlCreateButton("Read", 80, 50, 50, 20) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $iAdd MsgBox(0, "Input!!!", $sRead) EndSwitch WEnd  
    • Skysnake
      By Skysnake
      Hi
      Wiki has this entry: https://www.autoitscript.com/wiki/Label, which differs from the actual Help file.
      I can not READ the value of a LABEL.  Code
      GuiCtrlRead($myLabel)  returns "False". Help appreciated.
    • iresolver
      By iresolver
      Hi guys When I run this part of my script     If GUICtrlRead(Input1) = "" Then on_Close()      it closes that gui window but still sends 0
      I want it to send nothing if the user don't type anything
      anyone know how to fix this?
      thanks
      this is my full script       the   GUICtrlRead(input1) = "" Then on_Close()    is near the bottom of the script
      #RequireAdmin #include <IE.au3> #include <ComboConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <AutoEmail.au3> Opt("GUIOnEventMode", 1) AutoItSetOption ( "TrayIconDebug", 1 ) Global $AutoEmail, $AutoReplace_GUI = 9999, $Gmail_Button, $Hotmail_Button, $AutoReplace_Button = 9999 ; Predeclare the variables with dummy values to prevent firing the Case statements Global $Gmail1_Button, $Gmail2_Button, $Hotmail1_Button, $Hotmail2_Button, $Input1, $Input2, $Input3, $Input4 Global $Gmail, $Hotmail, $cCombo, $cCombo2 Global $sFilename = @ScriptFullPath Global $DataFromUser GUI_AutoEmail() Func GUI_AutoEmail() $AutoEmail = GUICreate("Auto Email", 339, 125, @DesktopWidth, @DesktopHeight) $aTaskbar = WinGetPos("[CLASS:Shell_TrayWnd]", "") $aWin = WinGetPos($AutoEmail) WinMove($AutoEmail, "", @DesktopWidth - $aWin[2] - 4, @DesktopHeight - $aWin[3] - $aTaskbar[3] - 4) GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close") ; Call a common GUI close function $Gmail_Button = GUICtrlCreateButton("Gmail", 64, 16, 49, 41, $BS_ICON) GUICtrlSetImage(-1, "C:\Program Files\AutoEmail\gmail_icon.ico", 1) $Hotmail_Button = GUICtrlCreateButton("Hotmail", 223, 16, 49, 41, $BS_ICON) GUICtrlSetImage(-1, "C:\Program Files\AutoEmail\MSMail_icon.ico", 1) Global $cCombo = GUICtrlCreateCombo("", 16, 72, 145, 25) GUICtrlSetData(-1, "YourAccount1@gmail.com|YourAccount2@gmail.com", "YourAccount1@gmail.com") $cCombo2 = GUICtrlCreateCombo("", 176, 72, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "YourAccount1@hotmail.com|YourAccount2@hotmail.com", "YourAccount1@hotmail.com") Global $msg GUICtrlSetOnEvent(3, "On_Button") GUICtrlSetOnEvent(4, "On_Button") GUICtrlSetOnEvent(-1, "On_Button") ; Call a common button function $AutoReplace_Button = GUICtrlCreateButton("Add Your Email", 10, 100, 80, 30) GUICtrlSetOnEvent(-1, "On_Button") ; Call a common button function GUISetState() EndFunc Func On_Button() Switch @GUI_CTRLID ; See which button sent the message Case $Gmail_Button Gmail() Case $Hotmail_Button Hotmail() Case $AutoReplace_Button GUICtrlSetState($AutoReplace_Button, $GUI_DISABLE) GUI_AutoReplace() Case $Gmail1_Button AddEmail1() Case $Gmail2_Button AddEmail2() Case $Hotmail1_Button AddEmail3() Case $Hotmail2_Button AddEmail4() EndSwitch EndFunc ;--------------------------------------- This is the Main App Read Combos --------------------------------------------------------------------- While 1 Sleep(10) WEnd Func Gmail() $DataFromUser = GUICtrlRead($cCombo) If $DataFromUser = "YourAccount1@gmail.com" Then gmail_login1() EndIf $DataFromUser = GUICtrlRead($cCombo) If $DataFromUser = "YourAccount2@gmail.com" Then gmail_login2() EndIf EndFunc Func Hotmail() $DataFromUser = GUICtrlRead($cCombo2) If $DataFromUser = "YourAccount1@hotmail.com" Then hotmail_login1() EndIf $DataFromUser = GUICtrlRead($cCombo2) If $DataFromUser = "YourAccount2@hotmail.com" Then hotmail_login2() EndIf EndFunc ;----------------------------------------------------- This sends account info to web Browser & Logs in ------------------------------------------------------------ Func gmail_login1() Sleep (60) Global $oIE =_IECreate ("https://accounts.google.com/ServiceLogin?sacu=1&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fpc%3Dtopnav-about-en&hl=en&service=mail") local $username = _IEGetObjByName ($oIE, "Email") Local $password = _IEGetObjByName ($oIE, "Passwd") Local $Email_button = _IEGetObjByName ($oIE, "Email") Local $Signin_button = _IEGetObjByName ($oIE,"signIn") _IEFormElementSetValue ($username, "YourAccount1@gmail.com") ;<===== Here you put your Gmail Account Name _IEFormElementSetValue ($password, "Your Password") ;<===== Here you put your Gmail Account Password _IEAction ($Email_button, "click") _IEAction ($Signin_button, "click") EndFunc Func gmail_login2() Sleep(60) Global $oIE =_IECreate ("https://accounts.google.com/ServiceLogin?sacu=1&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fpc%3Dtopnav-about-en&hl=en&service=mail") local $username = _IEGetObjByName ($oIE, "Email") Local $password = _IEGetObjByName ($oIE, "Passwd") Local $Email_button = _IEGetObjByName ($oIE, "account-email") Local $Signin_button = _IEGetObjByName ($oIE,"signIn") _IEFormElementSetValue ($username, "YourAccount2@gmail.com") ;<===== Here you put your 2nd Gmail Account Name _IEFormElementSetValue ($password, "Your Password") ;<===== Here you put your 2nd Gmail Account Password _IEAction ($Email_button, "click") _IEAction ($Signin_button, "click") EndFunc Func hotmail_login1() Sleep(60) Global $oIE =_IECreate ("http://www.live.com") local $username = _IEGetObjByName ($oIE, "login") Local $password = _IEGetObjByName ($oIE, "passwd") Local $Signin_button = _IEGetObjByName ($oIE,"SI") _IEFormElementSetValue ($username, "YourAccount1@hotmail.com") ;<===== Here you put your Hotmail Account Name _IEFormElementSetValue ($password, "Your Password") ;<===== Here you put your Hotmail Account Password _IEAction ($Signin_button, "click") EndFunc Func hotmail_login2() Sleep(60) Global $oIE =_IECreate ("http://www.live.com") local $username = _IEGetObjByName ($oIE, "login") Local $password = _IEGetObjByName ($oIE, "passwd") Local $Signin_button = _IEGetObjByName ($oIE,"SI") _IEFormElementSetValue ($username, "YourAccount2@hotmail.com") ;<===== Here you put your Hotmail Account Name _IEFormElementSetValue ($password, "Your Password") ;<===== Here you put your Hotmail Account Password _IEAction ($Signin_button, "click") EndFunc Func On_Close() Switch @GUI_WINHANDLE ; See which GUI sent the CLOSE message Case $AutoEmail Exit ; If it was this GUI - we exit <<<<<<<<<<<<<<< Case $AutoReplace_GUI GUIDelete($AutoReplace_GUI) ; If it was this GUI - we just delete the GUI <<<<<<<<<<<<<<< GUICtrlSetState($AutoReplace_Button, $GUI_ENABLE) EndSwitch EndFunc Func GUI_AutoReplace() $AutoReplace_GUI = GUICreate("Auto Add Email", 474, 324, 969, 306) $Input1 = GUICtrlCreateInput("", 24, 32, 329, 21) $Gmail1_Button = GUICtrlCreateButton("Add Gmail", 360, 30, 89, 25) $Label_AddGmail1 = GUICtrlCreateLabel("Type Your Gmail Account1", 24, 8, 131, 17) $Input2 = GUICtrlCreateInput("", 24, 106, 329, 21) $Gmail2_Button = GUICtrlCreateButton("Add Gmail", 360, 104, 89, 25) $Label_AddGmail2 = GUICtrlCreateLabel("Type Your Gmail Account2", 24, 82, 131, 17) $Input3 = GUICtrlCreateInput("", 24, 183, 329, 21) $Hotmail1_Button = GUICtrlCreateButton("Add Hotmail", 360, 181, 89, 25) $Label1 = GUICtrlCreateLabel("Type Your Hotmail Account1", 21, 159, 140, 17) $Input4 = GUICtrlCreateInput("", 24, 257, 329, 21) $Hotmail2_Button = GUICtrlCreateButton("Add Hotmail", 360, 255, 89, 25) $Label2 = GUICtrlCreateLabel("Type Your Homail Account2", 21, 233, 137, 17) GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close") ; Call a common GUI close function GUICtrlSetOnEvent(-1, "On_Button") ; Call a common button function GUICtrlSetOnEvent(9, "On_Button") GUICtrlSetOnEvent(12, "On_Button") GUICtrlSetOnEvent(15, "On_Button") GUICtrlSetOnEvent(18, "On_Button") GUICtrlSetOnEvent(3, "On_Button") GUICtrlSetOnEvent(4, "On_Button") GUISetState() EndFunc Func AddEmail1() If GUICtrlRead($Input1) = "" Then On_Close() $DataFromUser = GUICtrlRead($Input1) _ReplaceStringInFile ($sFilename, $sFindg1, $DataFromUser) ;FileSaveDialog("Save File", @ScriptDir, "Au3 Files (*.au3)", 16) EndFunc Func AddEmail2() If GUICtrlRead($Input2) = "" Then On_Close() $DataFromUser = GUICtrlRead($Input2) _ReplaceStringInFile ($sFilename, $sFindg2, $DataFromUser) ;FileSaveDialog("Save File", @ScriptDir, "Au3 Files (*.au3)", 16) EndFunc Func AddEmail3() If GUICtrlRead($Input3) = "" Then On_Close() $DataFromUser = GUICtrlRead($Input3) _ReplaceStringInFile ($sFilename, $sFindh1, $DataFromUser) ;FileSaveDialog("Save File", @ScriptDir, "Au3 Files (*.au3)", 16) EndFunc Func AddEmail4() If GUICtrlRead($Input4) = "" Then On_Close() $DataFromUser = GUICtrlRead($Input4) _ReplaceStringInFile ($sFilename, $sFindh2, $DataFromUser) ;FileSaveDialog("Save File", @ScriptDir, "Au3 Files (*.au3)", 16) EndFunc