p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Visual Basic > VB 2008 > Visual Basic 2008 Essentials
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Visual Basic 2008 Essentials If you are new to Visual Basic programming with version 2008, this is the place to start your questions.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2008 Essentials section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 19th, 2008, 12:29 PM
Registered User
 
Join Date: May 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Stop button won't stop loop

Here is a small program I have been playing with. At this point all it does is toggle the colors of the radio buttons.
I can't get the stop command button to stop the loop, can someone please help with what I am doing wrong. I have spent a couple weeks trying to figure it out myself.


Public Class Form1
    Dim T As Integer
    Dim A As Integer

    Public Declare Function GetTickCount Lib "kernel32" () As Long




    Private Sub Start1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Start1.Click
        A = 1
        T = 300

        Do While A = 1
            RB1.BackColor = System.Drawing.Color.LightGreen
            Me.Refresh()
            wait(T)
            RB1.BackColor = System.Drawing.Color.Red
            Me.Refresh()

            RB2.BackColor = System.Drawing.Color.LightGreen
            Me.Refresh()
            wait(T)
            RB2.BackColor = System.Drawing.Color.Red
            Me.Refresh()

            RB3.BackColor = System.Drawing.Color.LightGreen
            Me.Refresh()
            wait(T)
            RB3.BackColor = System.Drawing.Color.Red
            Me.Refresh()

            RB4.BackColor = System.Drawing.Color.LightGreen
            Me.Refresh()
            wait(T)
            RB4.BackColor = System.Drawing.Color.Red
            Me.Refresh()

            RB5.BackColor = System.Drawing.Color.LightGreen
            Me.Refresh()
            wait(T)
            RB5.BackColor = System.Drawing.Color.Red
            Me.Refresh()


        Loop


    End Sub






    Public Sub wait(ByVal dblMilliseconds As Double)
        Dim dblStart As Double
        Dim dblEnd As Double
        Dim dblTickCount As Double

        dblTickCount = GetTickCount()
        dblStart = GetTickCount()
        dblEnd = GetTickCount + dblMilliseconds

        Do
            dblTickCount = GetTickCount()
        Loop Until dblTickCount > dblEnd Or dblTickCount < dblStart


    End Sub


    Private Sub Stop1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Stop1.Click
        A = 0

        RB1.BackColor = System.Drawing.Color.Blue
        RB2.BackColor = System.Drawing.Color.Blue
        RB3.BackColor = System.Drawing.Color.Blue
        RB4.BackColor = System.Drawing.Color.Blue
        RB5.BackColor = System.Drawing.Color.Blue


    End Sub


End Class

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old May 19th, 2008, 01:06 PM
Friend of Wrox
Points: 5,269, Level: 30
Points: 5,269, Level: 30 Points: 5,269, Level: 30 Points: 5,269, Level: 30
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 1 Time in 1 Post
Default

Have you verified that Stop1_Click runs? If that button has been renamed so that " Handles Stop1.Click" refers to nothing, then the event won't run.

If Sub wait() ties up the computer, the click on the button might get ignored.
Or perhaps clicking the button does get noted by the computer, but when the Windows Message is dispatched, it gets ignored because the processor is busy.

Seems a first step. (You could change the caption of the form as proof...)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old May 19th, 2008, 02:56 PM
Registered User
 
Join Date: May 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have verified that the button is named properly. When I click the stop1 first the radio buttons do change color to blue. I just tried taking out the delay function. The program still just loops and doesn't see the stop. Do I need to do something in the loop so it will check if the stop button has been clicked?
Thanks.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old May 23rd, 2008, 04:22 PM
Friend of Wrox
Points: 5,269, Level: 30
Points: 5,269, Level: 30 Points: 5,269, Level: 30 Points: 5,269, Level: 30
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 1 Time in 1 Post
Default

This still misbehaves. You click the start, and it starts. You click the stop or the form's client area and the start button depresses.

Having done that, clicking the stop then functions. (?)
Code:
Public Class Form1
    Dim T As Integer
    Dim A As Integer

    Public Declare Function GetTickCount Lib "kernel32" () As Long

    Private Sub Start1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Start1.Click
        A = 1
        T = 300

        Do While A = 1
            ProcessRB(1): If A = 0 Then Exit Do
            ProcessRB(2): If A = 0 Then Exit Do
            ProcessRB(3): If A = 0 Then Exit Do
            ProcessRB(4): If A = 0 Then Exit Do
            ProcessRB(5)
        Loop

    End Sub

    Public Sub ProcessRB(ControlNum As Integer)

        Dim c As Control
            c = Me.Controls("RB" & ControlNum)

        c.BackColor = System.Drawing.Color.LightGreen
        Me.Refresh()
        If A = 0 Then Exit Sub
        wait(T)
        If A = 0 Then Exit Sub
        c.BackColor = System.Drawing.Color.Red
        Me.Refresh()

    End Sub

    Public Sub wait(ByVal dblMilliseconds As Double)

        Dim dblStart As Double
        Dim dblEnd As Double
        Dim dblTickCount As Double

        dblTickCount = GetTickCount()
        dblStart = GetTickCount()
        dblEnd = GetTickCount + dblMilliseconds

        Do
            dblTickCount = GetTickCount()
            System.Windows.Forms.Application.DoEvents()
            If a = 0 Then Exit Do
        Loop Until dblTickCount > dblEnd Or dblTickCount < dblStart

    End Sub

    Private Sub Stop1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Stop1.Click

        A = 0

        RB1.BackColor = System.Drawing.Color.Blue
        RB2.BackColor = System.Drawing.Color.Blue
        RB3.BackColor = System.Drawing.Color.Blue
        RB4.BackColor = System.Drawing.Color.Blue
        RB5.BackColor = System.Drawing.Color.Blue

    End Sub

End Class
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to stop file uploading when a cancel button coolcoder2007 ASP.NET 2.0 Basics 0 October 26th, 2007 05:21 AM
How to know my COM+ stop start vanthq Pro VB Databases 0 January 6th, 2006 05:19 AM
Loop through records- stop if certain value met SoC Classic ASP Basics 2 July 28th, 2005 09:22 PM
Cannot stop the process mcinar SQL Server 2000 11 October 20th, 2004 08:39 AM
Mail Loop Will Randomly Stop Working jimmlegs VBScript 1 February 2nd, 2004 08:18 AM



All times are GMT -4. The time now is 05:42 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc