|
-
Nov 26th, 2000, 05:19 PM
#1
Thread Starter
Frenzied Member
Hi,
In vb if i do Controls.Add, that works fine except that if i want to make an array of controls then it doesnt work, how can i create an array like btnOk(1)
-
Nov 26th, 2000, 05:29 PM
#2
See if this works. (I can't test it because I don't have VB6)
Code:
Private Sub Command1_Click()
Controls.Add "VB.Label", "Label1"
Me!Label1.Move 0, 0
Me!Label1.Caption = "Label1"
Me!Label1.Visible = True
Me!Label1.Index = 0
'Now add more controls with the same name.
Controls.Add "VB.Label", "Label1"
Controls.Add "VB.Label", "Label1"
End Sub
-
Nov 26th, 2000, 07:36 PM
#3
transcendental analytic
In fact you can't create control arrays at runtime.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 26th, 2000, 10:55 PM
#4
Hyperactive Member
Try This
Use the load() statement to load a control in an array.
code:
Private Sub Command1_Click()
dim iLoop as Integer
Controls.Add "VBLabel", "Label1"
Label1.index = 0
'Creates an array of 20 controls.
for iLoop = 1 to 1
Load Label1(iLoop)
next iLoop
End sub
Visual Basic 6.0 Enterprise
Visual C++ 6.0 Professional
Wak 
-
Nov 27th, 2000, 03:22 AM
#5
Addicted Member
No can do
Wak, in your coding you have "Label1.index = 0". This will cause an error and your application will not compile, because there is no Label1 yet.
The only way you can do this is by adding one control during design time, then you can load as many as you want during runtime.
Add the control you need, set the index property to 0, thus making it an array, and then you can load instances as you need during runtime.
Code:
'create 2 more textboxes
Load txtTest(1)
Load txtTest(2)
'use the next index in line
Load lblPrompt(lblPrompt.UBound + 1)
Hope this helps.
Shrog
-
Nov 27th, 2000, 01:47 PM
#6
Thread Starter
Frenzied Member
Ok, i can add controls at design time, do u think that is the best way (using the load statement) ?
-
Nov 27th, 2000, 01:52 PM
#7
Addicted Member
I don't know if it's the best way, but it's the best way I know. I use this all the time, and we use it in the commercial software that my company produce.
Shrog
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|