Jump to content
Sign in to follow this  

Click Button to send text string to Input field

Recommended Posts

Hello All,

I am new to Autoit and am attempting to translate an existing HTA using Koda. The GUI is basically a form containing 2 x columns. The first column contains buttons and the second column contains corresponding input fields. Each button is rigged up to perform a specific function (run a .bat file etc)

What I'm attempting to do is input a string of text into the adjacent input field to confirm that the button has been clicked, and therefore that the task is complete. This way the person using the form can keep track of the progress if they are interrupted.

In a .hta I would normally use <span> and then use innerhtml to update it when a button is clicked. Can anyone tell me if this is possible in an Autoit GUI or if there is a better way of performing this task. (Maybe input fields are the wrong approach?/) I have done the Google searching to no avail and trying to avoid re-inventing the proverbial wheel. Appreciate it if someone could point me in the write direction.


Share this post

Link to post
Share on other sites

No matter what type of control it is, you can always go back and update it:

#include <GuiConstantsEx.au3>

Opt("GUIOnEventMode", 1)

Global $Form1, $idButton, $aSteps, $f_Run = False

$Form1 = GUICreate("TheForm", 300, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")

$idButton = GUICtrlCreateButton("START", 100, 250, 100, 30)
GUICtrlSetOnEvent(-1, "_ButtonHit")

$aSteps = StringSplit("Step 1,New Step 2,My Step 3,Yet Another Step 4,Your Step 5,His Step 6,Her Step 7", ",")
For $n = 1 To $aSteps[0]
    $aSteps[$n] = GUICtrlCreateLabel($aSteps[$n], 20, ($n * 30) - 20, 260, 20)


; Gui Loop
While 1
    If $f_Run Then
        ; Run the steps
        For $n = 1 To $aSteps[0]
            GUICtrlSetData($aSteps[$n], GUICtrlRead($aSteps[$n]) & "... In Progress")
            GUICtrlSetColor($aSteps[$n], 0x0000FF) ; Blue
            If Random(0, 1, 1) Then
                GUICtrlSetColor($aSteps[$n], 0x00FF00) ; Green
                GUICtrlSetData($aSteps[$n], StringReplace(GUICtrlRead($aSteps[$n]), "... In Progress", "... PASSED."))
                GUICtrlSetColor($aSteps[$n], 0xFF0000) ; Red
                GUICtrlSetData($aSteps[$n], StringReplace(GUICtrlRead($aSteps[$n]), "... In Progress", "... FAILED!"))
        $f_Run = False

Func _ButtonHit()
    $f_Run = True
EndFunc   ;==>_ButtonHit

Func Form1Close()
EndFunc   ;==>Form1Close


Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post

Link to post
Share on other sites

Much appreciated PSaltyDS. Beautiful code and certainly pointed me in the right direction. "GUICtrlSetData" has worked a treat for what I was trying to achieve.

Thanks again

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...