Drawing  an oval and making it smaller with code

Posted on 2005-03-31
Medium Priority
Last Modified: 2010-05-02
I want to create a falling down (or up) tunnel effect.

I want to have a form with about 20 ovals on it .
The first oval starting from the size of a dot, with each of the other ovels getting bigger with the last ovel filling the  screen.

I then want some code under a command button that will make the ovals get smaller until they are just a dot at the center  of the form. I also need create new outer ovals to take the place of each oval that disapears creating a continous falling effect.

I have provided some code that will demonstrate the type of effect I'm after using a shape control

Place two oval shape controls on a form one bigger than the other and put the following code under a command botton

Private Sub Command1_Click()
For x = 1 To 6000
    Shape1.Height = Shape1.Height - 1
    Shape1.Width = Shape1.Width - 1
    Shape2.Height = Shape2.Height - 1
    Shape2.Width = Shape2.Width - 1
 Next x
End Sub
Question by:backflash
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2

Expert Comment

ID: 13678590
This sounds like a fun question to play with, but i really just dont have the time at the moment.
What you might like to investigate with though is the use of control arrays.
Generate your initial shape then copy + paste it. you'll be given the option of creating a control array of that object. You should select yes, you can then use code like this to reduce each object one at a time...

For x = 1780 To 0 Step -1     'Initial size of my object was 1780
    For y = 0 To 19       ' I have 20 ovals that i wish to reduce within my control array
        Shape1(y).Height = Shape1(y).Height - 1
    Next i
Next x

Hope this is of some help.

Accepted Solution

craigewens earned 1000 total points
ID: 13678734
Small oversight on one of the lines..

For y = 0 To 19

should really be something like

For y = Shape1.LBound To Shape1.UBound

Just makes things a little nicer :)
LVL 16

Expert Comment

ID: 13679930
As craigewans suggests, a control array is the best method.  

Instead of creating 20 Shape objects (Shape1, Shape2, Shape3, etc) create a Shape object (shpOval) and set its Index property to 0.  Now create another Shape object (also called shpOval) and set its Index to 1.  Do the same for 2 to 21 and set them up with the initial sizes that you want.  You should now have 21 Shape objects (shpOval(0), shpOval(1), shpOval(2), etc.)

Now set shpOval(0) to be the biggest shape that you want and set it's Visible property to False (this is your template shape).

Add a command button (btnStartStop) and paste the following code into your Form:

    Private Const gc_nShrink As Long = 10
    Private Const gc_nDelay As Long = 100

    Private g_bIsRunning As Boolean

    Sub TunnelEffectLoop()

        Dim nShape As Long
        Dim nDelay As Long


            If g_bIsRunning And nDelay = gc_nDelay Then
                nDelay = 0

                For nShape = 1 To UBound(shpOval())

                    With shpOval(nShape)

                        If .Height > gc_nShrink And .Width > gc_nShrink Then
                            'SHRINK OVALS BY DESIRED AMOUNT
                            .Height = .Height - gc_nShrink
                            .Width = .Width - gc_nShrink
                            .Top = .Top + (gc_nShrink / 2)
                            .Left = .Left + (gc_nShrink / 2)
                            'RESET OVAL TO TEMPLATE SIZE
                            .Height = shpOval(0).Height
                            .Width = shpOval(0).Width
                            .Top = shpOval(0).Top
                            .Left = shpOval(0).Left
                        End If

                    End With

                Next nShape      

            End If

            nDelay = nDelay + 1
            DoEvents               'ALLOW WINDOWS TO PROCESS ANY MESSAGES


    End Sub

    Private Sub Form_Load()
        TunnelEffectLoop()     'START EFFECT CHECK
    End Sub

    Private Sub btnStartStop_Click()

        If g_bIsRunning Then
            btnStartStop.Caption = "Start"
            g_bIsRunning = False
            btnStartStop.Caption = "Stop"
            g_bIsRunning = True
        End If

    End Sub

Run the program and click the button.  It should start to cycle and recycle the ovals.  You should also be able to click the button again to stop it.

Fiddle with the values of gc_nDelay and gc_nShrink to affect the speed/magnitude of the effect...


Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 16

Expert Comment

ID: 13679942
One small amendment; change the following:

                nDelay = nDelay + 1


                If g_bIsRunning Then nDelay = nDelay + 1



Author Comment

ID: 14050904
Sorry about the delay in following up on your answers.

School Hollidays and a computer crash saw me  out of action for a little while. (Dam I wish I was rich)

craigewens I got your  little demo working ok

jimbob I couldn't  get your code to work.
have you  tried it out and had it working?  (not a critisism, it just the I'm not an advanced user Your code looke ok on the serface so perhaps I haven't transferred the code into my program properly)

kind regards


Author Comment

ID: 14201121
Thanks for the help  people

Much appreciated


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question