Jump to content
Sign in to follow this  
nf67

Variable in Variable(name)?

Recommended Posts

nf67

Heya,

I'd like to clear a large set of Inputs which share a part of the name (Input), and have a number at the end of their name.

Is there any way to do this quickly?

Something like

For $Number = 1 to 10  ;for 10 inputs
GUICtrlSetData($Input$Number, "") ;reset data from $Input1 - $Input10 to nothing
Next
MsgBox(0, "MSG", "Your inputs have been cleared.")oÝ÷ Øí+"²g­b±¼§¢gÊh²È謶«y©ò¢Ø^¯²¶h¶¬ªè©ä±´¨÷ý¶®¶­sb6æ6ÇVFRfÇC´'WGFöä6öç7FçG2æS2fwC°¢6æ6ÇVFRfÇC´VFD6öç7FçG2æS2fwC°¢6æ6ÇVFRfÇC´uT6öç7FçG4WæS2fwC°¢6æ6ÇVFRfÇCµvæF÷w46öç7FçG2æS2fwC°¢4æ6ÇVFRfÇC´'&æS2fwC²²fÇC²ÒÒÐ  ¢b33c´uTÒuT7&VFRgV÷C´f÷&ÓgV÷C²Â#ÂÂ"Â#B¤FÒb33c¶çWE³UÒ²fÇC²ÒÒТb33c´çWE³ÒÒuT7G&Ä7&VFTçWBgV÷C´çWCgV÷C²ÂÂÂ#Â#²fÇC²ÒÒТb33c´çWE³%ÒÒuT7G&Ä7&VFTçWBgV÷C´çWC"gV÷C²ÂÂ#Â#Â#²fÇC²ÒÒТb33c´çWE³5ÒÒuT7G&Ä7&VFTçWBgV÷C´çWC2gV÷C²ÂÂC"Â#Â#²fÇC²ÒÒТb33c´çWE³EÒÒuT7G&Ä7&VFTçWBgV÷C´çWCBgV÷C²ÂÂc2Â#Â#²fÇC²ÒÒТb33cµ&W6WD'WGFöâÒuT7G&Ä7&VFT'WGFöâgV÷Cµ&W6WBÆÂgV÷C²ÂÂBÂ#Â#RÂb33cµu5ôu$õU¤uT6WE7FFR5uõ4õr  ¥vÆR¢b33c¶ä×6rÒuTvWD×6r¢7vF6b33c¶ä×6p¢66Rb33c´uTôUdTåEô4Äõ4P¢W@¢66Rb33cµ&W6WD'WGFöà¢&W6WDÆ¢VæE7vF6¥tVæ@ ¤gVæ2&W6WDÆ¢f÷"b33c´çVÖ&W"ÒFò@¢uT7G&Å6WDFFb33c´çWE²b33c´çVÖ&W%ÒÂgV÷C²gV÷C²²fÇC²ÒÒТæW@¢×6t&÷ÂgV÷C´Õ4rgV÷C²ÂgV÷Cµ÷W"çWG2fR&VVâ6ÆV&VBâgV÷C²¤VæDgVæ0
Edited by nf67

Share this post


Link to post
Share on other sites
PsaltyDS

Heya,

I'd like to clear a large set of Inputs which share a part of the name (Input), and have a number at the end of their name.

Is there any way to do this quickly?

Something like

For $Number = 1 to 10;for 10 inputs
GUICtrlSetData($Input$Number, "");reset data from $Input1 - $Input10 to nothing
Next
MsgBox(0, "MSG", "Your inputs have been cleared.")

?

If this is method is by no means possible, is there any other way to do this quickly?

Thanks :D

You could use Assign(), but it would be better to keep all your Control IDs in an array (i.e. $avInputs).

:D

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
nf67

Hi PsaltyDS (or anyone else :D ), could you please clarify a bit more? I barely have any experience with arrays (used it once or twice when returned by another command), reading the Assign() command didn't really help me either, do you have any example regarding this and my script's subject?

Thanks

Share this post


Link to post
Share on other sites
FreeFry

Dim $var1 = "var1"
Dim $var2 = "var2"
Dim $var3 = "var3"

For $i = 1 To 3
    MsgBox(0, "Var" & $i, Execute("$var" & $i))
Next

Should work I think. :D

Edit: or with an array:

Dim $varArray[3]
$varArray[0] = "var1"
$varArray[1] = "var2"
$varArray[2] = "var3"

For $i = 0 To UBound($varArray)-1
    MsgBox(0, "Var" & $i+1, $varArray[$i])
Next
Edited by FreeFry

Share this post


Link to post
Share on other sites
BlackPhoenix

Indeed you should use arrays:

Maybe this is what you are looking for

Guicreate('test',200,200)
Dim $input[4]
$Input[0]=GUICtrlCreateInput('Input1',20,30)
$Input[1]=GUICtrlCreateInput('Etc.',20,60)
$Input[2]=GUICtrlCreateInput('blabla',20,90)
$Input[3]=GUICtrlCreateInput('blabladd',20,120)
guisetstate()


Sleep(4000)

For $Number = 0 to ubound($Input)-1;for 10 inputs
GUICtrlSetData($Input[$Number], "");reset data from $Input1 - $Input10 to nothing
Next
MsgBox(0, "MSG", "Your inputs have been cleared.")

This i some quickmade code but I think you reach your goal with it.

Share this post


Link to post
Share on other sites
nf67

Thanks, I tried something like that but was missing the Dim

Share this post


Link to post
Share on other sites
ResNullius

@nf67,

Similar approach, but without the array.

Relies on all your Inputs being created consecutively:

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

$GUI = GUICreate("Form1", 201, 111, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 0, 0, 200, 21); <---
$Input2 = GUICtrlCreateInput("Input2", 0, 21, 200, 21); <---
$Input3 = GUICtrlCreateInput("Input3", 0, 42, 200, 21); <---
$Input4 = GUICtrlCreateInput("Input4", 0, 63, 200, 21); <---
$ResetButton = GUICtrlCreateButton("Reset All", 0, 84, 200, 25, $WS_GROUP)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $ResetButton
            ResetAll()
    EndSwitch
WEnd

Func ResetAll()
    For $i = $Input1 to $Input4
        GUICtrlSetData($i, ""); <---
    Next
    MsgBox(0, "MSG", "Your inputs have been cleared.")
EndFunc

Share this post


Link to post
Share on other sites
PsaltyDS

@nf67,

Similar approach, but without the array.

Relies on all your Inputs being created consecutively:

Also relies on knowing in advance exactly how many inputs there will be. Using an array makes dynamic controls easier. This demo adjusts the GUI to an unknown number of inputs, and reading/clearing the inputs is made easy by just looping through the array:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $iInputCnt, $hGUI, $ctrlRead, $ctrlReset
$iInputCnt = InputBox("Test", "How many inputs?")
Global $avInputs[$iInputCnt]

$hGUI = GUICreate("Test", 300, 50 + (30 * $iInputCnt))
For $n = 0 To UBound($avInputs) - 1
    $avInputs[$n] = GUICtrlCreateInput("Input " & $n, 10, 10 + ($n * 30), 280, 20)
Next
$ctrlRead = GUICtrlCreateButton("Read All", 25, 10 + (30 * $iInputCnt), 100, 30)
$ctrlReset = GUICtrlCreateButton("Reset All", 175, 10 + (30 * $iInputCnt), 100, 30)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $ctrlRead
            _ReadAll()
        Case $ctrlReset
            _ResetAll()
    EndSwitch
WEnd

Func _ReadAll()
    Local $sMsg = "Inputs:" & @CRLF
    For $n = 0 to UBound($avInputs) - 1
        $sMsg &= $n & ": " & GUICtrlRead($avInputs[$n]) & @CRLF
    Next
    MsgBox(64, "MSG", $sMsg)
EndFunc

Func _ResetAll()
    For $n = 0 to UBound($avInputs) - 1
        GUICtrlSetData($avInputs[$n], "")
    Next
    MsgBox(64, "MSG", "Your inputs have been cleared.")
EndFunc

:D


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
ResNullius

Also relies on knowing in advance exactly how many inputs there will be. Using an array makes dynamic controls easier.

Agreed, but to be fair the OP wasn't explicitly asking about dynamically creating controls:

I'd like to clear a large set of Inputs which share a part of the name (Input), and have a number at the end of their name.

Is there any way to do this quickly?

That presumes a foreknowledge of how many controls were created and need to be cleared. :D

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.