|
-
Feb 23rd, 2001, 10:48 AM
#1
Thread Starter
Lively Member
I figured out all about DoEvents yesterday.
I'll try to explain:
Code:
Private Sub DoSomething()
Text1 = "working"
Do Until Text1 = "Quit"
DoEvents
Loop
Text1 = "Ready"
End Sub
Private Sub Command1_Click()
DoSomething
End Sub
Private Sub Command2_Click()
Text1 = "Quit"
Do Until Text1 = "Ready"
DoEvents
Loop
MsgBox "Hello"
End Sub
It never gets out of the Do..Loop in Command2.
Any suggestions to fix this or even a different thought process would be greatly appreciated.
-
Feb 23rd, 2001, 10:55 AM
#2
Looks like you haven't quite got what the use of doevents is - look at this thread : http://forums.vb-world.net/showthrea...threadid=55745
-
Feb 23rd, 2001, 10:55 AM
#3
Retired VBF Adm1nistrator
I think your code is in a kind of catch 22 situation.
Try this code :
Code:
Private Sub DoSomething()
Text1 = "working"
Do Until Text1 = "Quit"
DoEvents
Loop
Text1 = "Ready"
MsgBox "Hello"
End Sub
Private Sub Command1_Click()
DoSomething
End Sub
Private Sub Command2_Click()
Text1 = "Quit"
End Sub
- jamie
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Feb 23rd, 2001, 10:55 AM
#4
Member
What are you trying to do?
-
Feb 23rd, 2001, 11:02 AM
#5
_______
<?>
Code:
'Use a boolean variable to stop a For Next Loop
Option Explicit
Dim bGetOut As Boolean 'trigger to stop loop
Private Sub Command1_Click()
bGetOut = False 'reset if you want to start again
Dim myInt As Integer 'incremen
'display a random number as form caption in a loop
Do While Not bGetOut
Randomize 'Rnd Function
myInt = myInt + CInt(Rnd * 10) + 1 'create new caption
Me.Caption = myInt
DoEvents
Loop
End Sub
Private Sub Form_DblClick()
'dbl click the form to stop the loop
bGetOut = True
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Feb 23rd, 2001, 11:13 AM
#6
Thread Starter
Lively Member
Both of the examples that were given is basically the same as my original code w/o the Do..Loop in Command2.
The only problem with that is I haven't verified that I'm out of the other Loop before I move on to something else.
-
Feb 23rd, 2001, 11:16 AM
#7
Retired VBF Adm1nistrator
Well the example you gave is a little silly ...
Give us something more substantial and we'll see.
- jamie
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Feb 23rd, 2001, 11:26 AM
#8
Thread Starter
Lively Member
I agree, it was silly but the structure was understood.
What it's actually doing is the user keys in a stock symbol and then the program begins to download a bunch of information for that stock which takes a while. In case the user changes their mind and keys in another stock I want to cancel grabbing all the previous stock info and start downloading the new stock info.
-
Feb 23rd, 2001, 11:30 AM
#9
Retired VBF Adm1nistrator
I think someone posted this kinda thing already in here.
However,
try the following ...
Code:
Private Sub DownloadData_Click()
Winsock1.Connect ...
End Sub
Private Sub Winsock1_Connect()
Do While DoLoop
'Download commands ...
Loop
End Sub
Private Sub StopDownload_Click()
DoLoop = False
End Sub
- jamie
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Feb 23rd, 2001, 11:42 AM
#10
_______
<?>
the example was just to give you somthing to play with
Code:
Dim bReady As Boolean
Private Sub DoSomething()
Do While bReady = False
Me.Caption = CInt(Rnd * 120)
DoEvents
Loop
End Sub
Private Sub Command1_Click()
DoSomething
End Sub
Private Sub Command2_Click()
Do While bReady = True
DoEvents
Loop
MsgBox "Hello"
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Feb 23rd, 2001, 11:49 AM
#11
Thread Starter
Lively Member
HeSaidJoe, you reference bReady a few times in your example but you never set it or change it. How do any of the loops exit?
-
Feb 23rd, 2001, 12:28 PM
#12
_______
<?>
Code:
Dim bReady As Boolean
Private Sub DoSomething()
Do While Not bReady
Me.Caption = CInt(Rnd * 1200)
'reset in here when you get whatever you are looking for
If Me.Caption = 1000 Then
bReady = True
Command2_Click
Exit Do
End If
DoEvents
Loop
End Sub
Private Sub Command1_Click()
bReady = False
DoSomething
End Sub
Private Sub Command2_Click()
bReady = True
MsgBox "Hello"
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|