Does anyone know if it is possible to create a certain number of shape objects whilst the program is running? What I want to do is create a certain number of rectangles depending on a variable in my program.
Printable View
Does anyone know if it is possible to create a certain number of shape objects whilst the program is running? What I want to do is create a certain number of rectangles depending on a variable in my program.
Make a CommandButton and put this code in it.
Code:Private Sub Command1_Click()
Controls.Add "VB.Shape", "Shape1"
Me!Shape1.Move 0, 0
Me!Shape1.Visible = True
End Sub
That didn't work, I get an error saying "Object doesn't support that property or method". Does that work for you cos I am using VB5 SP3 aswell?
Yeah, that's the big deal with vb6, i have vb5 and that doesn't work for me either. You must use a an array of objects and use Load object(index) to load a second item. There's a lot of threads on this topic, go search for "create runtime"
In VB6 I believe you would go about this using a control array. Try it in VB5 and see if this works.
Your form has a control Shape1. In the IDE, set it's Index property to 0. This tells VB it is the first member in a control array.
I hope this helps :) But as I said this something I've done in VB6, I don't recall if VB5 would do the same thing in the same fashion. Give it a shot.Code:Dim intNumber as Integer
'intNumber can be any integer value
intNumber = 6
'Enter your loop
For i = 1 To intNumber
'Load a new instance of Shape1 into the control array
Load Shape1(i)
'The default setting of each new controls Visible
'property is False. Change it or you won't see them
Shape1(i).Visible = True
'Remember not to overlap them unless you want to
'This spaces the controls out vertically with 20 twips or
'or pixels whatever between them. You can do the same
'vertically by using Top instead of Left
Shape1(i).Left = Shape1(i - 1).Left + Shape1(i).Width + 20
Next
Cheers very much for that, it does work in VB5.
This should work:
Done this is VBA for Office 97 which is somewhere between VB 4 and VB 5.Code:Dim Kontroll As Control
Dim ActiveForm As Object
Set ActiveForm = Form1
Set Kontroll = ActiveForm.Controls.Add("Forms.TextBox.1", "SomeNameOnTheControl)
Kontroll.left = 10
Kontroll.top = 10
Kontroll.width = 100
Kontroll.height = 16
Kontroll.Text = "SomeText"
etc...