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
Window2.PagePanel1.SelectedPanelIndex=0
elseif PopupMenu1.SelectedRowIndex=1 then
Window2.PagePanel1.SelectedPanelIndex=1
elseif PopupMenu1.SelectedRowIndex=2 then
Window2.PagePanel1.SelectedPanelIndex=2
elseif PopupMenu1.SelectedRowIndex=3 then
Window2.PagePanel1.SelectedPanelIndex=3
elseif PopupMenu1.SelectedRowIndex=4 then
Window2.PagePanel1.SelectedPanelIndex=4
end
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
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
n=PagePanel1.SelectedPanelIndex
If segmentIndex = 0 Then
TextArea(n).Visible=True
Canvas(n).Visible=False
// code for when segment 0 is selected
Else
TextArea(n).Visible=False
Canvas(n).Visible=True
// code for when segment 1 is selected
End If
[/code]
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?
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.
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:
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
TextArea5.Visible=True
Canvas5.Visible=False
// code for when segment 0 is selected
Else
TextArea5.Visible=False
Canvas5.Visible=True
// code for when segment 1 is selected
End If
TextArea5.Top=64
TextArea5.Left=20
TextArea5.Width=560
TextArea5.Height=392
Canvas5.Top=100
Canvas5.Left=20
Canvas5.Width=540
Canvas5.Height=297
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.