-
I jsut started using arrays, and have a question.
I am trying to manually add data to arrays, below is some basic code:
Code:
'When Control Button Clicked, Textboxes (Array) are reset
name(0) = ""
name(1) = ""
name(2) = ""
name(3) = ""
name(4) = ""
name(5) = ""
name(6) = ""
name(7) = ""
name(8) = ""
name(9) = ""
name(10) = ""
name(11) = ""
name(12) = ""
name(13) = ""
I continue to recieve "Wrong number of arguments or invalid property assignment" errors when using this code.
Does anyone know what the problem could be?
-
<?>
Code:
Dim myArr(4) As String
myArr(0) = "Hope"
myArr(1) = "This"
myArr(2) = "Works"
myArr(3) = "Now"
myArr(4) = "OK"
Dim i as integer
For i = lBound(myArr) to uBound(myArr)
msgbox myarr(i)
Next i
-
Maybe this?
dim c as integer
for ctxt = 1 to 13
name(ctxt)=""
next c
-
OOPS
-
Hmmm...problem though...
name(0)
name(1)
...etc
They are text boxes. When i enter what HeSaidJoe wrote, i get a syntax error.
Any suggestions?
-
<?>
if you are trying to call textboxes based on a name stored in a string, it won't work.
You would need a control array and reference the index
-
How would I go about doing that?
-
<?>
Code:
'perhaps this will let you get a grasp on it
'start a new project
'add 2 command buttons Command1 and Command2
'add a textbox Text1
'
'then right click and copy the textbox
'then right click and paste
'will ask you if you want a control array
'say yes
'then delete the one you just pasted on the form
run the job
Option Explicit
Public MaxId As Integer
Private Sub Command1_Click()
Dim i
For i = 0 To Text1.Count - 1
Text1(i) = "DirtBagDog"
Next i
End Sub
'unload the textboxes
Private Sub Command2_Click()
Dim i As Integer
For i = 1 To MaxId
If MaxId < 1 Then Exit Sub ' Keep first buttons.
Unload Text1(i) ' Delete last button.
MaxId = MaxId - 1 ' Decrement button count.
Text1(0).SetFocus ' Reset button selection.
Text1(0).Width = 4000
Text1(0).Height = 400
Next
End Sub
Private Sub Form_Load()
'load 4 more textboxes
MaxId = 4
Dim i
For i = 1 To MaxId
Load Text1(i) ' Create new button.
' Set new button under previous button.
Text1(i).Top = Text1(i - 1).Top + 500
Text1(i).Visible = True ' Display new
' button.
Text1(i).Width = 4000
Text1(i).Text = "Command" & i + 1
Next i
End Sub