Daka

reading value gives me 68 and after 0 in GUICtrlCreateInput

4 posts in this topic

#1 ·  Posted

Global $l = GUICtrlCreateInput("3", 16, 48, 25, 22, $ES_NUMBER)
Global $p = GUICtrlCreateInput("3", 56, 48, 25, 22, $ES_NUMBER)
$go = GUICtrlCreateButton("Start", 136, 48, 83, 25)
Global $m = GUICtrlCreateInput("1", 96, 48, 25, 22, $ES_NUMBER)

Case $go
         $l = Number(GUICtrlRead($l))
         $p = Number(GUICtrlRead($p))
         $m = Number(GUICtrlRead($m))

Then I say consolewrite:

ConsoleWrite(" l: " & $l & " p: " & $p & " m: " & $m & @LF);

And first time when I hit Start ($go) button it gives me default numbers and works fine

l: 3 p: 3 m: 1

But then I hit Start again and no need to change the numbers in input it gives me:

l: 68 p: 68 m: 0

Then I hit again Start and this is result:

l: 0 p: 0 m: 0

from this moment it is all the time 0 (zero) so what could be this?

Share this post


Link to post
Share on other sites



#2 ·  Posted

You are mixing two things: The ID of a control returned by GUICtrlCreate* function and the value entered by the users as returned by GUICtrlRead.
Use separate variables for the ID and the value.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

24 minutes ago, water said:

...Use separate variables for the ID and the value.

For example

;https://www.autoitscript.com/wiki/Best_coding_practices#Names_of_Variables
Global $idL = GUICtrlCreateInput("3", 16, 48, 25, 22, $ES_NUMBER)
Global $idP = GUICtrlCreateInput("3", 56, 48, 25, 22, $ES_NUMBER)
$idGo = GUICtrlCreateButton("Start", 136, 48, 83, 25)
Global $idM = GUICtrlCreateInput("1", 96, 48, 25, 22, $ES_NUMBER)

Case $idGo
         $iL = Number(GUICtrlRead($idL))
         $iP = Number(GUICtrlRead($idP))
         $iM = Number(GUICtrlRead($idM))
         
         ConsoleWrite(" l: " & $iL & " p: " & $iP & " m: " & $iM & @LF);

 

Edited by spudw2k
1 person likes this

Share this post


Link to post
Share on other sites

#4 ·  Posted

@spudw2k Thank you that was the solution :)

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

    • Jibberish
      By Jibberish
      I am having difficulties getting updated results from GUICtrlCreateInput. I wrote a small script to demonstrate what I am trying to do.
      This script reads a text file into an array and displays the Name and Number from the text file.
      The user can check a name and change the number, and the results are displayed in _ArrayDisplay.
      Only the Checked names are displayed in their original position. This is necessary for future
      plumbing.
      The problem with this script is the original number is returned, not the changed number. I cannot
      figure out how to get the updated number to be displayed.
      ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; This script reads a text file into an array and displays the Name and Number from the text file. ; The user can check a name and change the number, and the results are displayed in _ArrayDisplay. ; Only the Checked names are displayed in their original position. This is necessary for future ; plumbing. ; ; The problem with this script is the original number is returned, not the changed number. I cannot ; figure out how to get the updated number to be displayed. ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include-once #include <MsgBoxConstants.au3> #include <array.au3> #include <Date.au3> #include <WinAPIFiles.au3> #include <AutoItConstants.au3> #include <Misc.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> Local $iMax = 6 ;Default number of Videos - 1 for the array counter Dim $aTextFile[$iMax][2] ; [start with 5 entries][Name, Number] Don't get confused! [Row][Column] Local $i = 0 Local $iLeft = 30 Local $iTop = 30 Local $sName Local $sNumber Local $aArray Local $iMaxCol = 5 Local $iRow = 0 Local $iCol = 0 Local $aNumberCount[$iMaxCol][2] $aArray1 = ReadFile() $aNamesNumbers = DisplayNames($aArray1) _ArrayDisplay($aNamesNumbers) ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; ReadFile() places the contents of the NameNumber.txt file in an array ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func ReadFile() Local $sFileData = @ScriptDir & "\NameNumber.txt" Local $iStrReturn = 0 Local $aArrayFile Local $aTextFile[$iMaxCol][2] Local $aName Local $sCheckBox1 Const $iL = 10 ; Count from Left for GUI so all buttons line up Local $sFill Local $iA = 0, $iN = 0 ; Put the Names into an Array _FileReadToArray($sFileData, $aArrayFile) For $iA = 0 To $aArrayFile[0] ; Step through the array looking for Names If StringInStr($aArrayFile[$iA], "Name:") Then $aName = StringSplit($aArrayFile[$iA],":") $sFill = $aName[2] If UBound($aTextFile) <= $iRow Then ; Resize the array when $iRow is equal to the element count in the array to prevent subscript error ReDim $aTextFile[UBound($aTextFile) + 1][$iMaxCol] EndIf $aTextFile[$iRow][$iCol] = $sFill $iRow += 1 EndIf Next $iCol = 1 $iRow = 0 $sFill = "" For $iA = 1 To $aArrayFile[0] ; Step through the array looking for Numbers If StringInStr($aArrayFile[$iA], "Number:") Then $aName = StringSplit($aArrayFile[$iA],":") $sFill = $aName[2] If UBound($aTextFile) <= $iRow Then ; Resize the array when $iRow is equal to the element count in the array to prevent subscript error ReDim $aTextFile[UBound($aTextFile) + 1][$iMaxCol] EndIf $aTextFile[$iRow][$iCol] = $sFill $iRow += 1 EndIf Next Return $aTextFile EndFunc ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Display the Name and Number ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func DisplayNames($aArray1) Local $aName[$iMax] Local $aNumbers[$iMax] $iMMCount = UBound($aArray1) $iMMCount -=1 Local $iWidth = 300 Local $iLength = 300;$iMMCount * 30 GUISetFont(12) $hGUI = GUICreate("Edit / Update Number Test", $iWidth, $iLength, -1, -1) GUICtrlCreateLabel(" Name Number",1,5) ;$iTop += 30 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Display Name with a Checkbox. Only Checked Names should be saved. ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For $i = 0 to $iMMCount Step 1 $sNameText = $aArray1[$i][0] $iNameLength = StringLen($sNameText) $aName[$i] = GUICtrlCreateCheckbox($sNameText,$iLeft, $iTop) $iTop += 30 Next ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Display the number from the text file below each name. Allow the user to change the number and display the ; new number. ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $iLeft = 60 GUIStartGroup() $iTop = 28 For $i = 0 to $iMMCount Step 1 $sNumberText = $aArray1[$i][1] $aNumberCount[$i][1] = $sNumberText $aNumberCount[$i][0] = GUICtrlCreateInput($sNumberText,$iLeft, $iTop, 50,18, $GUI_DOCKAUTO) GUICtrlSetPos($aNumberCount[$i][0],200) $iTop += 30 Next ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Read the checked names and (possibly updated) number ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $iMMCount = UBound($aNumberCount) $iMMNewCount = $iMMCount - 1 Local $aGUICheckbox[$iMMCount] Local $aCheckedNameNumber[$iMMCount][2] $iLeft = 30 Local $idCloseGUI = GUICtrlCreateButton("Close",$iLeft, $iTop) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idCloseGUI For $i = 0 To $iMMNewCount Step 1 Switch GUICtrlRead($aName[$i]) Case $GUI_CHECKED $aCheckedNameNumber[$i][0] = $aArray1[$i][0] Case $GUI_UNCHECKED EndSwitch Switch GUICtrlRead($aNumberCount[$i][0]) Case $aCheckedNameNumber[$i][1] = GUICtrlRead($aNumberCount[$i][1]) EndSwitch Next ExitLoop EndSwitch WEnd For $i = 0 to $iMMNewCount step 1 GUICtrlRead($aNumberCount[$i][0]) If $aCheckedNameNumber[$i][0] <> "" Then $aCheckedNameNumber[$i][1] = $aNumberCount[$i][1] EndIf Next GUIDelete($hGUI) Return $aCheckedNameNumber EndFunc This is the text file I am reading. If you want to try this out put the NameNumber.txt file in your script directory. It's attached to the post.
      * This is a dummy file with a Name and Number * The only purpose of this file is to read the updated Number. Name:Taggart Number:916 Name:Mongo Number:90 Name:Hedley Lamarr Number:22 Name:Bart Number:9999 Name:The Waco Kid Number:2244 If I change the number, the original number is displayed at the end, not the updated/modified number. I need the modified number to be displayed.
      Thanks in advance for any assistance!
      Jibberish
      NameNumber.txt
    • crazyjts
      By crazyjts
      Hi all,
      I have the following snippet of code that sort of works but isn’t doing exactly what I want.
      expand popup #include <GuiConstants.au3> Global $gGUIWidth = 250 Global $gGUIHeight = 150 Initial() Func Initial()    ; Create the initial GUI    $BaseGUI = GUICreate("", $gGUIWidth, $gGUIHeight, -1, -1, -1, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW)    GUISetState(@SW_SHOW, $BaseGUI)    ; Create a field for entering the current value    GUICtrlCreateLabel("Current Value:",  10, 10)    $CurrentValueFld = GUICtrlCreateInput("", 10, 40, 215, 20, $ES_NUMBER)    GUICtrlSetState($CurrentValueFld, $GUI_FOCUS)    ; Create Calculate button    Local $CalculateButton = GUICtrlCreateButton("Calculate", 10, 70, 75, 25)    GUICtrlSetState($CalculateButton, $GUI_DISABLE)    ; Watch the value field and determine if the value is greater than 0 and if so, enable Calculate button    $i = 0    Do       $CurrentValue = GUICtrlRead($CurrentValueFld)       If $CurrentValue > 0 Then          GUICtrlSetState($CalculateButton, $GUI_ENABLE + $GUI_FOCUS)          $i = 1       EndIf    until $i = 1    ;Loop until the user exits and check for ESC, "X", or Begin button    While 1       $InitialGUIMsg = GUIGetMsg()       If $InitialGUIMsg = $GUI_EVENT_CLOSE Then          Exit       EndIf    WEnd EndFunc  
      I want to be able to:
        Start with focus in the value field (it is doing this now)  Allow for more than one digit to be entered into the field (it is sort of doing this now but I have to bring focus back to the field) Enable the Calculate button and give focus to it once a value is entered into the value field (it is doing this now) but keep the cursor in the value field so the more digits can be entered (it is not doing this now) Be able to hit ESC or “X” to close the dialog at any time (this only works after I enter a digit in the value field Basically, I want to be able to allow the user to enter one or more digits and hit ENTER or SPACE (while the cursor is still in the value field) to push the Calculate button.  I assume I need to bring focus to the button but maybe I don't and can get away with assigning hotkeys for ENTER and SPACE to push the Calculate button while keeping focus in the value field.
      If you could, please add comments in your code as to what the changes are doing if they aren't obvious to a noobish programmer.  
      Thanks for any help you can offer on this.
    • tarretarretarre
      By tarretarretarre
      As the title states, is there a way to detect which inputbox is "selected"
      like: 
      if IsSelectedForWritingEtc($MyInputBox) then xxxx
      i was searching some without success, all my results were like how to read or and write to a inputbox. 
       
       
      /T
    • GreenCan
      By GreenCan
      NEW VERSION: 17 Jun 2013
      Ever wondered how to avoid input being so painful?
      You can type a lot of errors in a GUICtrlCreateInput, for example alphanumeric where you want only numbers and decimals, typing 10 characters where you only want 9, etc.
      Input masks can make your life easier and Validation can be as simple as this:
      GuiCtrlCreateLabel("Input Decimal(8,2)", 10, 110, 200, 15) $MyInput = GUICtrlCreateInput("",210,110,110,20) _Inputmask_add($MyInput, $iIM_INTEGER, 0, "", 8, 2) It requires only one additional line per input
      The UDFexample script demonstrates 13 dynamic input validations.  A lot more validations can be made. Up to you to be inventive.
      _inputmask 1.0.0.5.zip
      Enhanced:
      Better input control
      - The previous versions worked well with blank fields but editing non-blank inputs was really a pain.
      Now the cursor remains where the edit is occurring.  Once the max width is reached, no additional characters can be added.
      - Added beep on invalid entry.  In fact I use soundplay instead of beep because beep gives a cracking sound result on my laptop.  You can set beep off (put Global $bBeep = False anywhere in your script)
      If you prefer a true beep, you can beep it on in line 150.
      Minor issue:
      - decimal Numbers after the '.' scroll away when inserting until it bumps to the max allowed decimals. I didn't fix that yet, I don't know how to solve this ...



      Examples:
      Example 1 _inputmask - example.au3 (see zip file)
      Example 2: _Inputmask combining two WM_COMMAND handlers (see zip file)
      Thanks to Melba23 for his explanation how to combine GUIRegisterMsg WM_COMMAND handlers)
      If you create your own input mask that could be useful for the AutoIt community, please let me know, I will be glad to add it to the above example.
      GreenCan
    • lavascript
      By lavascript
      I'm creating a small MsgBox-style GUI window for a login, and I'm giving my $Username input box the default text "DOMAIN\Username". When I run it, the default text is highlighted as expected, but it'd be nicer if I could highlight only the username portion. I realize I could use multiple input fields, but I'd rather not.

      I'm currently accomplishing this by:

      GUISetState(@SW_SHOW) Send("{END}+{LEFT 8}") and that technically works, but I was wondering if there was a "right" way to do this.