Jump to content

Build GUI on the fly


Recommended Posts

I'm trying to build a GUI on the fly using a loop to generate the code needed. Array items are being read to get the values needed to build tabs,

For $r = 0 To UBound($genreArr, 1) - 1

        $tGenre = $genreArr[$r]
        
        $i = "$" & $tGenre & " = GUICtrlCreateTabItem(""" & $tGenre & """)"
        $j = "$" & $tGenre & "Edit = GUICtrlCreateEdit("""", 12, 33, 889, 484)"

        Eval($i) ; What goes here?
        Eval($j) ; What goes here?

    Next

I've checked using MsgBox, $i and $j contains the strings to make the Tab elements needed in the correct format.

I just used Eval in there as a placeholder but is there a function out there that can run the string like a line of code? I've tried searching for this as i'm sure it's been done loads of time but can't find the answer. Thanks.

Edited by Fly By Night
Link to comment
Share on other sites

To "execute" a function contained in a string like that you can use Execute(). But it will most likely end up very messy, so I recommend you find a way to use arrays instead.

Edited by AdmiralAlkex
Link to comment
Share on other sites

Cheers. I found what i was looking for after all. I did a search and came up with an "incremental variable names" post that provided a solution.

Global $numGenres = 15
Global $genreArr[$numGenres] = ["House", "Dance", "Electronic", "Trance", "Hardstyle", "Drum_&_Bass", "Commercial", "Jumpstyle", "Pop", "Rock", "Hip-Hop", "R_&_B", "Techno", "Other", "Psychedelic"]
Global $genreTabs[$numGenres], $genreEdit[$numGenres]

_ArraySort($genreArr)


$SBForm = GUICreate("TabsRUs", 914, 605, 193, 124)
$Tab = GUICtrlCreateTab(8, 8, 897, 513)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)


    For $r = 0 To UBound($genreTabs, 1) - 1

        $genreTabs[$r] = GUICtrlCreateTabItem($genreArr[$r])
        $genreEdit[$r] = GUICtrlCreateEdit("", 12, 33, 889, 484)

    Next



GUICtrlCreateTabItem("")


GUISetState(@SW_SHOW)
Edited by Fly By Night
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...