-
Creating an array of shapes at run time
Hi all,
I wonder if anyone can help me to create program that piles a load of hoops
on top of each other. The user defines the number of hoops (to a maximum
of 64).
The code below works if I create an array of 64 HoopOne at design time.
The user enters a number into txtNumHoops textbox and the program sets their
visible property to true, positions and sizes them.
It would be tidier though if the program actually created them at run time
Has anyone got any suggestions?
Thanks in advance,
Jaime
__________________________________________________________________
Option Explicit
Dim mNumHoops As Integer
Private Sub cmdCalculate_Click()
Dim x As Integer
If txtNumHoops.Text = "" Then
txtNumHoops.Text = 0
End If
mNumHoops = txtNumHoops.Text
ReDim hoopOne(mNumHoops)
For x = 0 To mNumHoops - 1
hoopOne(x).Visible = True
If x = 0 Then
hoopOne(x).Height = 6500 / mNumHoops
hoopOne(x).Top = linbase1.Y1 - (18 + hoopOne(x).Height)
hoopOne(x).Width = 2000
hoopOne(x).Left = linTower1.X1 - (hoopOne(x).Width / 2)
Else
hoopOne(x).Height = 6500 / mNumHoops
hoopOne(x).Top = (hoopOne(x - 1).Top) - (hoopOne(x).Height)
hoopOne(x).Width = hoopOne(x - 1).Width - (hoopOne(x - 1).Width
/ (mNumHoops + 10))
hoopOne(x).Left = linTower1.X1 - (hoopOne(x).Width / 2)
End If
Next x
End Sub
-
Re: Creating an array of shapes at run time
Sorry, the code I just posted had an error. It should have been:
Option Explicit
Dim mNumHoops As Integer
Private Sub cmdCalculate_Click()
Dim x As Integer
If txtNumHoops.Text = "" Then
txtNumHoops.Text = 0
End If
mNumHoops = txtNumHoops.Text
For x = 0 To mNumHoops - 1
hoopOne(x).Visible = True
If x = 0 Then
hoopOne(x).Height = 6500 / mNumHoops
hoopOne(x).Top = linbase1.Y1 - (18 + hoopOne(x).Height)
hoopOne(x).Width = 2000
hoopOne(x).Left = linTower1.X1 - (hoopOne(x).Width / 2)
Else
hoopOne(x).Height = 6500 / mNumHoops
hoopOne(x).Top = (hoopOne(x - 1).Top) - (hoopOne(x).Height)
hoopOne(x).Width = hoopOne(x - 1).Width - (hoopOne(x - 1).Width
/ (mNumHoops + 10))
hoopOne(x).Left = linTower1.X1 - (hoopOne(x).Width / 2)
End If
Next x
End Sub
>
>Hi all,
>
>I wonder if anyone can help me to create program that piles a load of hoops
>on top of each other. The user defines the number of hoops (to a maximum
>of 64).
>
>The code below works if I create an array of 64 HoopOne at design time.
>The user enters a number into txtNumHoops textbox and the program sets their
>visible property to true, positions and sizes them.
>
>It would be tidier though if the program actually created them at run time
>
>Has anyone got any suggestions?
>
>
>Thanks in advance,
>
>
>Jaime
>__________________________________________________________________
>Option Explicit
>
>Dim mNumHoops As Integer
>
>Private Sub cmdCalculate_Click()
> Dim x As Integer
>
> If txtNumHoops.Text = "" Then
> txtNumHoops.Text = 0
> End If
>
> mNumHoops = txtNumHoops.Text
>
> For x = 0 To mNumHoops - 1
> hoopOne(x).Visible = True
> If x = 0 Then
> hoopOne(x).Height = 6500 / mNumHoops
> hoopOne(x).Top = linbase1.Y1 - (18 + hoopOne(x).Height)
> hoopOne(x).Width = 2000
> hoopOne(x).Left = linTower1.X1 - (hoopOne(x).Width / 2)
> Else
> hoopOne(x).Height = 6500 / mNumHoops
> hoopOne(x).Top = (hoopOne(x - 1).Top) - (hoopOne(x).Height)
> hoopOne(x).Width = hoopOne(x - 1).Width - (hoopOne(x - 1).Width
>/ (mNumHoops + 10))
> hoopOne(x).Left = linTower1.X1 - (hoopOne(x).Width / 2)
> End If
> Next x
>
>End Sub
>
>
-
Re: Creating an array of shapes at run time
You can add just one hoopOne at design time with an index of 0 and the
progrmatically add more using
Load hoopOne(x)
Check out control arrays in help for more info.
Sue
"jaime Hyland" <jaime.hyland@iolfree.ie> wrote in message
news:3c76292c$1@10.1.10.29...
>
> Sorry, the code I just posted had an error. It should have been:
> Option Explicit
> Dim mNumHoops As Integer
>
> Private Sub cmdCalculate_Click()
> Dim x As Integer
>
> If txtNumHoops.Text = "" Then
> txtNumHoops.Text = 0
> End If
>
> mNumHoops = txtNumHoops.Text
>
> For x = 0 To mNumHoops - 1
> hoopOne(x).Visible = True
> If x = 0 Then
> hoopOne(x).Height = 6500 / mNumHoops
> hoopOne(x).Top = linbase1.Y1 - (18 + hoopOne(x).Height)
> hoopOne(x).Width = 2000
> hoopOne(x).Left = linTower1.X1 - (hoopOne(x).Width / 2)
> Else
> hoopOne(x).Height = 6500 / mNumHoops
> hoopOne(x).Top = (hoopOne(x - 1).Top) - (hoopOne(x).Height)
> hoopOne(x).Width = hoopOne(x - 1).Width - (hoopOne(x -
1).Width
> / (mNumHoops + 10))
> hoopOne(x).Left = linTower1.X1 - (hoopOne(x).Width / 2)
> End If
> Next x
>
> End Sub
> >
> >Hi all,
> >
> >I wonder if anyone can help me to create program that piles a load of
hoops
> >on top of each other. The user defines the number of hoops (to a maximum
> >of 64).
> >
> >The code below works if I create an array of 64 HoopOne at design time.
>
> >The user enters a number into txtNumHoops textbox and the program sets
their
> >visible property to true, positions and sizes them.
> >
> >It would be tidier though if the program actually created them at run
time
> >
> >Has anyone got any suggestions?
> >
> >
> >Thanks in advance,
> >
> >
> >Jaime
> >__________________________________________________________________
> >Option Explicit
> >
> >Dim mNumHoops As Integer
> >
> >Private Sub cmdCalculate_Click()
> > Dim x As Integer
> >
> > If txtNumHoops.Text = "" Then
> > txtNumHoops.Text = 0
> > End If
> >
> > mNumHoops = txtNumHoops.Text
> >
> > For x = 0 To mNumHoops - 1
> > hoopOne(x).Visible = True
> > If x = 0 Then
> > hoopOne(x).Height = 6500 / mNumHoops
> > hoopOne(x).Top = linbase1.Y1 - (18 + hoopOne(x).Height)
> > hoopOne(x).Width = 2000
> > hoopOne(x).Left = linTower1.X1 - (hoopOne(x).Width / 2)
> > Else
> > hoopOne(x).Height = 6500 / mNumHoops
> > hoopOne(x).Top = (hoopOne(x - 1).Top) - (hoopOne(x).Height)
> > hoopOne(x).Width = hoopOne(x - 1).Width - (hoopOne(x -
1).Width
> >/ (mNumHoops + 10))
> > hoopOne(x).Left = linTower1.X1 - (hoopOne(x).Width / 2)
> > End If
> > Next x
> >
> >End Sub
> >
> >
>
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
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks