Results 1 to 6 of 6

Thread: [RESOLVED] What comes after Long?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    294

    Resolved [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.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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

  3. #3

  4. #4
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: What comes after Long?

    Single is also 4 byte, and goes to ~ +- 10^38

    zaza



    EDIT: Rats. Hacked!

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2005
    Posts
    294

    Re: What comes after Long?

    Well so far double seems to be working.

    In a nut shell I have
    VB Code:
    1. Private BytesReceived As Double
    2. Private BytesSent As Double
    3. Private Sub Timer1_Timer()
    4.     If BytesReceived = 0 And BytesSent = 0 Then
    5.         BytesReceived = IpHelper.BytesReceived
    6.         BytesSent =  IpHelper.BytesSent
    7.         Exit Sub
    8.     End If
    9.     Download = IpHelper.BytesReceived - BytesReceived
    10.     Upload = IpHelper.BytesSent - BytesSent
    11. End Sub

  6. #6
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Post Re: What comes after Long?

    Quote 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:
    1. Private lDivisor As Long      'Holds the current "mode"
    2. Private lTotal As Long      'Holds the amount of data denominated by the "mode"
    3.  
    4. Public Sub AddBytes(lBytes As Long)
    5.  
    6.     On Error GoTo OverFlowCheck
    7.    
    8.     If lDivisor Then lBytes = lBytes \ lDivisor
    9.    
    10.     lTotal = lTotal + lBytes      'NOTE:  this is the only possible overflow in the sub.
    11.    
    12. OverFlowCheck:
    13.     If Err.Number = 6 Then     'Overflow
    14.         If lDivisor Then
    15.             lDivisor = lDivisor * 1024
    16.         Else
    17.             lDivisor = 1024
    18.         End If
    19.         lTotal = (lTotal \ lDivisor) + (lBytes \ lDivisor)
    20.     End If
    21.    
    22. End Sub
    23.  
    24. Private Function DisplayAs() As String     'Returns a string to append on the end of your display.
    25.  
    26.     Dim lTemp As Long
    27.    
    28.     lTemp = lDivisor \ 1024
    29.     Select Case lTemp
    30.         Case 0
    31.             DisplayAs = "Bytes"
    32.         Case 1
    33.             DisplayAs = "KB"
    34.         Case 2
    35.             DisplayAs = "MB"
    36.         Case 3
    37.             DisplayAs = "GB"
    38.         Case 4
    39.             DisplayAs = "TB"        'If you get here, I want your connection  :P
    40.     End Select
    41.  
    42. 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
  •  



Click Here to Expand Forum to Full Width