• Welcome to Valhalla Legends Archive.
 

Queue Problem

Started by Yegg, February 16, 2005, 02:43 PM

Previous topic - Next topic

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,
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

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.

UserLoser.

Quote from: Yegg on February 16, 2005, 02:43 PM
Note: The overflow error is caused by trying to send a message to battle.net.

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

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
RequiredDelay Len(myMsg)
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?
Pause.Pause msDelay
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 ?

Grok

Quote from: UserLoser on February 16, 2005, 03:39 PM
Quote from: Yegg on February 16, 2005, 02:43 PM
Note: The overflow error is caused by trying to send a message to battle.net.

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

Yes exactly.  And now looking at it, and your complaint about sending to battle.net, I know where.
Public Delay As Integer
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.

Blaze

Your tab key is getting neglected.
Quote
Mitosis: Haha, Im great arent I!
hismajesty[yL]: No

Networks

#5
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.

^

Quote from: Networks on February 16, 2005, 07:28 PM
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.



Just looking at his code, does that mean basically all of hes code is copy and pasted? :P

Joe[x86]

Heres you're new freekin pause sub.

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


EDIT: In order to answer your problem, use a Double instead of an Integer. Double = freekin HUGE.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

CrAz3D

Is a double over doing it though?  Isn't gettickcount a long?  So why would you store it in a double?
rebundance - having or being in excess of sheer stupidity
(ré-bun-dance)
Quote from: Spht on June 22, 2004, 07:32 PMSlap.
Quote from: Adron on January 28, 2005, 09:17 AMIn a way, I believe that religion is inherently evil, which includes Christianity. I'd also say Christianity is eviller than Buddhism (has more potential for evil).
Quote from: iago on April 19, 2005, 01:06 PM
CrAz3D's ... is too big vertically, at least, too big with ... iago ...

Stealth

Quote from: JoeTheOdd on February 17, 2005, 07:08 PM
CLng(CStr(lSeconds) & "000")

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?
- Stealth
Author of StealthBot

UserLoser.

Quote from: JoeTheOdd on February 17, 2005, 07:08 PM
Public Sub Pause(lSeconds as Long)
    lTickCount = GetTickCount()
    While GetTickCount > lTickCount + CLng(CStr(lSeconds) & "000")
        Sleep 100
    Wend
End Sub


horrible.  sleep blocks main thread, everything freezes, bad bad bad

Warrior

Quote from: Stealth on February 19, 2005, 11:33 AM
Why do all these people insist on treating numbers as strings when they are not?

Anything that doesn't error they assume is good coding.
Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?

R.a.B.B.i.T

Note to newbies: anything that doesn't error is just working, not good.

Blaze

Why not just do this?


    lTickCount = GetTickCount()
    While GetTickCount > lTickCount + CLng(CStr(lSeconds) & "000")
        DoEvents
    Wend
     'Send the message here.
Quote
Mitosis: Haha, Im great arent I!
hismajesty[yL]: No

UserLoser.

For what reason has nobody posted the suggestion of using a timer?