Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Types and their elements

Status
Not open for further replies.

Phailak

Programmer
Apr 10, 2001
142
0
0
CA
Hail,

Let's say you have:

Public Type Test
Test1 as string
Test2 as string
Test3 as string
End Type

Is there a way to loop through the elements? For example, let's say I would want to assign three values (1, 2 and 3) to each of those, is there a way to loop them instead of doing

Dim TestType as Test

TestType.Test1 = 1
TestType.Test2 = 2
TestType.Test3 = 3

Could I do something like

For X =1 to 3
TestType.? = X
next
 
You can loop thru the controls collection, and check to see what type of control it is. If it matches, then you can do something. This loops thru all forms in the forms collection and sets the text property of all textboxes.

Code:
Option Explicit
'
'  ? TypeName(ctlall)
'  ? ctlall.name


Private Sub Form_Load()
  Dim frm As Form, x as Integer
  Dim ctlAll As Control
    For Each frm In Forms
      For Each ctlAll In frm
        If TypeOf ctlAll Is TextBox Then
         x=x+1 
         ctlAll.Text = x
        End If
      Next ctlAll
    Next frm
End Sub

-David
2006 Microsoft Valued Professional (MVP)
 
I used a multiarray which worked out great, thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top