Hi, I new here and currently learning as much programming languages as needed.

To start with the simplest programming language, VB.

I'm kind of having problems with producing an animation that uses the FOR Loop statement and the System.Threading.Thread.Sleep () command.

I've placed two objects (rectangles) together and would like to create a fake animation of 2nd rectangle yielding to the first object as if its pushing it. And place a line as a larger marker of movement.

The output should refresh the image in each time interval.

But instead of a multiple resizing and showing, the output only resizes the image once and directly goes to the final result.

For x = 0 To [[I]Limiting value w/c depends on input[/I]] Step 1
                System.Threading.Thread.Sleep(1000)

                RectangleShape1.Width = Val(a.Text) - x
                RectangleShape2.Left = 500 - x
                RectangleShape2.Width = Val(b.Text) + x
                Line2.Left = RectangleShape2.Left
                Line2.Visible = True

                Line2.Refresh()
                RectangleShape1.Refresh()
                RectangleShape2.Refresh()
                Next x

I'm stuck because it doesn't fake an animation, it acts like this code which imposes an instantaneous resizing.

RectangleShape1.Width = Val(a.Text) - Val(TextBox3.Text)
                RectangleShape2.Left = 500 - Val(TextBox4.Text)
                RectangleShape2.Width = Val(b.Text) + Val(TextBox4.Text)
                Line2.Left = RectangleShape2.Left
                Line2.Visible = True

Is there any other way to fake an animation or I have something wrong in my code?

Help would be greatly appreciated :)

By the way, I'm currently using VB2008 :(

Recommended Answers

All 9 Replies

You need multithreading :) to do that

Thank you for the answer, i'll look more into multithread

But how can i call a multithread?

To be frank, I've never encountered using multithread before, it is also my first time to fake an animation using loop and the Thread.Sleep command.

Can someone please elaborate what is and how to use multithread inside a loop that needs a refreshing of the image each time it goes thru the loop.

Thanks again.

You told me you'll read, after reading come here back and tell me what did you do? you'll say I can use it well :) just try it's very

Nope, i still can't use it well.

I've been thinking of using the Timer function, would that work?

Try...

Wow, imagine you helped me solve my problem by nagging on me :)

I didn't use any multithread. >:(

I'm now using the timer and it now animates

The new problem now is my animation goes indefinitely.
Is there any code like "break;" command in c that will stop the timer when it reaches a certain limit?

Come on now, start naggin.

I've managed to solve my other problem and got the results i wanted.

Thanks for the help and motivation. :)

But i'm not gonna tell how i did it :twisted:

timer1.enabled = false ;)

nope, that would require a button to stop it or some other action.

the thing i did stops on its own, without any other command :)

I've put something in the timer to make it stop, that's close but not quite, and its not timer1.stop() either :twisted:

Resizing only to a certain point.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.