|
-
Jan 19th, 2002, 05:37 PM
#1
Thread Starter
New Member
Cant find error
I have set up a dynamic shape array to add new shapes to the form during runtime, but am having trouble looping them.
This way works:
Option Explicit
Private WithEvents Block As Shape
Private Sub cmdCreate_Click()
Dim Block() As Shape
Dim Name As String
ReDim Block(5) As Shape
Dim X As Integer
Dim number As Integer
Name = "Block" & number
Set Block(0) = Me.Controls.Add("VB.Shape", Name, Me)
With Block(0)
.Visible = True
.Shape = 0
.BackStyle = 1
.BackColor = vbBlue
.Height = 250
.Width = 500
End With
number = number + 1
Name = "Block" & number
Set Block(1) = Me.Controls.Add("VB.Shape", Name, Me)
With Block(1)
.Visible = True
.Shape = 0
.BackStyle = 1
.BackColor = vbBlue
.Top = 500
.Height = 250
.Width = 500
End With
number = number + 1
Name = "Block" & number
Set Block(2) = Me.Controls.Add("VB.Shape", Name, Me)
With Block(2)
.Visible = True
.Shape = 0
.BackStyle = 1
.BackColor = vbBlue
.Top = 1000
.Height = 250
.Width = 500
End With
End Sub
When I add the loop, I get a fatal execution.
Option Explicit
Private WithEvents Block As Shape
Private Sub cmdCreate_Click()
Dim Block() As Shape
Dim Name As String
ReDim Block(5) As Shape
Dim X As Integer
For X = 0 To 5
Name = "Block" & X
Set Block(X) = Me.Controls.Add("VB.Shape", Name, Me)
With Block(X)
.Visible = True
.Shape = 0
.BackStyle = 1
.BackColor = vbBlue
.Top = .Top + (500 * X)
.Height = 250
.Width = 500
End With
Next X
End Sub
Can anyone see where the error is?
Thanks for the help.
-
Jan 19th, 2002, 05:53 PM
#2
PowerPoster
Hi
Both work ok for me. Are u sure that u arent attempting to create a control that has been created earlier in code? What exact error are u getting?
Regards
Stuart
-
Jan 19th, 2002, 07:09 PM
#3
Thread Starter
New Member
no errors, just crashes my vb to desktop
-
Jan 19th, 2002, 07:16 PM
#4
PowerPoster
I think u should go the control array method per your other threads.
ie put one shape control on the form with Index = 0
then
VB Code:
For x = 1 to 20
Load Shape1(x)
With Shape1(x)
.Top = 20
.Left = x * 10
.Visible = true
End With
Next
Also, it is quicker to loop thru setting the Visible property after all controls are loaded if there are a lot of controls... ie a seperate loop at the end.
VB Code:
For x = 1 to 20
Load Shape1(x)
With Shape1(x)
.Top = 20
.Left = x * 10
End With
Next
For x = 1 to 20
Shape1(x).Visible = true
Next
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
|