TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
MDavid Johnson
NA
3
1.5k
Stop Button
Jun 27 2012 4:44 PM
I need to use a "Run" button and a "Stop" button to control the execution of an internal subroutine. The following code works, but you have to click the Stop button twice to stop the routine. What do I have to do to get it to stop in a single click?
-----
' RunTest.exe
' Version 1.0.0
' MDJ 2012/06/27
' Label1 initially displays "STOPPED"
Option Strict On
Imports System.Windows
Public Class Form1
' Global Variable
Public runControl As Boolean
' Run Button
Private Sub RunButton_Click(sender As System.Object, e As System.EventArgs) Handles RunButton.Click
runControl = True
Label1.Text = "RUNNING"
While runControl = True
RunStep()
End While
End Sub
' Stop Button
Private Sub StopButton_Click(sender As System.Object, e As System.EventArgs) Handles StopButton.Click
' With this configuration, the Stop button must be clicked twice before the While Loop will exit ???
runControl = False
Label1.Text = "STOPPED"
End Sub
Public Sub RunStep()
Dim ValueHolder As Integer
' Process some data
For i = 1 To 79
For j = 1 To 79
ValueHolder = i * j + 23
Next
Next
' Allow outside events to be processed
Application.DoEvents()
End Sub
End Class
Reply
Answers (
2
)
VB calculating salary
Datagridview in VB.net connecting to Access slow