home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.visual.basic      MS Visual Basic discussions, NOT dot-net      10,840 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 9,662 of 10,840   
   Rick Rothstein [MVP - Visual Basic] to All   
   Re: populate textboxes with a loop??   
   21 Aug 05 04:28:35   
   
   From: rickNOSPAMnews@NOSPAMcomcast.net   
      
   > Apologies in advance if this sounds slow-witted, but I didn't find it   
   here.   
   >   
   > Need to populate some textboxes on a form. While I could hard code it   
   (the   
   > number of options aren't that high), it would be more   
   compact/efficient to   
   > use a loop.   
   >   
   > However, I haven't found anything that describes how to reference the   
   > textboxes sequentially ... evaluating the hard part of the textbox   
   name,   
   > with the number of the loop iteration, to address the specific box.   
   >   
   > E.G. textboxes named textbox1, textbox2, textbox3   
   >   
   > For x = 1 to 3   
   > {textbox(x)} = x   
   > Next x   
   >   
   > What I need is how to call out the part of the line {in braces} so   
   that it   
   > executes dynamically. In the stupid example, t-box 1 would have 1,   
   t-box 2   
   > 2, t-box 3 3.   
   >   
   > I really don't want to get into arrays here, would be killing an ant   
   with a   
   > cannon, and more learning curve to overcome ... even though my example   
   looks   
   > like array notation   
      
   You have the wrong impression about arrays... they are extremely useful   
   devices. In the case of controls, VB provides a construct called control   
   arrays. They are quite easy to work with and will easily do what you   
   asked. The key to creating a control array is to give all of the member   
   controls (they must be of the same type) the same name. The first   
   duplicate you name will popup a dialog box asking if you want to create   
   a control array. Answer Yes to the question. Each member of the control   
   array will have its Index property assigned a value and they will all   
   share the same events. The event procedures will automatically be given   
   a parameter (between the parentheses) called, believe it or not, Index.   
   The beauty of this system is that VB will automatically assign the Index   
   property value to this Index parameter so that you will know which   
   control's event was activated. Anyway, for reference purposes, you can   
   address the members of the control array just like you would the members   
   of a normal array. For example, the question you asked would be coded   
   this way...   
      
   For X = 1 To 3   
     Text1(x).Text = CStr(X)   
   Next   
      
   Look up "control arrays" (without the quote marks) in VB's help files   
   for more information.   
      
   Rick   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca