Jump to content

having trouble with array and gui


bobbintb
 Share

Recommended Posts

so im having a little programmers block and thought id ask for help. i have an updown button called $updown that ranges from 1 to 15 with 1 as the default. i want the code create a number of input boxes with browse buttons based on the number in the updown. so if 7 in the number in updown, there should be 7 inputs with 7 browse buttons. i also need it to correct itself. so for instance i go to 8 and then down one to 7, it needs to delete the last one. right now i just have the gui call this function when $updown is clicked. heres what i have so far:

Func browseforvidarray()
$i=1
Do
;~    MsgBox(0, "", $i)
$videoinput[$i-1] = GUICtrlCreateInput("", 16, 136+25*$i, 417, 21)
$videolook[$i-1] = GUICtrlCreateButton("Browse", 444, 132+25*$i, 65, 25)
   $i=$i+1
   redim $videoinput[$i+1]
   redim $videolook[$i+1]
  until $i>=GUICtrlRead($input)+1
EndFunc
Link to comment
Share on other sites

  • Moderators

bobbintb,

Perhaps something along these lines might do the trick: :D

#include <GUIConstantsEx.au3>
#include <UpdownConstants.au3>
#include <EditConstants.au3>

Global $aInputs[15]

$hGUI = GUICreate("Test", 500, 500)

$hInput = GUICtrlCreateInput(1, 10, 10, 40, 20, $ES_READONLY)
$hUpDown = GUICtrlCreateUpdown(-1, $UDS_WRAP)
GUICtrlSetLimit(-1, 15, 1)

For $i = 0 To 14
    $aInputs[$i] = GUICtrlCreateInput("", 10, 50 + ($i * 30), 200, 20)
    If $i Then
        GUICtrlSetState(-1, $GUI_HIDE)
    EndIf
Next

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hUpDown
            $iCount = GUICtrlRead($hInput)
            For $i = 0 To $iCount - 1
                GUICtrlSetState($aInputs[$i], $GUI_SHOW)
            Next
            For $i = $iCount To UBound($aInputs) - 1
                GUICtrlSetState($aInputs[$i], $GUI_HIDE)
            Next
    EndSwitch

WEnd

As you can see, all the controls are created initially and then shown/hidden as required. Sneaky but useful. :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

bobbintb,

Perhaps something along these lines might do the trick: :D

#include <GUIConstantsEx.au3>
#include <UpdownConstants.au3>
#include <EditConstants.au3>
 
Global $aInputs[15]
 
$hGUI = GUICreate("Test", 500, 500)
 
$hInput = GUICtrlCreateInput(1, 10, 10, 40, 20, $ES_READONLY)
$hUpDown = GUICtrlCreateUpdown(-1, $UDS_WRAP)
GUICtrlSetLimit(-1, 15, 1)
 
For $i = 0 To 14
    $aInputs[$i] = GUICtrlCreateInput("", 10, 50 + ($i * 30), 200, 20)
    If $i Then
        GUICtrlSetState(-1, $GUI_HIDE)
    EndIf
Next
 
GUISetState()
 
While 1
 
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hUpDown
            $iCount = GUICtrlRead($hInput)
            For $i = 0 To $iCount - 1
                GUICtrlSetState($aInputs[$i], $GUI_SHOW)
            Next
            For $i = $iCount To UBound($aInputs) - 1
                GUICtrlSetState($aInputs[$i], $GUI_HIDE)
            Next
    EndSwitch
 
WEnd

As you can see, all the controls are created initially and then shown/hidden as required. Sneaky but useful. :oops:

M23

ah! very sneaky. i like. hadnt even thought of that. thanks, i'll give it a shot.
Link to comment
Share on other sites

that worked great but now i have a problem. i added some lines to do the same thing but with a button as well. here is the code:

#include <GUIConstantsEx.au3>
#include <UpdownConstants.au3>
#include <EditConstants.au3>
Global $aInputs[15]
Global $bInputs[15]
$hGUI = GUICreate("Test", 500, 500)
$hInput = GUICtrlCreateInput(1, 10, 10, 40, 20, $ES_READONLY)
$hUpDown = GUICtrlCreateUpdown(-1, $UDS_WRAP)
$bInput = GUICtrlCreateButton("Browse", 230, 50, 65, 20)
GUICtrlSetLimit($hUpDown, 15, 1)
For $i = 0 To 14
$aInputs[$i] = GUICtrlCreateInput("", 10, 50 + ($i * 30), 200, 20)
$bInputs[$i] = GUICtrlCreateButton("Browse", 230, 50 + ($i * 30), 65, 20)
If $i Then
  GUICtrlSetState(-1, $GUI_HIDE)
EndIf
Next
GUISetState()
While 1
Switch GUIGetMsg()
  Case $GUI_EVENT_CLOSE
   Exit
  Case $hUpDown
   $iCount = GUICtrlRead($hInput)
   For $i = 0 To $iCount - 1
    GUICtrlSetState($aInputs[$i], $GUI_SHOW)
    GUICtrlSetState($bInputs[$i], $GUI_SHOW)
   Next
   For $i = $iCount To UBound($aInputs) - 1
    GUICtrlSetState($aInputs[$i], $GUI_HIDE)
   Next
   For $i = $iCount To UBound($bInputs) - 1
    GUICtrlSetState($bInputs[$i], $GUI_HIDE)
   Next
EndSwitch
WEnd

problem is when i run it i get the full 15 inputs at first unless i remark out the this line:

$bInputs[$i] = GUICtrlCreateButton("Browse", 230, 50 + ($i * 30), 65, 20)

i dont understand why adding it would affect the other.

Edited by bobbintb
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...