Jump to content

Not able to retrieve value from GuiCtrlcreateinput()


Recommended Posts

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

Link to comment
Share on other sites

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

 

Saludos

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 1 month later...

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

 

Link to comment
Share on other sites

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!

Link to comment
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
 Share

×
×
  • Create New...