|
-
Dec 29th, 2005, 01:24 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] What comes after Long?
I am working on a bandwidth meter and my bytes sent/received overflow long type. I tried currency but all the numbers are negative.
-
Dec 29th, 2005, 01:26 PM
#2
Re: What comes after Long?
Try Double or Single
Double is 8 byte floating point number which covers the range of -1.79E+308 to 1.79E+308
Single is a 4 byte floating point number which covers the range of -3.40E38 to 3.40E38
-
Dec 29th, 2005, 01:28 PM
#3
Re: What comes after Long?
 Originally Posted by frozen
... I tried currency but all the numbers are negative.
Can you show us how you did it?
-
Dec 29th, 2005, 01:28 PM
#4
Re: What comes after Long?
Single is also 4 byte, and goes to ~ +- 10^38
zaza
EDIT: Rats. Hacked!
-
Dec 29th, 2005, 01:40 PM
#5
Thread Starter
Hyperactive Member
Re: What comes after Long?
Well so far double seems to be working.
In a nut shell I have
VB Code:
Private BytesReceived As Double
Private BytesSent As Double
Private Sub Timer1_Timer()
If BytesReceived = 0 And BytesSent = 0 Then
BytesReceived = IpHelper.BytesReceived
BytesSent = IpHelper.BytesSent
Exit Sub
End If
Download = IpHelper.BytesReceived - BytesReceived
Upload = IpHelper.BytesSent - BytesSent
End Sub
-
Dec 29th, 2005, 01:51 PM
#6
Re: What comes after Long?
 Originally Posted by frozen
I am working on a bandwidth meter and my bytes sent/received overflow long type. I tried currency but all the numbers are negative.
Can't you just trap the overflow error and then switch to KB, then MB, then GB? Make a global variable to store the mode you are keeping track in, and then divide the bytes by the current mode amount when you update. Something like (a more sophisticated version of) this:
VB Code:
Private lDivisor As Long 'Holds the current "mode"
Private lTotal As Long 'Holds the amount of data denominated by the "mode"
Public Sub AddBytes(lBytes As Long)
On Error GoTo OverFlowCheck
If lDivisor Then lBytes = lBytes \ lDivisor
lTotal = lTotal + lBytes 'NOTE: this is the only possible overflow in the sub.
OverFlowCheck:
If Err.Number = 6 Then 'Overflow
If lDivisor Then
lDivisor = lDivisor * 1024
Else
lDivisor = 1024
End If
lTotal = (lTotal \ lDivisor) + (lBytes \ lDivisor)
End If
End Sub
Private Function DisplayAs() As String 'Returns a string to append on the end of your display.
Dim lTemp As Long
lTemp = lDivisor \ 1024
Select Case lTemp
Case 0
DisplayAs = "Bytes"
Case 1
DisplayAs = "KB"
Case 2
DisplayAs = "MB"
Case 3
DisplayAs = "GB"
Case 4
DisplayAs = "TB" 'If you get here, I want your connection :P
End Select
End Function
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
|