Creating an array of shapes at run time


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Creating an array of shapes at run time

  1. #1
    Jaime Hyland Guest

    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



  2. #2
    jaime Hyland Guest

    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
    >
    >



  3. #3
    Sue Harsevoort Guest

    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center