Jump to content
Shirdish_chakravarthi

Not able to retrieve value from GuiCtrlcreateinput()

Recommended Posts

Shirdish_chakravarthi

Hello Guys this is my gui and i need the numeric value typed in the highlighted  inputbox. if this value is greater than 1 i need to perform some operations

\auto4.PNG

 

Here is the summary about that field which i got from wininfo tool

auto2.PNG

i tried writing the code as shown below.. but the msgbox is popping up empty value..when the same code is pasted under some button action i am able to access the value present in the field..but when placed alone as written in the attached script i am unable to fetch it... 

my_isssue.PNG

here i am using the valu present in the field

code_2.PNG

can you guys tell me what's wrong??? or how can i get that value?

 

My_GUI.au3

auto4.PNG

Share this post


Link to post
Share on other sites
Danyfirex

It you're the owener of the GUI you just need to use. GUICtrlRead($YourControl)

 

Saludos

Share this post


Link to post
Share on other sites
Shirdish_chakravarthi

@Danyfirex yes i am owner of the gui..,.. i tried this but i am unable to retireve using this...

Share this post


Link to post
Share on other sites
Danyfirex

Your control id is $hello. Try to use meanfull names for your variables.

here is your script fixed. Check line 84.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#Region
$Form1 = GUICreate("Automatic Programming Tool", 696, 336, 192, 124, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_TABSTOP))

$Input1 = GUICtrlCreateInput("", 56, 76, 498, 21)
GUICtrlSetLimit(-1, 100)
GUICtrlSetColor(-1, 0x000000)
GUICtrlSetBkColor(-1, 0xFFFFFF)

$Input2 = GUICtrlCreateInput("", 56, 156, 490, 21)
GUICtrlSetLimit(-1, 100)
GUICtrlSetColor(-1, 0x000000)
GUICtrlSetBkColor(-1, 0xFFFFFF)

$cancel = GUICtrlCreateButton("Cancel", 584, 296, 75, 25)
GUICtrlSetColor(-1, 0x000000)

$Ok = GUICtrlCreateButton("OK", 488, 296, 75, 25)
GUICtrlSetColor(-1, 0x000000)

$Label1 = GUICtrlCreateLabel("Location of Flashing files", 64, 48, 175, 22)
GUICtrlSetFont(-1, 10, 800, 0, "@Arial Unicode MS")
GUICtrlSetColor(-1, 0xFF0000)

$Label2 = GUICtrlCreateLabel("Location  of CANoe Configuration", 64, 128, 229, 22)
GUICtrlSetFont(-1, 10, 800, 0, "@Arial Unicode MS")
GUICtrlSetColor(-1, 0xFF0000)

$hello = GUICtrlCreateInput("", 64, 232, 73, 21, $ES_NUMBER)
GUICtrlSetColor(-1, 0x001234)


$Label3 = GUICtrlCreateLabel("No. of times to be flashed", 56, 200, 180, 22)
GUICtrlSetFont(-1, 10, 800, 0, "@Arial Unicode MS")
GUICtrlSetColor(-1, 0xFF0000)

$Browse_1 = GUICtrlCreateButton("Browse...", 568, 72, 75, 25)
GUICtrlSetColor(-1, 0x000000)

$Button4 = GUICtrlCreateButton("Browse...", 568, 152, 75, 25)
GUICtrlSetColor(-1, 0x000000)
GUISetState(@SW_SHOW)
#EndRegion

;Assignments
Global $auto_1 = ControlGetText("Automatic Programming Tool", "", 9)
;Sleep(5000)
;MsgBox(0,"",$auto_1)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $cancel
            Exit
        Case $Browse_1
            Global $txt = FileOpenDialog("Open", "C:\", "Text files (*.Zip)")
            GUICtrlSetData($Input1, $txt)
            Global $data = ControlGetText("Automatic Programming Tool", "", $Input1)
        Case $Ok
            GUIDelete("Automatic Programming Tool")
            DPS()
    EndSwitch
WEnd


Func DPS()
    $open = Run("C:\DPS\dps.exe")

    If Not $open Then
        MsgBox($MB_ICONQUESTION, "Note", "DPS is not installed in the system")
    EndIf

    WinWaitActive("Development Programming System", "", "")
    Send("{ALT}" & "{ENTER 2}")
    WinWaitActive("Development Programming System - Programming1", "", "")
    Send("g")
    Sleep(500)
    $auto_1 = GUICtrlRead($hello)
    If $auto_1 > 1 Then
        Send("+{TAB}" & "{+}")
        WinWaitActive("Auto Repeat Mode", "", "")
        Send("{TAB}")
        Sleep(200)
        Send("{+}")
        Sleep(200)
        Send("{TAB}")
        Sleep(200)
        Send($auto_1)
        Sleep(200)
        Send("{ENTER}")
        Sleep(200)
        ;send("{UP 5}" & "{ENTER}")
        flash()
    EndIf
    Send("{TAB 6}" & "{ENTER}")
    flash()
EndFunc   ;==>DPS

Func flash()
    WinWaitActive("Open", "", "")
    Send($data & "{ENTER}")
    WinWaitClose("Open", "", "")
    Sleep(200)
    ;send("{DOWN}" & "{ENTER}")
    Sleep(3000)
    If WinActive("dps") Then ; Check if Notepad is currently active.
        MsgBox($MB_SYSTEMMODAL, "Error", "Error occured during Programming")
    EndIf
EndFunc   ;==>flash

Saludos

Share this post


Link to post
Share on other sites
Jibberish

Hi,

I am having the same problem as Shirdish. I checked Danyfirex's solution and I have that line (line 84 above is line 47 in my code). Still returns blank. It's late so I'm posting my code here in the hopes someone can figure out what I've done wrong, and I can fix it and move on sometime tomorrow!

This is the beginning of a search program. I have the search working in another function, I just wanted to add some features. When finished, it will look in the specific Log file for the search parameter. I've generalized the SelectSearchFile func to look in whatever directory this is run in, since that part really doesn't matter at this point.

Your help is truly appreciated!

 

#include-once
#include <WinAPIFiles.au3>
#include <AutoItConstants.au3>
#include <Misc.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <FontConstants.au3>
#include <MsgBoxConstants.au3>


Local $bButton
Local $sUserInput
Local $idInput

Local $sSelectedFile = SelectSearchFile()   ;Select a file to search

;Create the GUI with Search Text, checkbox for Whole Words Only & checkbox for Case Sensitive
GUICreate("Search Parameters",800,800)
GUISetFont(10,$FW_BOLD)
GUICtrlCreateLabel("Enter the parameters for the search in the selected Log File ",10,10)
GUISetFont(10,$FW_NORMAL)
GUICtrlCreateLabel($sSelectedFile,10,30)
GUISetFont(10,$FW_BOLD)
GUICtrlCreateLabel("Enter the search word or phrase.",10,60)
Local $idInput = GUICtrlCreateInput("",10,80)   ;Need a way to require input. No blanks allowed
GUICtrlSetState(-1,$GUI_SHOW)
Local $idBtn = GUICtrlCreateButton("Ok", 380, 750, 40, 20, $BS_DEFPUSHBUTTON)
;GUICtrlSetState(-1, $GUI_FOCUS) ; the focus is on this button

GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idBtn
                GUIDelete()
                ExitLoop
        EndSwitch
    WEnd

$sUserInput = GUICtrlRead($idInput)
;Don't allow a blank entry
MsgBox(0,"","User Entry is ",$sUserInput)


Func SelectSearchFile() ;Thank you AutoIt Examples!
    ; Create a constant variable in Local scope of the message to display in FileOpenDialog.
    Local Const $sMessage = "Select a single file of any type."

    ; Display an open dialog to select a file.
    Local $sFileOpenDialog = FileOpenDialog($sMessage, @WorkingDir & "\", "(*.*)", $FD_FILEMUSTEXIST)
    If @error Then
        ; Display the error message.
        MsgBox($MB_SYSTEMMODAL, "", "No file was selected.")

        ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
        FileChangeDir(@ScriptDir)
    Else
        ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
        FileChangeDir(@ScriptDir)

        ; Replace instances of "|" with @CRLF in the string returned by FileOpenDialog.
        $sFileOpenDialog = StringReplace($sFileOpenDialog, "|", @CRLF)

        ; Return the selected file.
        Return $sFileOpenDialog
    EndIf
EndFunc   ;==>Example

 

Share this post


Link to post
Share on other sites
aa2zz6

@Jibberish Your msgbox statement is incorrect in your code. See solution below.. :D

Incorrect

MsgBox(0,"","User Entry is ",$sUserInput)

Fixed

MsgBox(0, "", "User Entry is " & $sUserInput)

 

Share this post


Link to post
Share on other sites
Jibberish

Thanks @aa2zz6, I figured I was missing something  simple. I just couldn't see it!

I also had to move this line

    $sUserInput = GUICtrlRead($idInput)
to here:

   Case $idBtn
    $sUserInput = GUICtrlRead($idInput)
    GUIDelete()
    ExitLoop
 

Now it's working!

 Cheers!

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

    • nacerbaaziz
      By nacerbaaziz
      Hello my friends
      I have an inquiry and I hope to find the answer here
      I want to create a graphical user interface
      but I want to hide the system menu
      I mean the window menu
      Is this possible?
      If is possible please give me how to do that
      Thanks in advance
    • helmar
      By helmar
      I was playing around with simple GUI creation.  I tend to like parameter driven coding (in prior life (years ago) as Clipper/FoxPro/dBase coder).  Just wanted to see what I could do with a GUI.
      #Region options, includes Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) ; Change to OnEvent mode #include <GUIConstantsEx.au3> #EndRegion options, includes Global Const $nCols = 2, $nRows = 6, $nSpacer = 10, $nBtnWidth = 150, $nBtnHeight = 30 Global $xName = 0, $xID = 0 Global $nGUIWidth = ($nCols * $nBtnWidth) + (($nCols + 1) * $nSpacer) Global $nGUIHeight = ($nRows * $nBtnHeight) + (($nRows + 1) * $nSpacer) Global $hMainGUI = GUICreate("Calculated GUI", $nGUIWidth, $nGUIHeight, -1, -1) For $xRows = 1 to $nRows ;in this arrangement, tabbing is left to right, then next row For $xCols = 1 to $nCols ;reverse the order of this line with the prior line for top to bottom tabbing, then next col $xName += 1 $xID += 1 Global $Dummy = GUICtrlCreateButton("Button" & $xName, _ ($nBtnWidth * ($xCols - 1)) + (($xCols - 1) * $nSpacer) + $nSpacer, _ ($nBtnHeight* ($xRows - 1)) + (($xRows - 1) * $nSpacer) + $nSpacer, _ $nBtnWidth, _ $nBtnHeight) GUICtrlSetOnEvent($xID+2, "Handler") Next Next GUISetOnEvent($GUI_EVENT_CLOSE, "CloseApp") GUISetState(@SW_SHOW) While 1 Sleep(10) WEnd Func CloseApp() Exit EndFunc Func Handler() MsgBox(0,0,"Button " & @GUI_CtrlId - 2) EndFunc  
    • XinYoung
      By XinYoung
      For fun, I'm building an app that opens a webpage and refreshes it every 30 seconds.
      But once the script performs _IEAction($oIE, "refresh"), the GUI closes.
      Any help is appreciated.
       

      #include <ButtonConstants.au3>
      #include <EditConstants.au3>
      #include <GUIConstantsEx.au3>
      #include <StaticConstants.au3>
      #include <WindowsConstants.au3>
      #include <WinAPIFiles.au3>
      #include <Array.au3>
      #include <File.au3>
      #include <Excel.au3>
      #include <DateTimeConstants.au3>
      #include <MsgBoxConstants.au3>
      #include <WinAPIShellEx.au3>
      #include <MsgBoxConstants.au3>
      #include <Date.au3>
      #include <ComboConstants.au3>
      #include <guimenu.au3>
      #include <IE.au3>
      HotKeySet("{F4}", "_Exit")
      ;Open the file(s) in the selected folder
      $extension = ".txt"
      $app2openWith = @SystemDir & "\notepad.exe"
      Func Begin()
          Global $loopTrick = 0
          #Region ### START Koda GUI section ### Form=c:\users\mchu\downloads\autoit\my code\form1.kxf
          Global $UI = GUICreate("Hit Em Up!", 256, 113, -1, -1)
          GUISetBkColor(0x000000)
          $menu = _GUICtrlMenu_GetSystemMenu($UI)
          _GUICtrlMenu_EnableMenuItem($menu, $SC_CLOSE, 1, False)
          Global $url = GUICtrlCreateInput("https://www.youtube.com/watch?v=dQw4w9WgXcQ", 81, 8, 160, 21)
          $Label1 = GUICtrlCreateLabel("Target:", 16, 8, 55, 17)
          GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
          GUICtrlSetColor(-1, 0x00FF00)
          Global $StartBut = GUICtrlCreateButton("Start", 16, 40, 67, 25)
          GUICtrlSetFont(-1, 13, 800, 0, "MS Sans Serif")
          GUICtrlSetBkColor(-1, 0x008000)
          $Label2 = GUICtrlCreateLabel("(Press F4 to Exit)", 96, 40, 8000, 17)
          GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
          GUICtrlSetColor(-1, 0x00FF00)
          GUISetState(@SW_SHOW)
          #EndRegion ### END Koda GUI section ###
          While 1
              $UIfunc = GUIGetMsg()
              Select
                  Case $UIfunc = $GUI_EVENT_CLOSE
                      _Exit()
                  Case $UIfunc = $StartBut
                      If GUICtrlRead($url) = "" Then
                          MsgBox(48, "Um...", "Give me a target you idiot.")
                      Else
                          GUICtrlSetState($url, $GUI_DISABLE)
                          GUICtrlSetState($StartBut, $GUI_DISABLE)
                          Start()
                      EndIf
              EndSelect
          WEnd
      EndFunc   ;==>Begin
      Func Start()
          If $loopTrick = 0 Then
              Global $oIE = _IECreate(GUICtrlRead($url))
              _IELoadWait($oIE)
              Again()
          ElseIf $loopTrick = 1 Then
              Sleep(3000)
              _IEAction($oIE, "refresh")
              Sleep(3000)
              Start()
          EndIf
      EndFunc   ;==>Start
      Func Again()
          $loopTrick = 1
          Start()
      EndFunc   ;==>Again
      Func _Exit()
          Exit
      EndFunc   ;==>_Exit
    • vin1
      By vin1
      i need a script that can replace words in text with other words from a words list
      it has to have 2 edit boxes input/output and a button "run"
      from word_list.txt it choses which word to replace with. words are separated with commas for multiple choice
       

       
       

       
       
      ; AutoIt GUI Example ; Created: 17/01/2005 - CyberSlug ; Modifed: 05/12/2011 - guinness ; Modifed: 09/06/2014 - mLipok #Region INCLUDE #include <AVIConstants.au3> #include <GuiConstantsEx.au3> #include <TreeViewConstants.au3> #EndRegion INCLUDE #Region GUI GUICreate("Sample GUI", 400, 420) GUISetIcon(@SystemDir & "\mspaint.exe", 0) #EndRegion GUI #Region EDIT GUICtrlCreateEdit(@CRLF & " Sample Edit Control", 10, 10, 380, 175) GUICtrlSetTip(-1, '#Region EDIT') #EndRegion EDIT #Region EDIT2 GUICtrlCreateEdit(@CRLF & " Sample Edit Control", 10, 185, 380, 175) GUICtrlSetTip(-1, '#Region EDIT') #EndRegion EDIT2 #Region BUTTON GUICtrlCreateButton("Sample Button", 10, 360, 100, 30) GUICtrlSetTip(-1, '#Region BUTTON') #EndRegion BUTTON #Region GUI MESSAGE LOOP GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete() #EndRegion GUI MESSAGE LOOP  
    • kcvinu
      By kcvinu
      Hi all,
      I have a button created with _GUICtrlButton_Create function. I know that this function returns a handle of button instead of an ID. So i have obtain control ID by calling _WinAPI_GetDlgCtrlID function. After that i have tried the GUICtrlSetBkColor function. But it didnt worked. Any suggestions will be appreciated. Thanks in advance. 
      Note : - The window which carries this button is not created with native gui create function. Instead, it is created with CreateWindowEx api function.
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.