Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Auto increment variable name


  • Please log in to reply
10 replies to this topic

#1 flxfxp

flxfxp

    Wayfarer

  • Active Members
  • Pip
  • 87 posts

Posted 19 December 2008 - 02:25 PM

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?







#2 torels

torels

    I Hacked 127.0.0.1! :D

  • Active Members
  • PipPipPipPipPipPip
  • 676 posts

Posted 19 December 2008 - 02:27 PM

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, 19 December 2008 - 02:29 PM.

Some Projects:indifference will ruin the world, but in the end... WHO CARES :P---------------http://torels.altervista.org

#3 flxfxp

flxfxp

    Wayfarer

  • Active Members
  • Pip
  • 87 posts

Posted 19 December 2008 - 02:33 PM

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

#4 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,400 posts

Posted 19 December 2008 - 02:35 PM

AutoIt         
#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()


#5 flxfxp

flxfxp

    Wayfarer

  • Active Members
  • Pip
  • 87 posts

Posted 19 December 2008 - 02:45 PM

I created:

AutoIt         
#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?

#6 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,251 posts

Posted 19 December 2008 - 02:51 PM

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().

AutoIt         
#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

Posted Image AutoIt Russian CommunityPosted Image Projects: 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 ProgramPosted Image UDFs: 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 UDFPosted Image Examples: 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 DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#7 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,400 posts

Posted 19 December 2008 - 02:52 PM

AutoIt         
#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()


#8 PsaltyDS

PsaltyDS

    Most Venerable Penguin

  • MVPs
  • 13,279 posts

Posted 19 December 2008 - 02:59 PM

Yet another demo, where the array of input control IDs is used to do something functional (modified from KaFu's example):
Plain Text         
#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

#9 flxfxp

flxfxp

    Wayfarer

  • Active Members
  • Pip
  • 87 posts

Posted 19 December 2008 - 03:01 PM

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

#10 Zinthose

Zinthose

    Adventurer

  • Active Members
  • PipPip
  • 132 posts

Posted 19 December 2008 - 03:13 PM

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


#11 PsaltyDS

PsaltyDS

    Most Venerable Penguin

  • MVPs
  • 13,279 posts

Posted 19 December 2008 - 03:28 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users