Why doesn't this Code work?!

Objective: Have a popup menu with the a page listings available. The items from the previous “page” would vanish and the new ones would appear and become active.

Progress:

On Change

[code] If PageMenu.text = “1 - 12” Then

// make labels read row numbers 1-12
LabelOne.text = "1"
LabelTwo.text = "2"
LabelThree.text = "3"
LabelFour.text = "4"
LabelFive.Text = "5"
LabelSix.Text = "6"
LabelSeven.Text = "7"
LabelEight.Text = "8"
LabelNine.Text = "9"
LabelTen.Text = "10"
LabelEleven.Text = "11"
LabelTwelve.Text = "12"

// Group 1
TextField1.Visible = True
TextField2.Visible = True
TextField3.Visible = True
TextField4.Visible = True
TextField5.Visible = True
TextField6.Visible = True
TextField7.Visible = True
TextField8.Visible = True
TextField9.Visible = True
TextField10.Visible = True
TextField11.Visible = True
TextField12.Visible = True
TextField13.Visible = True
TextField14.Visible = True
TextField15.Visible = True
TextField16.Visible = True
TextField17.Visible = True
TextField18.Visible = True
TextField19.Visible = True
TextField20.Visible = True
TextField21.Visible = True
TextField22.Visible = True
TextField23.Visible = True
TextField24.Visible = True
TextField25.Visible = True
TextField26.Visible = True
TextField27.Visible = True
TextField28.Visible = True
TextField29.Visible = True
TextField30.Visible = True
TextField31.Visible = True
TextField32.Visible = True
TextField33.Visible = True
TextField34.Visible = True
TextField35.Visible = True
TextField36.Visible = True
TextField37.Visible = True
TextField38.Visible = True
TextField39.Visible = True
TextField40.Visible = True

TextField1.enabled = True
TextField2.enabled = True
TextField3.enabled = True
TextField4.enabled = True
TextField5.enabled = True
TextField6.enabled = True
TextField7.enabled = True
TextField8.enabled = True
TextField9.enabled = True
TextField10.enabled = True
TextField11.enabled = True
TextField12.enabled = True
TextField13.enabled = True
TextField14.enabled = True
TextField15.enabled = True
TextField16.enabled = True
TextField17.enabled = True
TextField18.enabled = True
TextField19.enabled = True
TextField20.enabled = True
TextField21.enabled = True
TextField22.enabled = True
TextField23.enabled = True
TextField24.enabled = True
TextField25.enabled = True
TextField26.enabled = True
TextField27.enabled = True
TextField28.enabled = True
TextField29.enabled = True
TextField30.enabled = True
TextField31.enabled = True
TextField32.enabled = True
TextField33.enabled = True
TextField34.enabled = True
TextField35.enabled = True
TextField36.enabled = True
TextField37.enabled = True
TextField38.enabled = True
TextField39.enabled = True
TextField40.enabled = True


// Group 2

TextField41.Visible = False
TextField74.Visible = False
TextField75.Visible = False
TextField76.Visible = False
TextField77.Visible = False
TextField78.Visible = False
TextField79.Visible = False
TextField80.Visible = False
TextField81.Visible = False
TextField82.Visible = False
TextField83.Visible = False
TextField84.Visible = False
TextField85.Visible = False
TextField86.Visible = False
TextField87.Visible = False
TextField88.Visible = False
TextField89.Visible = False
TextField90.Visible = False
TextField91.Visible = False
TextField92.Visible = False
TextField93.Visible = False
TextField94.Visible = False
TextField95.Visible = False
TextField96.Visible = False
TextField97.Visible = False
TextField98.Visible = False
TextField99.Visible = False
TextField100.Visible = False
TextField101.Visible = False
TextField102.Visible = False
TextField103.Visible = False
TextField104.Visible = False
TextField105.Visible = False
TextField106.Visible = False
TextField107.Visible = False
TextField108.Visible = False
TextField109.Visible = False
TextField110.Visible = False
TextField111.Visible = False
TextField112.Visible = False
TextField113.Visible = False
TextField114.Visible = False
TextField115.Visible = False
TextField116.Visible = False
TextField117.Visible = False
TextField118.Visible = False
TextField119.Visible = False
TextField120.Visible = False
TextField121.Visible = False
TextField122.Visible = False
TextField123.Visible = False
TextField124.Visible = False
TextField125.Visible = False
TextField126.Visible = False
TextField127.Visible = False

TextField41.Enabled = False
TextField74.enabled = False
TextField75.enabled = False
TextField76.enabled = False
TextField77.enabled = False
TextField78.enabled = False
TextField79.enabled = False
TextField80.enabled = False
TextField81.enabled = False
TextField82.enabled = False
TextField83.enabled = False
TextField84.enabled = False
TextField85.enabled = False
TextField86.enabled = False
TextField87.enabled = False
TextField88.enabled = False
TextField89.enabled = False
TextField90.enabled = False
TextField91.enabled = False
TextField92.enabled = False
TextField93.enabled = False
TextField94.enabled = False
TextField95.enabled = False
TextField96.enabled = False
TextField97.enabled = False
TextField98.enabled = False
TextField99.enabled = False
TextField100.enabled = False
TextField101.enabled = False
TextField102.enabled = False
TextField103.enabled = False
TextField104.enabled = False
TextField105.enabled = False
TextField106.enabled = False
TextField107.enabled = False
TextField108.enabled = False
TextField109.enabled = False
TextField110.enabled = False
TextField111.enabled = False
TextField112.enabled = False
TextField113.enabled = False
TextField114.enabled = False
TextField115.enabled = False
TextField116.enabled = False
TextField117.enabled = False
TextField118.enabled = False
TextField119.enabled = False
TextField120.enabled = False
TextField121.enabled = False
TextField122.enabled = False
TextField123.enabled = False
TextField124.enabled = False
TextField125.enabled = False
TextField126.enabled = False
TextField127.enabled = False

// Group 3

TextField145.Visible = False
TextField146.Visible = False
TextField147.Visible = False
TextField148.Visible = False
TextField149.Visible = False
TextField150.Visible = False
TextField151.Visible = False
TextField152.Visible = False
TextField153.Visible = False
TextField154.Visible = False
TextField155.Visible = False
TextField156.Visible = False
TextField157.Visible = False
TextField158.Visible = False
TextField159.Visible = False
TextField160.Visible = False
TextField161.Visible = False
TextField162.Visible = False
TextField163.Visible = False
TextField164.Visible = False
TextField165.Visible = False
TextField166.Visible = False
TextField167.Visible = False
TextField168.Visible = False
TextField169.Visible = False
TextField170.Visible = False
TextField171.Visible = False
TextField172.Visible = False
TextField173.Visible = False
TextField174.Visible = False
TextField175.Visible = False
TextField176.Visible = False
TextField177.Visible = False
TextField178.Visible = False
TextField179.Visible = False
TextField180.Visible = False
TextField181.Visible = False
TextField182.Visible = False
TextField183.Visible = False
TextField184.Visible = False
TextField185.Visible = False
TextField186.Visible = False

TextField145.Enabled = False
TextField146.enabled = False
TextField147.enabled = False
TextField148.enabled = False
TextField149.enabled = False
TextField150.enabled = False
TextField151.enabled = False
TextField152.enabled = False
TextField153.enabled = False
TextField154.enabled = False
TextField155.enabled = False
TextField156.enabled = False
TextField157.enabled = False
TextField158.enabled = False
TextField159.enabled = False
TextField160.enabled = False
TextField161.enabled = False
TextField162.enabled = False
TextField163.enabled = False
TextField164.enabled = False
TextField165.enabled = False
TextField166.enabled = False
TextField167.enabled = False
[/code]

ect…

Question: Why isn’t this working?

You may want to shorten this code, by using a while Wend loop for each group.

Example for group 1:

Dim i As Integer While i < 40 TextField(i).visible = True TextField(i).enabled = True Wend

Wow. What a nightmare to write and to maintain. This screams out for the use of control sets. Make your textFields a control set, then you can do…

for i As integer = 0 to kNumControls myTFControlSet(i).enabled = False myTFControlSet(i).visible = False Next

Yes, a bit of work now, but your future programmer self will thank you current self if you take the time to do so now.
You say “on change”. Which “change” event are you using? What wrong behavior are you seeing?

1st: Why you don’t use PagePanel?
2nd: The error must be somewhere in your if-clause, use your debugger to check string values in your pagemenu.text.
3rd: I am missing “end if”
4th use custom controls / control sets!!

[quote=174693:@Richard Summers]You may want to shorten this code, by using a while Wend loop for each group.

Example for group 1:

Dim i As Integer While i < 40 TextField(i).visible = True TextField(i).enabled = True Wend[/quote]

I was planning on shortening once I got it figured out. Right now, the items will not re-appear when a new “page” is called on even when they are being told to be visible.

[quote=174694:@Roger Clary]Wow. What a nightmare to write and to maintain. This screams out for the use of control sets. Make your textFields a control set, then you can do…

for i As integer = 0 to kNumControls myTFControlSet(i).enabled = False myTFControlSet(i).visible = False Next

Yes, a bit of work now, but your future programmer self will thank you current self if you take the time to do so now.
You say “on change”. Which “change” event are you using? What wrong behavior are you seeing?[/quote]

Might be something I do soon, but I this project needs to be done ASAP.

[quote=174695:@Tomas Jakobs]1st: Why you don’t use PagePanel?
2nd: The error must be somewhere in your if-clause, use your debugger to check string values in your pagemenu.text.
3rd: I am missing “end if”
4th use custom controls![/quote]

But it successfully changes my labels, but does not make my text boxes appear.

This is only one portion of the code… It is MUCH longer…

I’m assuming you’ve placed textfield41 on top of textfield1? In which case you need to look at textfield41’s parent which is probably textfield1. This would mean when textfield1 is not visible 41 can’t be visible either. When placing your control have a look at the item that is highlighted red.

all the more reason to INVEST some time to do it RIGHT, as opposed to WASTING time to figure why its wrong

You are right… I dislike your logic (sarcasm). I am being lazy and perhaps it is time I invest time into that…

This may be the answer!

I just tested it with

Open

Me.Parent = Nil

BINGO!

Thank you so much! I am going to call this the answer and also do as everyone else said and shorten the code.