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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refer The Field name From Array Dim HNo(Array_Size) 1

Status
Not open for further replies.

Trob70

Programmer
Sep 25, 2012
89
AU

I am trying to use the following code as a subroutine

I have an array.....

say dim a(10) as string
a(0)="TT1" a(1)="hh" etc

and loop through the following routine 10 times ie a(0) a(1)---> a(10)

Instead on refering to the field name as HNo i want to refer to it as a(0) etc

ie. Dim a(0)(Array_Size) a(0)(i) = New TextBox

Appreciate any advice...

Regards Trob70

-------------------------------------------------------------

Dim Array_Size As Integer = 23
Dim HNo(Array_Size)


For i = 0 To Array_Size

HNo(i) = New TextBox
HNo(i).Text = i.ToString + 1
HNo(i).Top = 50 + 20 * i
HNo(i).width = 200
HNo(i).height = 50
HNo(i).left = 100

Me.Controls.Add(HNo(i))

Next i
 
I haven't got VS running, but at a quick glance -

This assumes that the array is an array of TextBox

Code:
For i = 0 To Array_Size
  Dim tb As New TextBox
  With tb
    .Text = (i + 1).ToString
    .Top = 50 + 20 * i
    .Width = 200
    .Height = 50
    .Left = 100
  End With
    Me.Controls.Add(tb)
    HNo(i) = tb
Next i
 
As an aside, if you want to give each TextBox a Name then inside the With block just add
Code:
.Name = "ArrayTextBox" & i.ToString
 
Thanks softhemc

Appreciate the help

Regards Trob70
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top