Solved

Initialize Control Array with Loop

Posted on 2000-03-07
8
171 Views
Last Modified: 2010-05-02
Experts,

Is it possible to loop through control names, ie textboxes with number extensions using a for loop?

For i = 14 To 37
  RowID = "Txtbox" & cstr(i)
  frmMain.RowID.Text = cstr(StoArray(i))
Next i

I'm trying to initialize textboxes using the array and this is not working?

How is this done?  Thank you.
0
Comment
Question by:vbdvlper
8 Comments
 
LVL 12

Accepted Solution

by:
roverm earned 40 total points
Comment Utility
Yes:

For i = 14 To 37
  RowID = "Text" & CStr(i)
  frmMain.Controls(RowID).Text = "anynewvalue"
Next i

where all of your textboxes are numbered: Text14, Text15 and so on!

D'Mzzl!
RoverM
0
 
LVL 1

Expert Comment

by:North
Comment Utility
Try This,

Dim i As Integer

For i = 14 To 37 Step 1

   frmMain.TextBox(i).Text = cstr(StoArray(i))

Next i


Hope this helps, North
0
 

Author Comment

by:vbdvlper
Comment Utility
Thank you....can this loop be used to evaluate all controls on the form>
0
 
LVL 18

Expert Comment

by:deighton
Comment Utility
The thing to do is create a control array, copy and paste an existing text box to your form.  VB will ask you if you want to create a control array i.e text(1),text(2)...text(n)  then reference real easy.

For i = 14 To 37

                    RowID = Text (i)

Next i
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Expert Comment

by:North
Comment Utility
Sorry RoverM, yours appeared as I was submitting mine.

vbdvlper, the difference between my code and RoverM's is mine relies on the textboxes being in a control array (i.e. same name property, different Index property). RoverM's doesn't need a control array, choose whichever you prefer.

North.
0
 
LVL 12

Expert Comment

by:roverm
Comment Utility
Yes (again):

Dim ctl As Control

For Each ctl On frmMain
    If TypeOf ctl Is TextBox Then
      'do textbox stuff
    End If
Next ctl

D'Mzzl!
RoverM
0
 
LVL 12

Expert Comment

by:roverm
Comment Utility
by the way: ctl is the reference to the current selected TextBox, so all the properties are available:

ctl.Text = "anyvalue"
ctl.Font = "Arial"

And so on!
RoverM
0
 
LVL 12

Expert Comment

by:roverm
Comment Utility
North: no problem ;-)) ! RoverM
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now