New topic: Controls Question
<http://forums.realsoftware.com/viewtopic.php?t=45605> Page 1 of 1 [ 4 posts ] Previous topic | Next topic Author Message jerryab Post subject: Controls QuestionPosted: Sun Oct 14, 2012 5:20 pm Joined: Mon Dec 12, 2011 7:25 pm Posts: 98 Location: Grand Rapids MI Area I have 12 PopupMenu controls all with the same name with a different number after each name. puBusinessName1, puBusinessName2 etc.. I need to loop through and change the number of the control each time it loops. Can a control name be changed with a variable ? Example below: Dim i As Integer Dim puValue As String for i = 1 to 12 puValue = rs.Field("Thumbs" + Str(i)).StringValue Select Case puValue Case "A" puBusinessName(i).ListIndex = 0 //This does not work Case "B" puBusinessName + Str(i).ListIndex = 1 // This does not work Case "C" puBusinessName + Str(i).ListIndex = 2 Case "D" puBusinessName + Str(i).ListIndex = 3 Case "E" puBusinessName + Str(i).ListIndex = 4 Case "F" puBusinessName + Str(i).ListIndex = 5 Case "G" puBusinessName + Str(i).ListIndex = 6 Case "H" puBusinessName + Str(i).ListIndex = 7 Case "I" puBusinessName + Str(i).ListIndex = 8 Case "J" puBusinessName + Str(i).ListIndex = 9 Case "K" puBusinessName + Str(i).ListIndex = 10 Case "L" puBusinessName + Str(i).ListIndex = 11 Else puBusinessName + Str(i).ListIndex = 0 End Select next _________________ iMac 27" (2.8GHz Intel Core i5, 16GB RAM, 1TB Drive) OS X Lion 10.7.3 and Windows 7 Toshiba Laptop Running Windows 7 & WinXP SP3 REAL Studio Enterprise Edition 2012r1 http://www.theultimatecampgroundlog.com Being rewritten for the Mac Top timhare Post subject: Re: Controls QuestionPosted: Sun Oct 14, 2012 5:58 pm Joined: Fri Jan 06, 2006 3:21 pm Posts: 11729 Location: Portland, OR USA You should turn them into a control array. Give them all the same name and set the Index of each sequentially. Then you can address them by index. Top charonn0 Post subject: Re: Controls QuestionPosted: Sun Oct 14, 2012 6:26 pm Joined: Mon Apr 02, 2007 2:08 am Posts: 919 Location: San Francisco, CA, USA What you're looking for is a Control Array, and you had the right idea when you tried: Case "A" puBusinessName(i).ListIndex = 0 //This does not work It didn't work because you need a little bit of setup before you can treat a control like an array. Rename all the puBusinessName* instances to the same name, and then make sure each one has an appropriate index property: This will create a Control Array with that name. You can then access each PopupMenu by referencing the array with the index: Dim i As Integer Dim puValue As String for i = 1 to 12 puValue = rs.Field("Thumbs" + Str(i)).StringValue Select Case puValue Case "A" puBusinessName(i).ListIndex = 0 Case "B" puBusinessName(i).ListIndex = 1 Case "C" puBusinessName(i).ListIndex = 2 Case "D" puBusinessName(i).ListIndex = 3 Case "E" puBusinessName(i).ListIndex = 4 Case "F" puBusinessName(i).ListIndex = 5 Case "G" puBusinessName(i).ListIndex = 6 Case "H" puBusinessName(i).ListIndex = 7 Case "I" puBusinessName(i).ListIndex = 8 Case "J" puBusinessName(i).ListIndex = 9 Case "K" puBusinessName(i).ListIndex = 10 Case "L" puBusinessName(i).ListIndex = 11 Else puBusinessName(i).ListIndex = 0 End Select next _________________ Boredom Software Top jerryab Post subject: Re: Controls QuestionPosted: Sun Oct 14, 2012 9:08 pm Joined: Mon Dec 12, 2011 7:25 pm Posts: 98 Location: Grand Rapids MI Area Thanks for the help guys. I did not even think about using an array. I like the ease of using the array also. That worked as I wanted it to. Another lesson learned. _________________ iMac 27" (2.8GHz Intel Core i5, 16GB RAM, 1TB Drive) OS X Lion 10.7.3 and Windows 7 Toshiba Laptop Running Windows 7 & WinXP SP3 REAL Studio Enterprise Edition 2012r1 http://www.theultimatecampgroundlog.com Being rewritten for the Mac Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 4 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
