[RESOLVED] Creating Control Arrays During Runtime
I am creating a program where there is not necessarily a specific number of items in the menu...I was wondering if there is a specific way of creating a control during runtime... I'll have a minimum of one label... but I just want to make copies of it... but still be able to access them individually...
I remember seeing something like that... but I couldn't find it in the search... or maybe I am just not typing the correct keyword
If anyone could help or give me a link to that thread... I'd really appreciate it...
Khanjan
Re: Creating Control Arrays During Runtime
Create the array in design time, and say the user calls something that needs a new label:
VB Code:
Load (lblMyLabel(UBound(lblMyLabel + 1)), Label)
Please note that has not been tested, but it should be close.
Re: Creating Control Arrays During Runtime
Put one on your form and set it's Index to 0. You can hide it if you want and make it visible if you need just one. After that you Load new ones, making sure you make them visible and moving them where you want them.
Re: Creating Control Arrays During Runtime
Well... timeshifter you are close enough... you gave me that hint of the keyword "Load"
However the prompt I get for the format is ....
Code:
Load(Object As Object)
I enter:
VB Code:
Private Sub Command1_Click()
Static intCount As Integer
intCount = intCount + 1
Load (Label1(intUCount) As Label)
End Sub
I get an error with "As"
The error is:
Code:
Expected: list seperator or )
I get an error with your code too... at "+"
For the "+" the error is:
Code:
Expected: List Seperator
Re: Creating Control Arrays During Runtime
Have fun making Opbects
VB Code:
'
' SESSI4ML 10/10/2006
' Create Objects...or, create new Objects as the user needs them
'
'Option Explicit
'
' VBforums.com ....
'
Private Sub Form_Load()
Command3.Caption = "Make Objects"
Command1.Caption = "Single Step"
Text1.Text = 10
End Sub
Private Sub Command3_Click()
For a = 1 To Val(Text1.Text)
Call Command1_Click
Next
End Sub
Private Sub Command1_Click()
' what is the object count
' text1= number of objects to create
'
intobj = Command2.Count ' Points to the next Object
Load Command2(intobj) ' command2 will always default to index 0 for the load
' ready to create new object
' Create new object
' Create a new Row
'
If intobj / 5 = Int(intobj / 5) Then
' Create a new Top for object
Command2(intobj).Top = Command2(intobj - 1).Top + Command2(intobj).Height + 10
Command2(intobj).Left = 120 ' Start on Left column
Command2(intobj).Visible = True
Command2(intobj).Caption = Command2(intobj).Index
Exit Sub
End If
'
Command2(intobj).Top = Command2(intobj - 1).Top
Command2(intobj).Left = Command2(intobj - 1).Left + Command2(intobj - 1).Width + 5
Command2(intobj).Caption = Command2(intobj).Index
Command2(intobj).Visible = True
End Sub
'
1 Attachment(s)
Re: Creating Control Arrays During Runtime
Complete Code. The same could be used for Text boxes, Labels, etc...
Re: Creating Control Arrays During Runtime
Sessi4ml
YOU ARE THE BEST!!! :D
:bigyello:
I FEEL LIKE JUMPING WITH JOY... THANX A LOT...
I SHALL RATE YOUR POST FOR SURE...