Wait before continuing

Android

Active member
Joined
Mar 6, 2007
Messages
35
Programming Experience
1-3
I have a program that moves a textbox across the screen. I have written 4 subs to move the textbox in each direction, these enable a timer that increments or decrements the x or y depending on where it is going on each tick. once it is in position the timer disables itself.

The problem i am having is that if it want it to move up, then right i cant just call both subs as the move right overwrites everything for the move up and so it just moves right ignoring up completely. Also i dont want the program to continue until the text box reaches its destination, is there anyway that i could make the program wait until textbox stops moving before continuing on?

Although my profile says .net 2, for this project im using .net 1

Thanks
 
Last edited:
My timer tick
VB.NET:
    Private Sub tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmrMove.Tick
        If txtData.Location.X = endPos.X And txtData.Location.Y = endPos.Y Then
            tmrMove.Enabled = False
        End If
        Select Case Direction
            Case MoveDir.Up
                txtData.Top -= MoveAmount
            Case MoveDir.Down
                txtData.Top += MoveAmount
            Case MoveDir.Left
                txtData.Left -= MoveAmount
            Case MoveDir.Right
                txtData.Left += MoveAmount
        End Select
    End Sub

My movesub, i have changed this since posting to have 1 for all directions but still same problem

VB.NET:
    Public Sub MoveTxt(ByVal startP As Point, ByVal endP As Point, ByVal data As TextBox, ByVal dir As MoveDir)
        data.Location() = startP
        endPos = endP
        txtData = data
        Direction = dir
        tmrMove.Enabled = True
    End Sub

VB.NET:
    Private Sub btnRun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRun.Click
        MoveTxt(New Point(100, 100), New Point(100, 50), txtData, MoveDir.Up)
        MoveTxt(New Point(100, 50), New Point(150, 50), txtData, MoveDir.Right)
    End Sub
 
I'm afraid I'm having trouble following your code but what does this do?

VB.NET:
While txtData.Location.X <> endPos.X And txtData.Location.Y <> endPos.Y
 
Select Case Direction
Case MoveDir.Up
txtData.Top -= MoveAmount
Case MoveDir.Down
txtData.Top += MoveAmount
Case MoveDir.Left
txtData.Left -= MoveAmount
Case MoveDir.Right
txtData.Left += MoveAmount
End Select
txtData.Show
Loop
 
Last edited by a moderator:
That doesn't appear to work at all. I'm guessing that you meant to do that instead of the timer? if so then it doesn't work.
 
i worked out how to do this. as the timer disables itself once the textbox has reached position. I got it to wait until the timer is disabled before continuing. This seems to work.

VB.NET:
    Public Sub WaitForFinish()
        'Keep looping until the timer is disabled
        Do Until tmrMove.Enabled = False
            Application.DoEvents()
        Loop
    End Sub
 
Can you more accurately explain how you want the textbox to behave? Your description doesnt make much sense.

I'd like to point out that the way you have implemented this is quite inflexible with respect to moving in ore than one dimension at a time, as you have found. You should also never, ever (ever) go into a tight loop on DoEvents just to wait for something to happen
 
The program is for a simulation of the fetch execute cycle. The textbox moving contains data moving between the various parts of a processor. I want the text box to follow the buses between the part to show what is happening.

The problem that i am having is if i call MoveTxt to move the textbox up, then call it again to move it right. it will run it once but then the code continues on the move it right. I want it to wait until the textbox has finished moving up, before it starts moving right.

I got it to do this using the WaitForFinish sub I just posted but if this shouldnt be done then how else could I achieve the same result?

I have also changed my MoveTxt sub again to make it better for moving only 1 dimension.
VB.NET:
    Public Sub MoveTxt(ByVal startP As Point, ByVal endP As Integer, ByVal data As TextBox, ByVal dir As MoveDir)
        data.Location = startP
        endPos = endP
        txtData = data
        Direction = dir
        tmrMove.Enabled = True
    End Sub

Hope thats a better description.
 
Do you mean that you want your textbox to follow a path?

Then why not use an array of Point objects, or an array of motion vectors.. For example to get your box to move up 4 times then right 5 times, then diagonally down and left 3 times:

Dim path()() as Integer = {
{0, -10}, 'zero X coord, -10 Y coord
{0, -10},
{0, -10},
{0, -10},
{10, 0},
{10, 0},
{10, 0},
{10, 0},
{-10, 10},
{-10, 10},
{-10, 10}
}

Each timer tick, you read the next vector, move the textbox by that amount and when you reach the end of the array, ignore the timer ticks

The timer ticks all the time. Whether you listen to it or not defines whether the textbox moves. Keep track of which index of motion youre at. Design a custom class that will hold the motions array and also the index it is on, then put it in the .Tag of the textbox. Each tick, examine the tag of each textbox, and make the relevant motion.

Getting it to walk the path all over again again is as simple as setting the index of motion back to 0
 
my problem is not moving the textbox around, it is that once i enable the timer and it moves it each tick, the code continues on to the next line. I want the whole execution of the process to stop until the textbox reaches it's destination. that is why i had the loop of application.doevents. it was so that the program would stay in the loop until the timer was disabled meaning that the textbox had reached its destination. then the program could continue.
 
I dont think you understood what I was getting at in my post. Youre writing a storyboard, that happens in the timer tick event. Depending on the number of ticks that have happened so far, the story changes

Think about a cartoon, in a comic book. Its a set of still images depicting a story. If you, a human, can read one image per second, and the story is 30 images long, then in half a minute you will have absorbed the whole story. If you scanned the pictures in and showed them on a timer tick successively then again you would get the story across in 30 seconds. Now suppose your entire form was a picture box, with images of a textbox moving and once per tick you loaded an image giving the impression of a textbox that is moving..
Now take that concept of understanding in your mind, and instead of using a succession of gif images, make it as though the form and all its controls, are the images.. storyboard its movement, storyboard text being put into it, storyboard it moving again, whatever

Your app must do nothing between timer ticks, that's the whole point!
 
Back
Top