Sign in to follow this  
Followers 0
flxfxp

Auto increment variable name

11 posts in this topic

Hello,

I'm using a button which creates a new input box. However, I want that input box to have a unique name. How can I make it add a number behind the variable so it will name them uniquely?

So it will create with each press of a button:

$CaseNum1 = GUICtrlCreateInput("blah", 32, 40, 121, 21)

$CaseNum2 = GUICtrlCreateInput("blah", 32, 40, 121, 21)

$CaseNum3 = GUICtrlCreateInput("blah", 32, 40, 121, 21)

$CaseNum4 = GUICtrlCreateInput("blah", 32, 40, 121, 21)

$CaseNum5 = GUICtrlCreateInput("blah", 32, 40, 121, 21)

$CaseNum6 = GUICtrlCreateInput("blah", 32, 40, 121, 21)

Thanks!

Dennis

p.s: bonus question: how do i read all these values based on a array?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Use Arrays!

bonus answer:

dim $array[20]
;somethinghere to fill the array
For $i=0 to ubound($array)-1 ;for loop for each array element
msgbox(0,"",$array[$i])
next

cheers

Edited by torels

Some Projects:[list][*]ZIP UDF using no external files[*]iPod Music Transfer [*]iTunes UDF - fully integrate iTunes with au3[*]iTunes info (taskbar player hover)[*]Instant Run - run scripts without saving them before :)[*]Get Tube - YouTube Downloader[*]Lyric Finder 2 - Find Lyrics to any of your song[*]DeskBox - A Desktop Extension Tool[/list]indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

Share this post


Link to post
Share on other sites

hi torels, thank you for your swift answer.

I'm kind of new with Autoit, so could you please provide me a concrete example how to implement this?

Many thanks,

Dennis

Share this post


Link to post
Share on other sites

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

Dim $array[10]
;somethinghere to fill the array

Local $msg

GUICreate("My GUI") ; will create a dialog box that when displayed is centered

For $i = 0 To UBound($array) - 1 ;for loop for each array element
    GUICtrlCreateLabel($i,10,13 + $i*20)
    $array[$i] = GUICtrlCreateInput("", 30, 10 + $i*20, 121, 20)
Next

GUISetState(@SW_SHOW) ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()

Share this post


Link to post
Share on other sites

I created:

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

Dim $array[10]
;somethinghere to fill the array

Local $msg

GUICreate("My GUI") ; will create a dialog box that when displayed is centered

For $i = 0 To UBound($array) - 1 ;for loop for each array element
    GUICtrlCreateLabel($i,10,13 + $i*20)
    $array[$i] = GUICtrlCreateInput("", 30, 10 + $i*20, 121, 20)
Next
$SendButton = GUICtrlCreateButton("SND", 325, 10, 50, 20)

GUISetState(@SW_SHOW) ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Switch $msg 
        Case $SendButton
        dim $array[10]
        ;somethinghere to fill the array
        For $i=0 to ubound($array)-1 ;for loop for each array element
        msgbox(0,"",$array[$i])
        next
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
GUIDelete()

However, its not returning the inputbox value in the msgbox. What is wrong?

Share this post


Link to post
Share on other sites

its not returning the inputbox value in the msgbox. What is wrong?

1) You not should to Dim it again.

2) You need to read the value using GuiCtrlRead().

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

Dim $array[10]
;somethinghere to fill the array

GUICreate("My GUI") ; will create a dialog box that when displayed is centered

For $i = 0 To UBound($array) - 1 ;for loop for each array element
    GUICtrlCreateLabel($i,10,13 + $i*20)
    $array[$i] = GUICtrlCreateInput("", 30, 10 + $i*20, 121, 20)
Next

$SendButton = GUICtrlCreateButton("SND", 325, 10, 50, 20)

GUISetState(@SW_SHOW) ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    Switch $msg 
        Case $SendButton
            ;dim $array[10]
            
            ;somethinghere to fill the array
            For $i = 0 To UBound($array)-1 ;for loop for each array element
                MsgBox(0, "", GUICtrlRead($array[$i]))
            next
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

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

Dim $array[10]
;somethinghere to fill the array

Local $msg

GUICreate("My GUI") ; will create a dialog box that when displayed is centered

For $i = 0 To UBound($array) - 1 ;for loop for each array element
    GUICtrlCreateLabel($i, 10, 13 + $i * 20)
    $array[$i] = GUICtrlCreateInput("", 30, 10 + $i * 20, 121, 20)
Next
$SendButton = GUICtrlCreateButton("SND", 325, 10, 50, 20)

GUISetState(@SW_SHOW) ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $SendButton
            ;somethinghere to fill the array
            For $i = 0 To UBound($array) - 1 ;for loop for each array element
                MsgBox(0, "", GUICtrlRead($array[$i]))
            Next
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
GUIDelete()

Share this post


Link to post
Share on other sites

Yet another demo, where the array of input control IDs is used to do something functional (modified from KaFu's example):

#include <GUIConstantsEx.au3>

Global $avInputs[10], $iValNew, $iValOld = 0

GUICreate("My GUI"); will create a dialog box that when displayed is centered
For $i = 0 To UBound($avInputs) - 1;for loop for each array element
    GUICtrlCreateLabel($i, 10, 13 + ($i * 20))
    $avInputs[$i] = GUICtrlCreateInput("0", 30, 10 + ($i * 20), 121, 20)
Next
$Label_Total = GUICtrlCreateLabel("Total = " & $iValOld, 10, 20 * (UBound($avInputs) + 1), 121, 20)
GUISetState(@SW_SHOW); will display an empty dialog box

; Run the GUI until the dialog is closed
Do
    $iValNew = 0
    For $n = 0 To UBound($avInputs) - 1
        $iValNew += Number(GUICtrlRead($avInputs[$n]))
    Next
    
    If $iValNew <> $iValOld Then
        $iValOld = $iValNew
        GUICtrlSetData($Label_Total, "Total = " & $iValOld)
    EndIf
Until GUIGetMsg() = $GUI_EVENT_CLOSE

:)


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

ok, last question: As I mentioned before I use a button to create a new inputbox. This was simplified for you to understand. To get some background on what i would like to do, please look here.

Basically i'm slowly building a array, based on if there are cases or not. When i want a extra case, i click the button for it and i want it to:

create a tab [got this working]

create a inputbox with a unique id

create a combobox with a unique id

create a edit box with a unique id

In the end i would like to grab all the filled in inputboxes, comboboxes and editboxes from every tab so i can do stuff with it (in this case, putting it in a email and send it away).

How can I fill the array slowly so it won't create 10 inputboxes at once, but one everytime i press a button?

Thanks you very much for your support,

Dennis

Share this post


Link to post
Share on other sites

If you insist on creating dynamic variables you can use Assign() although Arrays are a better fit for controls.

Dim $TempID

For $i = 1 To 6
    $TempID = GUICtrlCreateInput("blah", 32, 40, 121, 21)
    Assign("CaseNum", $TempID, 2)
Next

--- TTFN

Share this post


Link to post
Share on other sites

ok, last question: As I mentioned before I use a button to create a new inputbox. This was simplified for you to understand. To get some background on what i would like to do, please look here.

Basically i'm slowly building a array, based on if there are cases or not. When i want a extra case, i click the button for it and i want it to:

create a tab [got this working]

create a inputbox with a unique id

create a combobox with a unique id

create a edit box with a unique id

In the end i would like to grab all the filled in inputboxes, comboboxes and editboxes from every tab so i can do stuff with it (in this case, putting it in a email and send it away).

How can I fill the array slowly so it won't create 10 inputboxes at once, but one everytime i press a button?

Thanks you very much for your support,

Dennis

So you have the IDs of tab, input, combo, and edit. That's four elements for each tab. You can keep that in a 1D array by some basic math:
Global $iTab = 0; Tab instance 0 is the first tab
Global $avTabControls[$iTab * 4]
$avTabControls[($iTab * 4)] = GUICtrlCreateTabItem(...); Tab control ID
$avTabControls[($iTab * 4) + 1] = GUICtrlCreateInput(...); Input control ID
$avTabControls[($iTab * 4) + 2] = GUICtrlCreateCombo(...); Combo control ID
$avTabControls[($iTab * 4) + 3] = GUICtrlCreateEdit(...); Edit control ID

The first tab instance is 0, so the controls IDs are at [0] thru [3], the second tab instance is 1, so the IDs are at [4] thru [7], etc.

If you are already comfortable with 2D arrays, my preference is to track them that way:

Global $avTabControls[3][4]

$avTabControls[0][0] = GUICtrlCreateTabItem(...); Tab control ID
$avTabControls[0][1] = GUICtrlCreateInput(...); Input control ID
$avTabControls[0][2] = GUICtrlCreateCombo(...); Combo control ID
$avTabControls[0][3] = GUICtrlCreateEdit(...); Edit control ID

The first tab's controls are at [0][0] thru [0][3], then second tab's ID are at [1][0] thru [1][3], etc.

:)


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

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  
Followers 0