# Visual Basic - out of order

This topic is 4211 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hi i was creating a simple program last night that simply draws to the screen and displays how long it took however i noticed while it was drawing the program recorded the time it took (it beeped) then when it finished drawing it displayed the time i did a few tests and prooved it was doing this since i let it draw a large amount of objects that took a couple of seconds where it said it only took 500ms i figured it was just a memory issue so i turned the pc off and thought i'd try again tommorow and im still having that problem it seems to only do it with bitblt any ideas? heres the code
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
Dim done As Boolean
Dim done2 As Boolean
Private Sub Command1_Click()
's = GetTickCount
MsgBox "a"
draw2
MsgBox "b"
'e = GetTickCount
End Sub
Private Sub draw2()
Dim xx As Long
Dim yy As Long
For vv = 1 To 30
Form1.Cls
For xx = 1 To 1000
g = 10 + (500 * Rnd)
g2 = 10 + (500 * Rnd)
BitBlt Form1.hdc, g, g2, 100 * Rnd, 79, 79, Picture2.hdc, 0, 0, vbSrcAnd
BitBlt Form1.hdc, g, g2, 79, 79, Picture1.hdc, 0, 0, vbSrcPaint
Next xx
Form1.Refresh
DoEvents
Next vv
End Sub
i can also provide the image used if neccesary when you run the program you will hear it beep before the drawing is complete well on my pc anyway

##### Share on other sites
Sorry just noticed this is the wrong forum could a moderator/admin move this to General Programming? Ty.

##### Share on other sites
Moved to General Programming.

##### Share on other sites
Well its been awhile since I did any VB programming, but here's what might be your problem. I used like VB-4 or something (not anywhere near the modern versions - what is it, v 10?).

Check your randomization part. Shouldn't you have the tag "Randomize" before the statement to declare you are randomizing? That's how I used to do it.

Or perhaps its your loop statement. Your saying "For something = 1 to 1000." It loops only 1000 times. Perhaps you could use a Do Until or Do While loop?

Just my thoughts on this subject. Sorry if I'm wrong its been awhile.

##### Share on other sites
hi thanks for the reply however i just did a bit of trial and error hoping to narrow down the problem

and the problem is BitBlt it seems to be causing problems with the tick timer and the high resolution timers

i had a standard vb timer running at 1,000 ms to capture the FPS and as i watching the label update it would skip sometimes and yeah shouldnt upload that fast if theres a 1 second interval so im not sure why its doing it but its definetly bitblt nothing else does it

bump

##### Share on other sites
The built in VB timers are not good, they only have a resolution of about 60-70 ticks per second. even if you give an interval of 1 the timer will never actually make it.
You should either use loops with GetTickCount which will be inaccurate, or use API timers.

As for measuring the time, this works fine on my system:

Private Sub Command1_Click()
MsgBox "Start"
t = GetTickCount
draw2
MsgBox "Took: " & GetTickCount - t & "ms"
End Sub

##### Share on other sites
Quote:
 Original post by TheShauThe built in VB timers are not good, they only have a resolution of about 60-70 ticks per second. even if you give an interval of 1 the timer will never actually make it.You should either use loops with GetTickCount which will be inaccurate, or use API timers.As for measuring the time, this works fine on my system:Private Sub Command1_Click()MsgBox "Start"t = GetTickCountdraw2MsgBox "Took: " & GetTickCount - t & "ms"End Sub

yes however i've tried every possible timing system i could think of

VB controls Timer
GetTickCount
QueryPerformanceCounter

etc only skips with bitblt but i havn't tried in a while maybe its fixed its self ^_^

bump