New topic: 

VERY simple control array question

<http://forums.realsoftware.com/viewtopic.php?t=33789>

         Page 1 of 1
   [ 3 posts ]                 Previous topic | Next topic          Author  
Message        UniAce          Post subject: VERY simple control array 
questionPosted: Fri May 14, 2010 4:30 pm                         
Joined: Tue Nov 15, 2005 5:45 pm
Posts: 18
Location: UCLA                Argh!  I can't even figure out how to do this 
VERY simple thing: Add more StaticText controls at runtime.

I've made one window, and dragged a single StaticText control into it, and 
named that control "StaticText1" and given it index=0.  When the window opens, 
I want it to generate and display THREE static texts, based on a list that I 
define ("Label1" "Label2" "Label3").  Here is the code I've tried to use in the 
window's Open event handler:

Code:  dim LabelArray() as string
  dim i, NumLabels as integer
  
  LabelArray=split("Label1_Label2_Label3","_")
  NumLabels=ubound(LabelArray)
  
  redim StaticText1(NumLabels)
  for i = 0 to (NumLabels-1)
  dim temp as new StaticText
  StaticText1(i) = temp
  StaticText1(i).text=LabelArray(i)
  StaticText1(i).top=i*20
  StaticText1(i).visible=true
  next
The redim statement gives me an error: "This is not an array but you are using 
it as one."  I've tried other approaches, but just cannot get the three static 
texts to appear in the window.  PLEASE tell me what I'm doing wrong here, and 
how to get this very simple thing to happen!   
                             Top                timhare          Post subject: 
Re: VERY simple control array questionPosted: Fri May 14, 2010 4:47 pm          
               
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 7751
Location: Portland, OR  USA                First, a control array is not an 
actual array. It is an accessor method that takes an index, making it appear 
like an array, so things like Redim and Ubound do not apply.

Once you have the first StaticText1 control on the window, you create more with 
New StaticText1 (not StaticText - notice the '1' on the end, you're creating a 
clone of the control on the window, not a brand new control out of thin air).

Code:  dim LabelArray() as string
  dim i, NumLabels as integer
  dim temp as StaticText1

  LabelArray=split("Label1_Label2_Label3","_")
  NumLabels=ubound(LabelArray)
  
  for i = 0 to (NumLabels-1)
  temp = new StaticText1
  temp.text=LabelArray(i)
  temp.top=i*20
  temp.visible=true
  next
Note that at the end of this code you now have 4 StaticText1 controls - the 
original, with index 0 and the 3 you created with indices 1 - 3.  Therefore, 
StaticText1(1).Text is "Label1".   
                             Top                UniAce          Post subject: 
Re: VERY simple control array questionPosted: Fri May 14, 2010 7:16 pm          
               
Joined: Tue Nov 15, 2005 5:45 pm
Posts: 18
Location: UCLA                Holy crap, thank you! I would've been stuck on 
this forever.   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 3 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]

Reply via email to