Valhalla Legends Forums Archive | Visual Basic Programming | Queue Problem

AuthorMessageTime
Yegg
I've been having a problem with RunTime Error 6, Overflow, in the code for my queue (Groks requried delay). Here is the code,
[code]Private Declare Function GetTickCount Lib "kernel32" () As Long
Public Delay As IntegerPrivate Function RequiredDelay(ByVal Bytes As Long) As Long
Static LastTick As Long
Static SentBytes As Long
Const PerPacket = 200
Const PerByte = 10
Const MaxBytes = 600
Dim Tick As Long
Tick = GetTickCount()
If (LastTick - Tick) > (SentBytes * PerByte) Then
    SentBytes = 0
Else
    SentBytes = SentBytes - (LastTick - Tick) / PerByte
End If
LastTick = Tick
If (SentBytes + PerPacket + Bytes) > MaxBytes Then
    Delay = (SentBytes + PerPacket + Bytes - MaxBytes) * PerByte
Else
    SentBytes = SentBytes + PerPacket + Bytes
    Delay = 0
End If
End FunctionPublic Sub QSend(data As String)
Dim myMsg As String, msDelay As Integer
myMsg = data
If Len(myMsg) = 0 Then
Exit Sub
End If
RequiredDelay Len(myMsg)
msDelay = Delay
If msDelay = 0 Then
modSend.Chat myMsg
Else
Pause.Pause msDelay
modSend.Chat myMsg
End If
End Sub[/code]
If I'm doing something else wrong, please tell me.
Note: The overflow error is caused by trying to send a message to battle.net.
February 16, 2005, 8:43 PM
UserLoser.
[quote author=Yegg link=topic=10585.msg100023#msg100023 date=1108586622]
Note: The overflow error is caused by trying to send a message to battle.net.
[/quote]

No.  It's because you're telling it to put a big number into a variable which cannot hold that large of a number
February 16, 2005, 9:39 PM
Grok
RequiredDelay is a FUNCTION that returns to you the number of milliseconds you should delay.  It does not do the delay itself. So calling
[code]RequiredDelay Len(myMsg)[/code]
does nothing but compute the required delay, and you are ignoring the return value.

Now here it looks like you are using a modified version, one that uses a global stuck into RequiredDelay in order to get that value.  Bad practice!  The function was nice as it was before.

What is this?
[code]Pause.Pause msDelay[/code]
Looks like you're trying to do a delay for some time lapse but you don't show the code for your Pause object's Pause method.

Finally, on what line of code is giving the Error 6 ?
February 16, 2005, 9:40 PM
Grok
[quote author=UserLoser link=topic=10585.msg100034#msg100034 date=1108589959]
[quote author=Yegg link=topic=10585.msg100023#msg100023 date=1108586622]
Note: The overflow error is caused by trying to send a message to battle.net.
[/quote]

No.  It's because you're telling it to put a big number into a variable which cannot hold that large of a number
[/quote]

Yes exactly.  And now looking at it, and your complaint about sending to battle.net, I know where.
[code]Public Delay As Integer[/code]
A VB Integer type holds values from -32768 to 32767, and since you are storing milliseconds, when the required delay is computed to be greater than 32.768 seconds, you are forcing an overflow condition.  With Blizzard's anti-flood algorithm, a required delay of 32 seconds is quite possible.
February 16, 2005, 9:44 PM
KkBlazekK
Your tab key is getting neglected.
February 16, 2005, 10:52 PM
Networks
FOR GOD SAKE DO NOT USE PAUSE. NEVER USE PAUSE. PAUSE IS GAY! IF YOU MUST USE PAUSE LEARN MORE VB6 AND DELETE PAUSE SUB! That's all I can say, pause creates more problems than it solves. Use a timer and Gettickcount() as your friends. There's ALWAYS another alternative to pause, use it.

And Use your freakin TAB KEY! It makes it so easy to see what you've copy and pasted and what you've written...plus it makes your code look like shit.
February 17, 2005, 1:28 AM
^
[quote author=Networks link=topic=10585.msg100087#msg100087 date=1108603733]
And Use your freakin TAB KEY! It makes it so easy to see what you've copy and pasted and what you've written...plus it makes your code look like shit.

[/quote]


Just looking at his code, does that mean basically all of hes code is copy and pasted? :P
February 17, 2005, 8:10 PM
JoeTheOdd
Heres you're new freekin pause sub.

[code]Public Sub Pause(lSeconds as Long)
    lTickCount = GetTickCount()
    While GetTickCount > lTickCount + CLng(CStr(lSeconds) & "000")
        Sleep 100
    Wend
End Sub[/code]

EDIT: In order to answer your problem, use a Double instead of an Integer. Double = freekin HUGE.
February 18, 2005, 1:08 AM
CrAz3D
Is a double over doing it though?  Isn't gettickcount a long?  So why would you store it in a double?
February 18, 2005, 6:55 AM
Stealth
[quote author=JoeTheOdd link=topic=10585.msg100286#msg100286 date=1108688886]
[code] CLng(CStr(lSeconds) & "000")[/code]
[/quote]

Clng(Cstr())?! What a waste of processor time.

lSeconds = lSeconds * 1000, thank you very much. Why do all these people insist on treating numbers as strings when they are not?
February 19, 2005, 5:33 PM
UserLoser.
[quote author=JoeTheOdd link=topic=10585.msg100286#msg100286 date=1108688886]
[code]Public Sub Pause(lSeconds as Long)
    lTickCount = GetTickCount()
    While GetTickCount > lTickCount + CLng(CStr(lSeconds) & "000")
        Sleep 100
    Wend
End Sub[/code]
[/quote]

horrible.  sleep blocks main thread, everything freezes, bad bad bad
February 19, 2005, 5:35 PM
Quarantine
[quote author=Stealth link=topic=10585.msg100530#msg100530 date=1108834383]
Why do all these people insist on treating numbers as strings when they are not?
[/quote]

Anything that doesn't error they assume is good coding.
February 19, 2005, 6:20 PM
R.a.B.B.i.T
Note to newbies: anything that doesn't error is just working, not good.
February 19, 2005, 7:53 PM
KkBlazekK
Why not just do this?

[code]
    lTickCount = GetTickCount()
    While GetTickCount > lTickCount + CLng(CStr(lSeconds) & "000")
        DoEvents
    Wend
    'Send the message here.
[/code]
February 20, 2005, 7:09 PM
UserLoser.
For what reason has nobody posted the suggestion of using a timer?
February 20, 2005, 7:40 PM
KkBlazekK
You could have told him, you were the first one to post...

Edit: After thinking about it, this shouldn't have made it this far, it should have ended quickly, so never mind userloser.
February 20, 2005, 7:48 PM

Search