I am trying to make a control array in visual basic 2008 (express edition), can anyone help me?

The code i was trying to edit worked in visual basic 6 but i was unable to get it to work, i need to make a control array for 80 textboxes and be able to loop through them. this is the code for the function i am trying to get to work.

Dim strlines() As String
Dim strElements() As String
Dim textboxIndex As Integer
textboxIndex = 0

strlines = Split(data, Chr(10))

If InStr(strlines(0), "Page not found") Then
MsgBox("User Not Found!") ‘Edit this line if you want to change the error user not found message
GoTo TheEnd
End If

For i = 0 To UBound(strlines)
strElements = Split(strlines(i), ",")
For x = 0 To UBound(strElements)
If (strElements(x)) = "-1" Then strElements(x) = "NA" ‘Edit this line if you want to change the error not in highscores message

instance(textboxIndex).Text = strElements(x)
textboxIndex = textboxIndex + 1
Next x

Next i

TheEnd:
End Sub

Control arrays work differently in .NET then they did in VB6. Here is a sample piece of code that will create 10 text boxes on a form.

Dim boxes(10) As TextBox

For i As Integer = 0 To 9

‘Create new textbox
boxes(i) = New TextBox()

‘Set it’s properties
boxes(i).Width = 200
boxes(i).Height = 25
boxes(i).Left = 10
boxes(i).Top = i * 30

‘Add control to current form
Me.Controls.Add(boxes(i))
Next

Related posts:

  1. Visual Basic Array Sorting?
  2. How can I get Visual Basic to open an excel doc in a textbox?
  3. Visual basic code question?
  4. What is the difference between Microsoft Visual Basic 2008 & Microsoft Visual Basic for Excel?
  5. In visual basic I have many problems?
This entry was posted in Learn Excel Macros. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>