Jump to content

Recommended Posts

Posted

I'm trying to make a script that has two inputbox, and a button will add two more on each click.

My first problem is how to assign those controls to a value, when that value has to increment with each click of addrow?

; $TTL keeps track of how many times it was ran.
; the variable name should be "pkg_1" and the next run should be "pkg_2" and so on.
; I have tried with $pkg_ + $TTL, didnt work
; tried $pkg = "$pkg_" & $TTL, didnt work.
; out of ideas :(

$TTL = $TTL+1
$pkg_ + $TTL = GUICtrlCreateInput("", 5, $PosY+$PosInc, $SZ1)
$srv_ + $TTL = GUICtrlCreateInput("", 305, $PosY+$PosInc, $SZ2)

Later on, I have to read those dynamically created cointrols.

I use $TTL to know how many loops to run.

For $i = 0 to $TTL
    
    ; an attempt to read from dynamic control name.
    
    $pkg = $pkg_ + $i
    $srv = $srv_ + $i
    $val1 = GUICtrlRead($pkg, 1)
    $val2 = GUICtrlRead($srv, 1)
    
    ; trying to assign values to my array
    
    $list[$i][0] = $val1
    $list[$i][1] = $val2
    ReDim $list[$i+1][2]
Next

Also it seems that the last commands, to assign values to the array is failing.

And aditionally, I can't seem to be able to GUICtrlRead any of the inputs created by AddRow.....!

Please help me!

Full script:

#include <GUIConstantsEx.au3>
#include <array.au3>

Dim $List[1][2]

$PosY = "60"
$PosInc = "25"
$SZ1 = "300"
$SZ2 = "150"
$TTL = "0"

GUICreate("", 460, 600)
$add = GUICtrlCreateButton("Add row", 5, 5, 75)
$exec = GUICtrlCreateButton("Launch copy", 305, 5, 75)
GUICtrlCreateLabel("Packages to affect", 5, 40)
GUICtrlCreateLabel("On which server to copy", 5+300, 40)
$pkg_0 = GUICtrlCreateInput("", 5, $PosY, $SZ1)
$srv_0 = GUICtrlCreateInput("", 305, $PosY, $SZ2)

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    If $msg = $add then AddRow()
    If $msg = $exec then Go()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Func AddRow()

    ; an attempt to create "dynamic" control names.
    
    $TTL = $TTL+1
    $pkg_1 = GUICtrlCreateInput("", 5, $PosY+$PosInc, $SZ1)
    $srv_1 = GUICtrlCreateInput("", 305, $PosY+$PosInc, $SZ2)   
    $PosInc = $PosInc+25

EndFunc


Func Go()

For $i = 0 to $TTL
    
    ; an attempt to read from dynamic control name.
    
;~  $pkg = $pkg_ + $i
;~  $srv = $srv_ + $i
    $val1 = GUICtrlRead($pkg_0, 1)
    $val2 = GUICtrlRead($srv_0, 1)
    
    ; trying to assign values to my array
    
    $list[$i][0] = $val1
    $list[$i][1] = $val2
    ReDim $list[$i+1][2]
Next
    
_arraydisplay($list)
    
EndFunc

Thanks :)

Posted (edited)

$pkg_ + $TTL

That doesn't really make much sense. Plus sign is used to add things, see Operators in the helpfile.

If you really really want to make it like that use Assign()/Eval(), but you really should be using an array. See the Array tutorial in the wiki if you are unsure about anything.

Edited by AdmiralAlkex
Posted (edited)

Thanks Alekex.

I switched to Arrays for my controls, and I was able to get the last loop to work properly by changing my ReDim from $i+1 to $i+2

#include <GUIConstantsEx.au3>
#include <array.au3>

Dim $List[1][2]
Dim $PKG[1][2]

$PosY = "60"
$PosInc = "25"
$SZ1 = "300"
$SZ2 = "150"
$TTL = "0"

GUICreate("", 700, 600)
$add = GUICtrlCreateButton("Add row", 25, 5, 75)
$exec = GUICtrlCreateButton("Launch copy", 305, 5, 75)
GUICtrlCreateLabel("Packages to affect", 25, 40)
GUICtrlCreateLabel("On which server to copy", 350, 40)
GUICtrlCreateLabel($TTL, 5, $PosY)
$PKG[$TTL][0] = GUICtrlCreateInput("", 25, $PosY, $SZ1)
$PKG[$TTL][1] = GUICtrlCreateInput("", 330, $PosY, $SZ2)

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    If $msg = $add then AddRow()
    If $msg = $exec then Go()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Func AddRow()

    ; an attempt to create "dynamic" control names.
    if $TTL = 0 then ReDim $PKG[2][2]
    If $TTL = 0 then $TTL = 1
    ;msgbox(0,"","adding box at " & $TTL)
    GUICtrlCreateLabel($TTL, 5, $PosY+$PosInc)
    $PKG[$TTL][0] = GUICtrlCreateInput("", 25, $PosY+$PosInc, $SZ1)
    $PKG[$TTL][1] = GUICtrlCreateInput("", 330, $PosY+$PosInc, $SZ2)
    $PosInc = $PosInc+25
    $TTL = $TTL+1
    ReDim $PKG[$TTL+1][2]
EndFunc


Func Go()
    _ArrayDelete($pkg, UBound($PKG)-1)
For $i = 0 to ubound($pkg)-1
    $list[$i][0] = GUICtrlRead($PKG[$i][0], 1)
    $list[$i][1] = GUICtrlRead($PKG[$i][1], 1)
    ReDim $list[$i+2][2]
Next
_arraydisplay($list)
EndFunc
Edited by PowerCat

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...