Jump to content

GUICreateInput save values


Recommended Posts

Hello,

I created a GUI with inputboxes, and I wrote a script with the vars of the inputboxes, but it's not saving the vars that I type in the inputs. What should I do?

That sort of question will usually result in an answer like "You need to delete line 3."

Without more information there is not much we can do to help. Preferably you need to provide a sample script, as small as possible, that demonstrates the problem.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Here is the script:

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1); Change to OnEvent mode

#Region ### START Koda GUI section ### Form=
$GUI = GUICreate("GUI", 681, 471, 187, 118)
$Input1 = GUICtrlCreateInput("", 16, 16, 150, 21)
$Input2 = GUICtrlCreateInput("", 16, 48, 150, 21)
$Input3 = GUICtrlCreateInput("", 16, 80, 150, 21)
$Input4 = GUICtrlCreateInput("", 16, 112, 150, 21)
$Input5 = GUICtrlCreateInput("", 16, 144, 150, 21)
$Input6 = GUICtrlCreateInput("", 16, 176, 150, 21)
$Input7 = GUICtrlCreateInput("", 16, 208, 150, 21)
$Input8 = GUICtrlCreateInput("", 16, 240, 150, 21)
$Input9 = GUICtrlCreateInput("", 16, 272, 150, 21)
$Input10 = GUICtrlCreateInput("", 16, 304, 150, 21)
$Input11 = GUICtrlCreateInput("", 182, 16, 150, 21)
$Input12 = GUICtrlCreateInput("", 182, 48, 150, 21)
$Input13 = GUICtrlCreateInput("", 182, 80, 150, 21)
$Input14 = GUICtrlCreateInput("", 182, 112, 150, 21)
$Input15 = GUICtrlCreateInput("", 182, 144, 150, 21)
$Input16 = GUICtrlCreateInput("", 182, 176, 150, 21)
$Input17 = GUICtrlCreateInput("", 182, 208, 150, 21)
$Input18 = GUICtrlCreateInput("", 182, 240, 150, 21)
$Input19 = GUICtrlCreateInput("", 182, 272, 150, 21)
$Input20 = GUICtrlCreateInput("", 182, 304, 150, 21)
$Input21 = GUICtrlCreateInput("", 348, 16, 150, 21)
$Input22 = GUICtrlCreateInput("", 348, 48, 150, 21)
$Input23 = GUICtrlCreateInput("", 348, 80, 150, 21)
$Input24 = GUICtrlCreateInput("", 348, 112, 150, 21)
$Input25 = GUICtrlCreateInput("", 348, 144, 150, 21)
$Input26 = GUICtrlCreateInput("", 348, 176, 150, 21)
$Input27 = GUICtrlCreateInput("", 348, 208, 150, 21)
$Input28 = GUICtrlCreateInput("", 348, 240, 150, 21)
$Input29 = GUICtrlCreateInput("", 348, 272, 150, 21)
$Input30 = GUICtrlCreateInput("", 348, 304, 150, 21)
$Input31 = GUICtrlCreateInput("", 514, 16, 150, 21)
$Input32 = GUICtrlCreateInput("", 514, 48, 150, 21)
$Input33 = GUICtrlCreateInput("", 514, 80, 150, 21)
$Input34 = GUICtrlCreateInput("", 514, 112, 150, 21)
$Input35 = GUICtrlCreateInput("", 514, 144, 150, 21)
$Input36 = GUICtrlCreateInput("", 514, 176, 150, 21)
$Input37 = GUICtrlCreateInput("", 514, 208, 150, 21)
$Input38 = GUICtrlCreateInput("", 514, 240, 150, 21)
$Input39 = GUICtrlCreateInput("", 514, 272, 150, 21)
$Input40 = GUICtrlCreateInput("", 514, 304, 150, 21)
$Input41 = GUICtrlCreateInput("", 16, 336, 150, 21)
$Input43 = GUICtrlCreateInput("", 182, 336, 150, 21)
$Input44 = GUICtrlCreateInput("", 348, 336, 150, 21)
$Input45 = GUICtrlCreateInput("", 514, 336, 150, 21)
$Input42 = GUICtrlCreateInput("", 16, 368, 150, 21)
$Input46 = GUICtrlCreateInput("", 182, 368, 150, 21)
$Input47 = GUICtrlCreateInput("", 348, 368, 150, 21)
$Input48 = GUICtrlCreateInput("", 514, 368, 150, 21)
$Button1 = GUICtrlCreateButton("Start", 290, 408, 100, 40, 0)
GUICtrlSetFont(-1, 16, 800, 0, "Arial")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;Events
GUICtrlSetOnEvent($Button1, "clicked")
GUISetOnEvent($GUI_EVENT_CLOSE, "close")
GUISetState()

Func close()
Exit
EndFunc

Func clicked()
GUIDelete()
$i=0
Do
If $i=1 Then Send ($Input1)
If $i=2 Then Send ($Input2)
If $i=3 Then Send ($Input3)
If $i=4 Then Send ($Input4)
If $i=5 Then Send ($Input5)
If $i=6 Then Send ($Input6)
If $i=7 Then Send ($Input7)
If $i=8 Then Send ($Input8)
If $i=9 Then Send ($Input9)
If $i=10 Then Send ($Input10)
If $i=11 Then Send ($Input11)
If $i=12 Then Send ($Input12)
If $i=13 Then Send ($Input13)
If $i=14 Then Send ($Input14)
If $i=15 Then Send ($Input15)
If $i=16 Then Send ($Input16)
If $i=17 Then Send ($Input17)
If $i=18 Then Send ($Input18)
If $i=19 Then Send ($Input19)
If $i=20 Then Send ($Input20)
If $i=21 Then Send ($Input21)
If $i=22 Then Send ($Input22)
If $i=23 Then Send ($Input23)
If $i=24 Then Send ($Input24)
If $i=25 Then Send ($Input25)
If $i=26 Then Send ($Input26)
If $i=27 Then Send ($Input27)
If $i=28 Then Send ($Input28)
If $i=29 Then Send ($Input29)
If $i=30 Then Send ($Input30)
If $i=31 Then Send ($Input31)
If $i=32 Then Send ($Input32)
If $i=33 Then Send ($Input33)
If $i=34 Then Send ($Input34)
If $i=35 Then Send ($Input35)
If $i=36 Then Send ($Input36)
If $i=37 Then Send ($Input37)
If $i=38 Then Send ($Input38)
If $i=39 Then Send ($Input39)
If $i=40 Then Send ($Input40)
If $i=41 Then Send ($Input41)
If $i=42 Then Send ($Input42)
If $i=43 Then Send ($Input43)
If $i=44 Then Send ($Input44)
If $i=45 Then Send ($Input45)
If $i=46 Then Send ($Input46)
If $i=47 Then Send ($Input47)
If $i=48 Then Send ($Input48)
Until $i=48
EndFunc

While 1
    Sleep (1000);Idle around
WEnd
Link to comment
Share on other sites

$Input1 is the reference number for the an input, or the ID. It is the varaiable which represent the control component. So when you want to do something with it you refer to it a s $Inout1. But reading the text which is written in the edit is different. In the same way that what is written in a newspaper is not the name of the newspaper. To read what is in the input you need to look up GuiCtrlRead.

Then I would do something to reduce all those lines.

Keeping with the way you have designed it using Koda you could write your function like this

Func clicked()
    GUIDelete()
    $i = 0
    Do
        Send(GUICtrlRead(Eval("Input" & $i)))
        $i += 1
    Until $i = 48
EndFunc;==>clicked

Which is a bit shorter.

It's not so straightforward to simplify the code for the creation of the controls when you do the design in Koda. Yoiu can use arrays to simplify the code, but then how do you use arrays in the Koda design?

My solution is to have a hybrid approach. Suppose as in your example we want to have columns of inputs. We need to use Koda to make sure they are in the right pace and so on.

So I use Koda to create only the ones at the tops of the columns.

Then in my code I use an array. Set the first element to be the variable name for the input at the top of a column, then create the ones below, but using the dimensions and position of the first one to guide me. It might not make much sense, but anyway here is what I would do. When you have a lot of controls this approach allows you to use Koda and also save a lot of code. Additioanlly it means you are dealing with arrays which is very much easier in the rest of the script.

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1); Change to OnEvent mode
;only make 4 inputs at the top to start with
#Region ### START Koda GUI section ### Form=
$GUI = GUICreate("GUI", 681, 471, 187, 118)
$Input1 = GUICtrlCreateInput("", 16, 16, 150, 21)
$Input2 = GUICtrlCreateInput("", 182, 16, 150, 21)
$Input3 = GUICtrlCreateInput("", 348, 16, 150, 21)
$Input4 = GUICtrlCreateInput("", 514, 16, 150, 21)

$Button1 = GUICtrlCreateButton("Start", 290, 408, 100, 40, 0)
GUICtrlSetFont(-1, 16, 800, 0, "Arial")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


Dim $ip[4][11]
For $n = 0 To 3
    $ip[$n][0] = Eval("input" & ($n + 1))
    $cp = ControlGetPos($GUI, "", $ip[$n][0])
    For $p = 1 To 10
        $ip[$n][$p] = GUICtrlCreateInput("", $cp[0], $cp[1] + 32 * $p, $cp[2], $cp[3])
    Next
Next

;Events
GUICtrlSetOnEvent($Button1, "clicked")
GUISetOnEvent($GUI_EVENT_CLOSE, "close")
GUISetState()

Func close()
    Exit
EndFunc;==>close

Func clicked()
    GUIDelete()
    For $i = 0 To 3
        For $j = 0 To 10
            Send(GUICtrlRead($ip[$i][$j]))
        Next
    Next
EndFunc;==>clicked

While 1
    Sleep(1000);Idle around
WEnd

EDIT:spelling. It always amazing me how pressing the button to submit a post can suddenly modify your script and put spelling mistakes and typos in which absolutely weren't there a second ago.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...