I really have a BIG problem in making control arrays.
The following is what i fed to the PC
sub form_load()
const n=15
dim Sam(n) as textbox
for n=1 to 15
next n
end sub
It won't work.

12 Years
Discussion Span
Last Post by SamY

hmm got it half-fixed:

sub form_load()
const n=15
dim Sam(n) as textbox
for a=1 to 15
next a
end sub

But now it's coming up with something being wrong with the 'sam(n).text="SamY" line.

The error is:

vb6 runtime error 91: Object Variable Not Set


That's exactly what i got.
I was trying to create something like a spread sheet.



Yuo can not create a control just like that. You have to set the control to something. That is the error that you are getting.

This will do the trick:

Dim sam(15) As TextBox
    For i = 1 To 15
        Set sam(i) = Controls.Add("vb.TextBox", "sam" & i)
        sam(i).Visible = True
        sam(i).Text = sam(i).Name
        sam(i).DragMode = 0
        If i <> 1 Then
            sam(i).Left = sam(i - 1).Left + sam(i - 1).Width
        End If
    Next i

the last part of the code is so they don't overlap and you can see them all next to each other.



You could also use load... which works just as well. Start a new project, and add a textbox... leave it's name alone (Text1). In The Properties Box, change index to 0. Now, in your form load (or in a button) add this:

For I = 0 To 9
    If I <> 0 Then
        Load Text1(I)
        Text1(I).Top = Text1(I - 1).Top + Text1(I - 1).Height
    End If
    Text1(I).Visible = True
Next I

Thanx again it worked. You guyz are really helpful!!!!!!!!!


ok the code for spread sheet is

sub main()
dim sam(10,12) as textbox
for i=1 to 10
for j=1 to 12
set sam(i,j)=controls.add("vb.textbox","sam" & i & j)
' the the code to prevent em' from overlaping
next j
next i
end sub

that code has an eeror when you reach 11 for i and 11 for j
but i want to try other new like after that you could
dim othe textboxes

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.