Solved

Initialize Control Array with Loop

Posted on 2000-03-07
8
183 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 40 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

729 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