Sie sind auf Seite 1von 11

User Name Password Log in Help Register

Remember Me?

Forum What's New? Advertiser Disclosure

New Posts FAQ Calendar Forum Actions Quick Links Advanced Search

VBForums Visual Basic Visual Basic 6 and Earlier [VB6] - about Doevents

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing
messages, select the forum that you want to visit from the selection below.

Results 1 to 35 of 35

Thread: [VB6] - about Doevents

Thread Tools Display

Nov 20th, 2012, 04:27 PM #1

joaquim
[VB6] - about Doevents
Thread Starter
PowerPoster can anyone explain to me why we need use the doevents?
and if we can avoid it for speed?

Click H
Join Date: Apr 2007
Posts: 3,358

VB6 2D Sprite control

To live is difficult, but we do it.

Reply With Quote

Nov 20th, 2012, 05:32 PM #2

SamOscarBrown
Re: [VB6] - about Doevents
PowerPoster
Sure:
In many situations, the DoEvents keyword can be a real boon. As you may know, this keyword yields operation to the
operating system so that it can process other events. Many times after initiating a procedure, you may want to pause
execution to gather further information from an end user via a form. For example, consider a project with two forms.
Join Date: Aug 2012 The main form performs a calculation and displays the results. The second form lets an end user manually enter two
Location: NC, USA numbers for the calculation. When you click the second form's Submit button, the main form multiplies the user-
Posts: 7,427 entered numbers and displays the results.
Typically, to handle this feature, you might use DoEvents to wait until the user has entered the two numbers.

Reply With Quote

Nov 20th, 2012, 05:34 PM #3

SamOscarBrown
Re: [VB6] - about Doevents
PowerPoster
Also, jmsrickland responded to a post just recently with these words of wisdom:
Usually you will see DoEvents in a loop. It allows the system to take care of other things while you are in the loop. If
you don't put a DoEvent in a loop, especially a lengthy loop nothing else can take place until the loop ends. What do
you think will happen if you get stuck in a loop and your loop does not have a DoEvents in it? You can't get out of the
Join Date: Aug 2012 loop unless you kill the program. So by putting a DoEvent in that loop you could add a button that will allow you to
Location: NC, USA either break out of the loop or examine what is taking place. Without the DoEvent the button or any other control is
Posts: 7,427 useless until the loop ends.

Reply With Quote

Nov 20th, 2012, 05:57 PM #4

DataMiser
Re: [VB6] - about Doevents
PowerPoster
Basically DoEvents should be used sparingly and you may run into issues depending on how your app is coded.
Join Date: Feb 2012
Location: West Virginia If you are running a long loop like perhaps reading 10,000 records from a database or something like that without the
Posts: 13,260 doevents then form repaints and such will not happen plus the program will not respond to windows messages and the
UI will appear to be frozen. You may also get a not responding message on the title bar or in task manager even
though the program is still working fine. If you switch to another program and back during such a process you may not
see your program at all until either it hits a doevents or completes the loop.

On the downside if you have a timer running or a Winsock or Com control when a doevents is hit the code may jump to
the sub for one of those events and start executing even though that is not what you may want to happen. So again
they must be used wisely. Often you can over come potential display issues by using a call to refresh rather than
doevents without the other side effects.
Reply With Quote

Nov 21st, 2012, 08:35 AM #5

joaquim
Re: [VB6] - about Doevents
Thread Starter
PowerPoster thanks to all.
but i have 1 problem on 1 code
Code:
Private Sub GetPic()
Join Date: Apr 2007
Posts: 3,358 Picture2.Picture = Nothing
UserControl.Picture = Nothing
UserControl.BorderStyle = 0

UserControl.MaskPicture = Nothing

API_DoEvents

CaptureContiner Picture2.hdc, UserControl.ContainerHwnd, _


Extender.Left + 2, Extender.Top + 2, Extender.Width, Extender.Height

TransparentAlphaBlend Picture1.hdc, Picture2.hdc, Extender.Width, Extender.Height, CInt(lngOp

UserControl.Picture = Picture2.Image

UserControl.MaskPicture = UserControl.Image
UserControl.MaskColor = UserControl.BackColor
UserControl.BorderStyle = 1
End Sub

i use API_doevents, but is more or less same.


if i don't use the API_doevents or doevents the container isn't updated\readrawed or something like these
in these case the API_doevents or doevents is slowing down my code
heres the module:
Code:
Option Explicit

Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Lo
Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Lon
Private Declare Function SetPixelV Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Lo

Public Sub CaptureContiner(DestinationHDC As Long, SourceHWND As Long, SourceX As Long, SourceY A


SourceHWND = GetDC(SourceHWND)
BitBlt DestinationHDC, 0, 0, SourceWidth, SourceHeight, SourceHWND, SourceX, SourceY, vbSrcCo
End Sub

'Opacy an image(alpha blend): finalrgb = a*rgb1 + (1-a)rgb2


Public Sub TransparentAlphaBlend(ByRef SrcHDC As Long, ByRef DstHDC As Long, ByRef SrcWidth As Lo
Dim x As Long, y As Long
Dim lngsrcColor As Long
Dim lngdstColor As Long
Dim lngNewColor As Long
Dim dblAlphaDst As Long
Dim dblAlpha As Double, R As Long, G As Long, B As Long
Dim SrcRed As Long, SrcBlue As Long, SrcGreen As Long
Dim DstRed As Long, DstBlue As Long, DstGreen As Long

'convert the values from 0-100 to 0-255


dblAlpha = 255 - (Opacy * 255 / 100)

For x = 0 To SrcWidth - 1
For y = 0 To SrcHeight - 1
'geting the source and destination colors\pixels

can anyone advice me for don't use the doevents, in these case?

VB6 2D Sprite control

To live is difficult, but we do it.

Reply With Quote

Nov 21st, 2012, 08:56 AM #6

Bonnie West
Re: [VB6] - about Doevents
Default Member
Perhaps the UserControl's Refresh method might help.

Join Date: Jun 2012


Location: InIDE
Posts: 4,057

On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency:
Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo
0
My CodeBank Contributions
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
Reply With Quote

Nov 21st, 2012, 09:00 AM #7

techgnome
Re: [VB6] - about Doevents
PowerPoster
DoEvents doesn't slow down code (not directly) ... what it does is tells Windows, hey, if you have any pending
messages, go ahead and process them... things like updating the UI, processing clicks, etc.
That's usually why people use doevents, so they can see their updates on the screen. UI threads are among the lowest
priority when it comes to processing which is why you're not seeing updates, the system is busy with other things.

Join Date: May 2002 That said, you should NOT call doevents on each and every single iteration of the loop... you should only call it on
Posts: 32,904 occasion.
Code:
For a as integer = 1 to 10000
if a mod 100 = 0 then
doevents
end if
next

This will call DoEvents every 100th iteration through the loop.

-tg

* I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
* I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
* How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
* How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my
data, where'd it run off to??? *

Reply With Quote

Nov 21st, 2012, 09:00 AM #8

joaquim
Re: [VB6] - about Doevents
Thread Starter
PowerPoster
Originally Posted by Bonnie West
Perhaps the UserControl's Refresh method might help.
Join Date: Apr 2007
Posts: 3,358 i have tested now and don't works

VB6 2D Sprite control

To live is difficult, but we do it.

Reply With Quote

Nov 21st, 2012, 09:04 AM #9

joaquim
Re: [VB6] - about Doevents
Thread Starter
PowerPoster
Originally Posted by techgnome
DoEvents doesn't slow down code (not directly) ... what it does is tells Windows, hey, if you have any pending messages,
go ahead and process them... things like updating the UI, processing clicks, etc.
That's usually why people use doevents, so they can see their updates on the screen. UI threads are among the lowest
Join Date:
Posts:
Apr 2007
3,358 priority when it comes to processing which is why you're not seeing updates, the system is busy with other things.
That said, you should NOT call doevents on each and every single iteration of the loop... you should only call it on
occasion.
Code:
For a as integer = 1 to 10000
if a mod 100 = 0 then
doevents
end if
next

This will call DoEvents every 100th iteration through the loop.
-tg
i understand what you mean, but can i avoid the doevents?
my transparentalphablend() use getpixel() and setpixelV() like you have seen the code(module). but the sample image
is with my avatar size. but i can see 1 second(or less) for change the image... so how can i avoid the doevents?
VB6 2D Sprite control

To live is difficult, but we do it.

Reply With Quote

Nov 21st, 2012, 09:30 AM #10

Bonnie West
Re: [VB6] - about Doevents
Default Member
If you avoid DoEvents, then your UI will freeze. If you call it often, then your code will slow down. techgnome just
showed you a compromise between the two.

Join Date: Jun 2012


Location: InIDE
Posts: 4,057

On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency:
Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo
0
My CodeBank Contributions
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

Reply With Quote

Nov 21st, 2012, 10:01 AM #11

dw85745
Re: [VB6] - about Doevents
PowerPoster
Appleman wrote an article years ago (Visual Basic Programmers Journal as I recall) that describes what's known as a
Join Date: Jul 2001 "State Machine". It is slightly different approach to event programming and is designed to try and eliminate UI lag.
Location: Tucson, AZ Alternatively, if can wrap up what your trying to do in an ActiveX control, then it "effectivwely" will run in a separate
Posts: 2,166 thread (like a menu) and will have no lag.
If you search for "State Machine" this forum I believe I've posted this article or a reference to it in the past.

Programs: VB6 Learn Sign Language http://www.vbforums.com/showthread.php?t=637161,

Text To Speak http://"http://www.vbforums.com/show...65#post3985265,

Speak Text - Using Word http://www.vbforums.com/showthread.p...ghlight=speech

Reply With Quote

Nov 21st, 2012, 10:07 AM #12

joaquim
Re: [VB6] - about Doevents
Thread Starter
PowerPoster
Originally Posted by Bonnie West
If you avoid DoEvents, then your UI will freeze. If you call it often, then your code will slow down. techgnome just showed
you a compromise between the two.
Join Date: Apr 2007
Posts: 3,358
i understand what you mean, but, without speaking in my sub(i can use DIB's instead), how can i speed up my code?
dw85745 i'm trying search what you said... thanks

VB6 2D Sprite control

To live is difficult, but we do it.

Reply With Quote

Nov 21st, 2012, 10:07 AM #13

joaquim
Re: [VB6] - about Doevents
Thread Starter
PowerPoster
Originally Posted by Bonnie West
If you avoid DoEvents, then your UI will freeze. If you call it often, then your code will slow down. techgnome just showed
you a compromise between the two.
Join Date: Apr 2007
Posts: 3,358
i understand what you mean, but, without speaking in my sub(i can use DIB's instead), how can i speed up my code?
dw85745 i'm trying search what you said... thanks
VB6 2D Sprite control

To live is difficult, but we do it.

Reply With Quote

Nov 21st, 2012, 02:58 PM #14

dw85745
Re: [VB6] - about Doevents
PowerPoster
An internet search will lead you to:
Join Date: Jul 2001
Location: Tucson, AZ http://www.desaware.com/tech/statemachineintro.aspx
Posts: 2,166

Programs: VB6 Learn Sign Language http://www.vbforums.com/showthread.php?t=637161,

Text To Speak http://"http://www.vbforums.com/show...65#post3985265,

Speak Text - Using Word http://www.vbforums.com/showthread.p...ghlight=speech

Reply With Quote

Nov 22nd, 2012, 09:18 AM #15

firoz.raj
Re: [VB6] - about Doevents
Frenzied Member

Also, jmsrickland responded to a post just recently with these words of wisdom:
Join Date: Jan 2009
Usually you will see DoEvents in a loop. It allows the system to take care of other things while you are in the loop. If you
don't put a DoEvent in a loop, especially a lengthy loop nothing else can take place until the loop ends. What do you think
Location: Watch
Window(Shift+f9)
Posts: 1,879 will happen if you get stuck in a loop and your loop does not have a DoEvents in it? You can't get out of the loop unless
you kill the program. So by putting a DoEvent in that loop you could add a button that will allow you to either break out of
the loop or examine what is taking place. Without the DoEvent the button or any other control is useless until the loop
ends.
So by putting a DoEvent in that loop you could add a button that will allow you to either break out of the loop or examine
what is taking place. Without the DoEvent the button or any other control is useless until the loop ends.
when i press btbreak in between finish look .it does not break .so why you say it will allow to either break out of the
loop ? . let me know some idea .
Code:
Option Explicit
Private Sub btbreak_Click()
DoEvents
End Sub

Private Sub Form_Load()


Dim x%
For x = 1 To 100000000
Print x
Next
End Sub

Last edited by firoz.raj; Nov 22nd, 2012 at 09:23 AM.


Reply With Quote

Nov 22nd, 2012, 09:40 AM #16

Bonnie West
Re: [VB6] - about Doevents
Default Member

Originally Posted by firoz.raj


let me know some idea.
Join Date: Jun 2012 Here's how to do it:
Location: InIDE
Posts: 4,057
Code:
Option Explicit

Private Break As Boolean


Private Sub btbreak_Click()
Break = True
End Sub
Private Sub Form_Activate() 'In the Load event, the Form is still hidden
Dim x As Long
For x = 1 To 100000000
Print x
DoEvents
If Break Then Exit For
Next

Last edited by Bonnie West; Nov 22nd, 2012 at 09:51 AM.


On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency:
Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo
0
My CodeBank Contributions
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

Reply With Quote

Nov 22nd, 2012, 09:51 AM #17

firoz.raj
Re: [VB6] - about Doevents
Frenzied Member
No it does not break out of the loop when press btbreak. let me know please
Join Date: Jan 2009
Code:
Location: Watch
Window(Shift+f9) Option Explicit
Posts: 1,879
Dim break As Boolean
Private Sub btbreak_Click()
break = True
End Sub

Private Sub Form_Load()


Dim x%
For x = 1 To 10000
Print x
DoEvents
If break Then Exit For
Next
End Sub

Reply With Quote

Nov 22nd, 2012, 09:58 AM #18

Bonnie West
Re: [VB6] - about Doevents
Default Member
I've just tested your code, Print x is too fast. Try something more taxing. Also, do it in the Form_Activate event so that
the Form is actually shown.

Join Date: Jun 2012


Location: InIDE
Posts: 4,057

On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency:
Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo
0
My CodeBank Contributions
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

Reply With Quote

Nov 22nd, 2012, 10:11 AM #19

firoz.raj
Re: [VB6] - about Doevents
Frenzied Member
it still the same it still does not braek while press button.
Join Date: Jan 2009
Code:
Location: Watch
Window(Shift+f9) Option Explicit
Posts: 1,879
Dim x As Long
Dim break As Boolean
Private Sub btbreak_Click()
break = True
End Sub
Private Sub Form_Activate()
For x = 1 To 1000000000
Print x
DoEvents
If break Then Exit For
Next
End Sub

Reply With Quote

Nov 22nd, 2012, 10:25 AM #20

Bonnie West
Re: [VB6] - about Doevents
Default Member Put a Beep statement after the Next keyword. If you hear it when the Form shows up, then the loop has just finished.
You never got the chance to click the button. Replace the Print x line with something more CPU-intensive.

Join Date: Jun 2012


Location: InIDE
Posts: 4,057

On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency:
Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo
0
My CodeBank Contributions
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

Reply With Quote

Nov 22nd, 2012, 10:36 AM #21

firoz.raj
Re: [VB6] - about Doevents
Frenzied Member
i tried another way round it still seems to be same .any more idea to test doevents keyword
Join Date: Jan 2009
Code:
Location: Watch
Window(Shift+f9) Option Explicit
Dim x As Long
Posts: 1,879
Dim break As Boolean
Private Sub btbreak_Click()
break = True
End Sub

Private Sub Command1_Click()


For x = 1 To 999999999
DoEvents
Print x
If break Then Exit For
Next
Beep
End Sub

Reply With Quote

Nov 22nd, 2012, 11:20 AM #22

DataMiser
Re: [VB6] - about Doevents
PowerPoster
Your code works but the way you \have written it you will not be able to tell for sure that it worked.
Join Date: Feb 2012
Location: West Virginia try this
Posts: 13,260
Code:
Option Explicit
Dim x As Long

Dim break As Boolean

Private Sub Command1_Click()


break = False
For x = 1 To 999999999
DoEvents
Print x
If break Then Exit For
Next
MsgBox x
End Sub
Private Sub Command2_Click()
break = True
End Sub

The longer you wait to press button 2 the higher the number will be as it completed more cycles before exit

Reply With Quote

Nov 23rd, 2012, 01:14 PM #23

joaquim
Re: [VB6] - about Doevents
Thread Starter
PowerPoster sorry why you use loops, if in these case it's diferent?
i understand that doevents see if theres any depend event and execute it
but why my code don't works without doevents?
because i'm simply clean the usercontrol and picturebox.
Join Date: Apr 2007
Posts: 3,358

VB6 2D Sprite control

To live is difficult, but we do it.

Reply With Quote


Nov 23rd, 2012, 01:42 PM #24

jmsrickland
Re: [VB6] - about Doevents
PowerPoster

Join Date: Jan 2008 Originally Posted by firoz.raj


Posts: 11,074 when i press btbreak in between finish look .it does not break .so why you say it will allow to either break out of
the loop ? . let me know some idea .
Code:
Option Explicit
Dim x As Long

Dim break As Boolean


Private Sub btbreak_Click()
break = True
End Sub

Private Sub Form_Activate()


For x = 1 To 1000000000
Print x
DoEvents
If break Then Exit For
Next
End Sub

Sure it breaks out of the loop. Your code works. You just didn't know it did.

Last edited by jmsrickland; Nov 24th, 2012 at 04:38 PM.

Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it
is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

Reply With Quote

Nov 23rd, 2012, 02:01 PM #25

DataMiser
Re: [VB6] - about Doevents
PowerPoster

Join Date: Feb 2012 Originally Posted by joaquim


Location: West Virginia sorry why you use loops, if in these case it's diferent?
Posts: 13,260 i understand that doevents see if theres any depend event and execute it
but why my code don't works without doevents?
because i'm simply clean the usercontrol and picturebox.
No idea what you are talking about when you say your code don't work without do events. I do not see any reason to
have doevents in that piece of code nor do I see a reason that it would slow it down any noticable amount unless of
course you have some other code somewhere that the doevent sis allowing to execute and that other code is slowing
you down.

Reply With Quote

Nov 24th, 2012, 04:12 PM #26

techgnome
Re: [VB6] - about Doevents
PowerPoster
Actually, doevents WILL slow things down...because it's releasing processing time to the REST of the system... UI
updates, other apps, other processes, etc... that's the reason why you shouldn't call DoEvents on every single iteration
in a loop... but to do it on a controlled basis, like I explained in post #7... if you want your code to run fast, dump the
DoEvents... if you want the UI to be responsive, then you need the DoEvents... you can't have both in their purest
forms though... you'll need to find the right combination of how often it gets called and performance, which will only
Join Date: May 2002 come with experimentation.
Posts: 32,904
-tg

* I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
* I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
* How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
* How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my
data, where'd it run off to??? *

Reply With Quote

Nov 24th, 2012, 05:18 PM #27

DataMiser
Re: [VB6] - about Doevents
PowerPoster
Actually do events can slow things down, but in the case mentioned there is no loop, there is only one call to do events
Join Date: Feb 2012 so 99.9% likely that it would be completely unnoticed in terms of program speed. Only if there happens to be some
Location: West Virginia pending event that takes a noticable amount of time at the point where the do events is called would there be any
Posts: 13,260
detectable slow down.

Edit: Looks like the piece of code I am referring to has been removed, but there was just some graphics calls in a
routine with a single do events an no loop so that is why I say it should nto slow things down, but the OP also said that
his code did not work without the doevents so I have no idea why this would be or how he was able to tell that it was
slower with it since it did not work without it. Sounds like the info is a bit less than accurate.

Edit2: Opps I was mistaken abotu it being removed I was looking at the wrong post for it. The OP posted code where
there is a call to API_DoEvents in the first block of code post #5 and it is not in a loop. I assume this is where he is
talking about.

Last edited by DataMiser; Nov 24th, 2012 at 05:25 PM.


Reply With Quote

Nov 27th, 2012, 03:02 AM #28

Ben321
Re: [VB6] - about Doevents
Fanatic Member
Also, DoEvents is ABSOLUTELY NECESSARY in computer games. The game's loop needs to keep running to keep
Join Date: Oct 2008 updating the NPCs (nonplayable characters) to make them run around on the screen or whatever they do, but it needs
Posts: 1,013 to yield control to other events (such as your keyboard key presses) so you can can control the player's character.

Reply With Quote

Nov 27th, 2012, 09:00 AM #29

DataMiser
Re: [VB6] - about Doevents
PowerPoster

Join Date: Feb 2012 Also, DoEvents is ABSOLUTELY NECESSARY in computer games
Location: West Virginia
Posts: 13,260
That is just not true, a timer can and should be used rather than a busy loop with doevents.

Reply With Quote

Dec 1st, 2012, 05:19 AM #30

Ben321
Re: [VB6] - about Doevents
Fanatic Member

Join Date: Oct 2008 Originally Posted by DataMiser


Posts: 1,013 That is just not true, a timer can and should be used rather than a busy loop with doevents.
Actually the Timer object isn't very precise when running faster than about 100ms per tick. To update the screen at the
normal NTSC speed would need 33ms per frame. At this rate, with the Timer object motion will look jerky, as if the
computer does something in the background (such as the bringing up of the task bar when the mouse goes to the
bottom of the screen, or even completely background tasks like wrighting whatever stuff gets writtend to the harddrive
in the background but doesn't normally effect most programs that aren't CPU intensive like video games) will "distract"
the computer enough that the Timer will maybe take 50 to 100ms on that one itteration, making the game appear to
briefly freeze during those few extra milliseconds.

The ultimate result is that using a timer configured to any speed faster than 100ms per tick will be unreliable and
produce jerky motion.

Better technique is to use a Do Loop which really ties up the CPU, such that it won't get "distracted" doing "background
tasks". Then to sync the graphics to the display's built in screen refresh speed (30fps) you put the line Sleep 33 (which
is an API call set to delay the game's computing the next frame for the duration of one screen refresh period) just
before the line that says Loop.

Then in any part of the game's main loop that needs input, add a DoEvents, followed by a series of GetKeyState
(another API call) lines to get the keys needed at that point in the game. This way the CPU is only allowed to be
bothered with accepting input (events) at very specific points in the cycle of the Loop.

With timer though it is as if it is ALWAYS in a DoEvents state, ALWAYS willing to let the CPU be distracted by other
inputs, making the game's frame timing very unreliable. Do NOT USE TIMER with computer games, unless you want
the game to have very crappy graphics.

Reply With Quote

Dec 1st, 2012, 06:36 AM #31

DataMiser
Re: [VB6] - about Doevents
PowerPoster
I totally disagree. A busy loop is not the way to go.
Join Date: Feb 2012
Location: West Virginia Then again VB6 is the wrong tool for game programming that requires fuild graphics.
Posts: 13,260
btw I am well aware of the limitations of the timer control

Reply With Quote


Dec 1st, 2012, 02:32 PM #32

firoz.raj
Re: [VB6] - about Doevents
Frenzied Member
i did not see any difference between the following shots of code .
Join Date: Jan 2009 i have been using 64 bit microprocessor .
Location: Watch
Window(Shift+f9)
Posts: 1,879
Code:
For a as integer = 1 to 10000
if a mod 100 = 0 then
form1.print a
doevents
end if
next
This

and the following .


Code:
For a as integer = 1 to 10000
if a mod 100 = 0 then
form1.print a
end if
next

Last edited by firoz.raj; Dec 1st, 2012 at 02:46 PM.


Reply With Quote

Dec 1st, 2012, 02:38 PM #33

joaquim
Re: [VB6] - about Doevents
Thread Starter
PowerPoster i'm sorry, i build these thread and i need some advices
thinking on these:
1 - clear the usercontrol;
2 - by some reason the usercontrol isn't clean, then i must use the 'doevents';
Join Date: Apr 2007 3 - copy the container image(include controls) with GetDC() and Bitblt() API functions;
Posts: 3,358 4 - combine the 2 images for make the Opacity and show the result in usercontrol.

why, in these case, i need the 'doevents' for clean the usercontrol?

VB6 2D Sprite control

To live is difficult, but we do it.

Reply With Quote

Dec 1st, 2012, 02:56 PM #34

joaquim
Re: [VB6] - about Doevents
Thread Starter
PowerPoster
Originally Posted by DataMiser
I totally disagree. A busy loop is not the way to go.
Join Date: Apr 2007 Then again VB6 is the wrong tool for game programming that requires fuild graphics.
Posts: 3,358
btw I am well aware of the limitations of the timer control
"Then again VB6 is the wrong tool for game programming that requires fuild graphics."
depends if you use directx ou API graphics functions

"btw I am well aware of the limitations of the timer control"


using API functions i build 1 timer(control) with 10ms of precision
but unfortely i didn't, for now, with 1ms of precision

VB6 2D Sprite control

To live is difficult, but we do it.

Reply With Quote

Dec 3rd, 2012, 07:17 AM #35

joaquim
Re: [VB6] - about Doevents
Thread Starter heres the sample project: http://depositfiles.com/files/5ijt993id
PowerPoster please someone test it and tell something.
thanks

Join Date: Apr 2007


Posts: 3,358

VB6 2D Sprite control

To live is difficult, but we do it.

Reply With Quote

Quick Navigation Visual Basic 6 and Earlier Top

« Previous Thread | Next Thread »

VBForums Visual Basic Visual Basic 6 and Earlier [VB6] - about Doevents

Posting Permissions
You may not post new threads BB code is On
You may not post replies Smilies are On
You may not post attachments [IMG] code is On
You may not edit your posts [VIDEO] code is On
HTML code is Off
Forum Rules

Contact Us VB Forums Top

Terms of Service | About Us | Privacy Notice | Contact Us | Advertise | California - Do Not Sell My Info
Copyright 2020 TechnologyAdvice. All Rights Reserved.

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact
how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products
available in the marketplace.
All times are GMT -5. The time now is 10:59 AM.

Das könnte Ihnen auch gefallen