fopetesl

GUICtrlRead() fails

7 posts in this topic

#1 ·  Posted (edited)

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

 

Edited by fopetesl
Typo!

The most powerful number in the Universe.  Zero.

Share this post


Link to post
Share on other sites



#2 ·  Posted

Your reading the label not the input.

1 person likes this

Share this post


Link to post
Share on other sites

#3 ·  Posted

4 minutes ago, Subz said:

Your reading the label not the input.

Oops! Thanks.

Now how do I force user to enter either Short or Long?


The most powerful number in the Universe.  Zero.

Share this post


Link to post
Share on other sites

#4 ·  Posted

$collectLS = GUICtrlRead($SampleLS)

 

1 person likes this

Share this post


Link to post
Share on other sites

#5 ·  Posted

2 minutes ago, LerN said:
$collectLS = GUICtrlRead($SampleLS)

 

Yeah. Works. A lesson in being more careful in naming variables!

Now. Forcing user input?


The most powerful number in the Universe.  Zero.

Share this post


Link to post
Share on other sites

#6 ·  Posted

Couple of ways, you could use a Radio or ComboBox as a control, which makes the user select Long or Short.  Also after the $collectLS = GuiCtrlRead($SampleLS)  you can use something like: 

$collectLS = GUICtrlRead($SampleLS)
Switch $collectLS
    Case "Long"
    Case "Short"
    Case Else
        MsgBox(0, "Selection", "Please Select Long/Short")
        ContinueLoop
EndSwitch

 

1 person likes this

Share this post


Link to post
Share on other sites

#7 ·  Posted

:) Something new every day.

'ContinueLoop'   Magic

Works like a charm.


The most powerful number in the Universe.  Zero.

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

  • Similar Content

    • 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
    • souldjer777
      By souldjer777
      Good Morning Yes, it's 12 AM here LOL.. so can't say good evening... anywho lol... it's late and I'm losing it haha sry... Love you guys, love the apps and all the support!
      I have somewhat lost my mind in the forums and trying to get my gui to update a label from an input box  on the same gui without the gui flashing like crazy... Point is I want to take that user input and VISUALLY use it to update the text in the rest of the gui... Is this possible without this insane flicker / flashing every time the mouse moves?
      Am I attacking this the wrong way? I know people have used OnEvent Mode - but I need  it where folks type... not just when the mouse moves or clicks...
       $GUI_EVENT_MOUSEMOVE or $GUI_EVENT_PRIMARYDOWN
       
      If I'm screwed I'm screwed... I'm just to tired to do this right, right now.  "Yeah, to hell with it TARS. Just give it to me straight" - Interstellar
      Also - If I offended anyone, please let me know and I'll edit my forum text. I'm just tired.
      While 1 If GuiCtrlRead($I_IPAddress01) <> "IP ADDRESS" and GuiCtrlRead($I_ComputerName01) <> "COMPUTER NAME" Then GUICtrlSetData($L_IP01, GuiCtrlRead($I_IPAddress01)) GUICtrlSetData($L_Hostname01, GuiCtrlRead($I_ComputerName01)) EndIf $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $B_Ping01 Ping01() Case $B_EXIT01 Exit Case $B_NBTSTAT01 NBTSTAT01() EndSwitch WEnd