Making the code better looking

Hi, I have the code below that based on the selection of the PopupMenu changes pages in the PagePanel in the other window.

Is there a way to make it better looking? I am writing all the code explicitly. Is this the right way to do it?

if PopupMenu1.SelectedRowIndex=0 then
elseif PopupMenu1.SelectedRowIndex=1 then
elseif PopupMenu1.SelectedRowIndex=2 then
elseif PopupMenu1.SelectedRowIndex=3 then
elseif PopupMenu1.SelectedRowIndex=4 then

Thank you in advance.


Please review documentation about case statements.

Alternative may be to put the page panels in an array on window open, so you can refer to them by index later.

Hi, all,

I just have re-written the code above with the following one.

Var n As Integer

It works and looks much better with 60 PopupMenu indices. Just for general education, I need to play and find other way to do the same.

Have a nice day, all,


Select Case PopupMenu1.SelectedRowIndex Case 0 Window2.PagePanel1.SelectedPanelIndex=0 Case 1 Window2.PagePanel1.SelectedPanelIndex=1 Case 2 Window2.PagePanel1.SelectedPanelIndex=2 Case 3 Window2.PagePanel1.SelectedPanelIndex=3 Case 4 Window2.PagePanel1.SelectedPanelIndex=4 End Select

Hi, guys, again,

I have 59 PagePanels. On each panel I have a segmented button that switches between a text area and an image.

I am trying to read the page panel index and parse it into the button’s name.

For example, if the PagePanel1.SelectedPanelIndex=0, then it should send commands to the TextArea0 and Canvas0.

To achieve this, I’ve written the following code

[code]Var n As Integer

If segmentIndex = 0 Then
// code for when segment 0 is selected
// code for when segment 1 is selected
End If


Apparently, I am doing something essential wrong because all the code area is red from bugs.

Can someone point me what exactly I am doing wrong?

Thank you,


Use the name of the actual control set.

HI, Tim,

Thank you for the advice. This is actually what I am ended doing. With 59 panels going through actual names is a pain.

I was hoping to automate this process some way.

Again, I appreciate your feedback.


Did you make the controls into a contol set? That will allow you use an index instead of typing out the control names in a big select case statement.

Hi, Tim,

I have 59 page panels. Each page panel has a segment button with two segments (“text” and “image”), one text area and one canvas.

Since all these text areas and canvases are located in different page panels, I am not sure that I can set them as a control set.

Thank you again for your help.


Sure you can. This is a classic example of when to use a control set. Make the control index the same as the panel index they are on, so you can use the panel index directly to index the control.

Window2.PagePanel1.SelectedPanelIndex = PopupMenu1.SelectedRowIndex
  • Don’t use the awful var because I don’t like it.
  • Give your variables good names.
  • You don’t need the intermediate variable at all.

Hi, Tim,

Thank you give me an example how to do it? I’ve never done sets before.

Is there a YouTube tutorial for that? Or maybe a written tutorial?

Thank you,


Hi, Tim,

I have found this one in the documentation.

I will try to learn from it as much as I can.

Thank you again for suggesting this idea.


Have I missed something?
In the original post,
Window2.PagePanel1.SelectedPanelIndex is always being set to the same value as the PopupMenu1.SelectedRowIndex

If that is the case, the whole code becomes one line:


Doesnt solve the 59 images thing obviously: control set is the right answer for that.

Hi, Jeff,

The following code is not a problem


It reads the index of the selected menu in popupmenu1 on Window 1 and sets the PagePanel1 to the corresponding index.

I’ve got stuck how to pass that index to the segment button, text area and canvas.

I want by using the popupmenu to address the textfield and canvas.

Right now I have the following code in the segmented button

If segmentIndex = 0 Then
  // code for when segment 0 is selected
  // code for when segment 1 is selected
End If


With 59 indices in the popup menu and 59 page panels, I have 59 segmented buttons, 59 textareas, and 59 canvases.

Going manually through each segmented button “press” event and changing which texture and canvas it will talk to, is a pain.

I am hoping that using a control set approach would simplify this process.