?
Solved

Initialize Control Array with Loop

Posted on 2000-03-07
8
Medium Priority
?
191 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 12

Accepted Solution

by:
roverm earned 160 total points
ID: 2591454
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
ID: 2591475
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
ID: 2591479
Thank you....can this loop be used to evaluate all controls on the form>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 18

Expert Comment

by:deighton
ID: 2591487
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
 
LVL 1

Expert Comment

by:North
ID: 2591495
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
ID: 2591518
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
ID: 2591524
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
ID: 2591526
North: no problem ;-)) ! RoverM
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month9 days, 10 hours left to enroll

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