Jump to content

Click Button to send text string to Input field


 Share

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.

Thanks

Link to comment
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)
Next

GUISetState()

; Gui Loop
While 1
    Sleep(10)
    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
            Sleep(1000)
            If Random(0, 1, 1) Then
                GUICtrlSetColor($aSteps[$n], 0x00FF00) ; Green
                GUICtrlSetData($aSteps[$n], StringReplace(GUICtrlRead($aSteps[$n]), "... In Progress", "... PASSED."))
            Else
                GUICtrlSetColor($aSteps[$n], 0xFF0000) ; Red
                GUICtrlSetData($aSteps[$n], StringReplace(GUICtrlRead($aSteps[$n]), "... In Progress", "... FAILED!"))
            EndIf
            Sleep(1000)
        Next
        $f_Run = False
    EndIf
WEnd

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

Func Form1Close()
    Exit
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
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...