Jump to content

[SOLVED] Calling a script with an GUI input


Recommended Posts

Hello! First time post.

I'm using AutoIt pretty extensively to help automate a lot of electronic testing at my job. So far, a co-worker of mine has been able to help me when it came to problematic scripts; but now neither of us can figure this one out. I don't have any example code, because almost all of the code could be considered proprietary; so I'll just have to explain what I'm trying to accomplish.

I have a GUI with many inputs - text boxes, combo boxes, IP boxes, etc. I'm writing the GUI script in such a way that the "Begin Test" button won't activate until all inputs are correct - so that you can't accidentally leave out an important IP or something. (These tests are being designed to run by themselves and spit information out over a weekend or weeks at a time. So if anything is input incorrectly, it won't be noticed for a long time.)

So here's what I need. When I input text into the GUICtrlCreateInput, I need for it to call a function. (When I tab off or click away from the control) letting another set of variables know that information has been typed. That way, when all GUICtrlCreateInput boxes contain text, you can continue on in the process of the test.

Any ideas would be an incredible help! Thanks so much!

-Kris

Edited by fett8802
[sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub]
Link to comment
Share on other sites

  • Moderators

fett8802,

Welcome to the AutoIt forum. :blink:

One way to do what you want would be to store the ControlIDs of the inputs into an array and then loop through the array to make sure that the inputs held something. Take a look at this:

#include <GUIConstantsEx.au3>

Global $aInput_ID[3]

$hGUI = GUICreate("Test", 500, 500)

$aInput_ID[0] = GUICtrlCreateInput("", 10, 10, 480, 20)
$aInput_ID[1] = GUICtrlCreateInput("", 10, 50, 480, 20)
$aInput_ID[2] = GUICtrlCreateInput("", 10, 90, 480, 20)

$hButton = GUICtrlCreateButton("Test", 10, 150, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            $fError = False
            For $i = 0 To UBound($aInput_ID) - 1
                If GUICtrlRead($aInput_ID[$i]) = "" Then
                    MsgBox(0, "", "Please enter some text into Input " & $i)
                    $fError = True
                EndIf
            Next

            If Not $fError Then
                MsgBox(0, "", "Off and running!")
            EndIf

    EndSwitch

WEnd

If you wanted to get even fancier, you could check that what they held was reasonably valid, but that comes later. :P

Does that help? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

As far as making sure that the program will not continue without text input, yes. Thank you very much!

The reason I wanted it to check as you were going was that I've got a kind of progress bar that let's the user know how much more stuff needs entered before the program will allow you to continue. So, once the bar is full, you are good to go.

So, as I type into an input box and tab or click to another, the progress bar would update the appropriate amount.

Thanks so much for your help! I'm sorry I couldn't be any more clear.

-Kris

EDIT: I found this script elsewhere on the site and was attempting to adapt it to my needs. I was having a bad time of it.

#include<WindowsConstants.au3> ; For $WM_COMMAND
#include<WinApi.au3> ; For _WinApi_HiWord and LoWord
#include<EditConstants.au3> ; for $EN_KILLFOCUS

; The variables are needed in functions too...
Global $hEdit1, $hEdit2

GUICreate("This is a test", 400, 200)

$hEdit1 = GUICtrlCreateInput("", 2, 2, 396, 20)
$hEdit2 = GUICtrlCreateInput("", 2, 24, 396, 20)

GUISetState()
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ; Register the message

While GUIGetMsg() <> -3 ; Wait for close
    Sleep(10)
WEnd

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)

    If _WinAPI_HiWord($iwParam) = $EN_KILLFOCUS Then ; An edit ctrl has lost focus
        Switch _WinAPI_LoWord($iwParam)
            Case $hEdit1
                ConsoleWrite("Edit 1 has lost focus" & @CRLF)
            Case $hEdit2
                ConsoleWrite("Edit 2 has lost focus" & @CRLF)
        EndSwitch
    EndIf

EndFunc   ;==>WM_COMMAND
Edited by fett8802
[sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub]
Link to comment
Share on other sites

This is a bit slapped together hope it helps.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)

Global $hWndChanged

_GUI()

Func _GUI()
    #Region ### START Koda GUI section ### Form=
    Local $Form1 = GUICreate("Form1", 161, 139, -1, -1)
    Local $sInputs = GUICtrlCreateInput("", 8, 8, 121, 21)
    Local $sLabels = GUICtrlCreateLabel("r", 136, 8, 16, 21, $SS_CENTER)
    GUICtrlSetFont(-1, 12, 400, 0, "Webdings")
    $sInputs &= "|" & GUICtrlCreateInput("", 8, 40, 121, 21)
    $sLabels &= "|" & GUICtrlCreateLabel("r", 136, 40, 16, 21, $SS_CENTER)
    GUICtrlSetFont(-1, 12, 400, 0, "Webdings")
    $sInputs &= "|" & GUICtrlCreateInput("", 8, 72, 121, 21)
    $sLabels &= "|" & GUICtrlCreateLabel("r", 136, 72, 16, 21, $SS_CENTER)
    GUICtrlSetFont(-1, 12, 400, 0, "Webdings")
    Local $hButton1 = GUICtrlCreateButton("Button1", 40, 104, 75, 25)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    Local $aInputs = StringSplit($sInputs, "|")
    Local $aLabels = StringSplit($sLabels, "|")
    Local $sAllowedIn1 = "One|1"
    Local $sAllowedIn2 = "Two|2"
    Local $sAllowedIn3 = "Three|3"
    Local $aAllowed[4] = [0, $sAllowedIn1, $sAllowedIn2, $sAllowedIn3]

    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

    While 1
        Local $nMsg = GUIGetMsg()
        Select
            Case $nMsg = $GUI_EVENT_CLOSE
                Exit
            Case $hWndChanged
                For $i = 1 To $aInputs[0] Step 1
                    If GUICtrlGetHandle($aInputs[$i]) = $hWndChanged Then ExitLoop
                Next
                Local $sRead = GUICtrlRead($aInputs[$i])
                Local $aCheckfor = StringSplit($aAllowed[$i], "|")
                Local $fOk = False
                For $i2 = 1 To $aCheckfor[0] Step 1
                    If $sRead = $aCheckfor[$i2] Then $fOk = True
                Next
                If $fOk Then
                    GUICtrlSetData($aLabels[$i], "a")
                Else
                    GUICtrlSetData($aLabels[$i], "r")
                EndIf

                $hWndChanged = ""
            Case Else
                Local $fAllChecked = True
                For $i = 1 To $aLabels[0] Step 1
                    If GUICtrlRead($aLabels[$i]) = "r" Then $fAllChecked = False
                Next
                If $fAllChecked Then
                    If BitAND(GUICtrlGetState($hButton1), $GUI_DISABLE) Then GUICtrlSetState($hButton1, $GUI_ENABLE)
                Else
                    If BitAND(GUICtrlGetState($hButton1), $GUI_ENABLE) Then GUICtrlSetState($hButton1, $GUI_DISABLE)
                EndIf
        EndSelect
    WEnd
EndFunc   ;==>_GUI

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom = $ilParam
    Local $nNotifyCode = BitShift($iwParam, 16)
    Switch $nNotifyCode
        Case $EN_CHANGE
            $hWndChanged = $hWndFrom
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

edit : i should explain that ive made it tick input one if it contains "One" or "1" change $sAllowedIn1 to suit, each input has its own $sAllowedIn that is a string with a delimeter of "|" , only once all are ticked will the button be enabled.

Edited by Yoriz
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
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...