• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 464
  • Last Modified:

Bytes Sent

How do I access the Bytes Sent/Received for a session?

I would like to be able to place this information in a label on a form window.
  • 6
  • 4
1 Solution
I don't think either inet control or winsock control keeps track.  You'll have to make a variable for each, add the count as the files xfer, then update your label in a timer control (say every 100 ms for the timer.interval property.)

For example:

Public lBytesSent as long
Public lBytesRec as long

Public Timer1_Timer()
   labelSent.Caption = Format(lBytesSent) & " bytes sent"
   labelRec.Caption = Format(lBytesRec) & " bytes received"
   'next 2 lines optional
End Sub

Public GetFile(strURL as string)
'assuming your using inet control
Dim myString as String
  inet1.URL = strURL
  myString = Inet1.OpenURL
  lBytesRec = lBytesRec + Len(myString)
End Sub
'need similar subroutine for sending file
cMhAuthor Commented:
The amount tracked would be the values shown in the connection box in windows (the one that appears when you connect to the internet via a modem next to the clock).

My program doesn't actually download anything so tracking an Inet/Winsock control wouldn't work I don't think.

Any other ideas?
Hmmm, even if you haven't told it to download a file, you are still downloading even if you are simply viewing a web-page.  For example, on one web page you would be downloading the html file and any pictures, audio or video on the page even though they may only be stored temporarily.

I don't know how to access the actual numbers from the dialup networking icon in the system tray.  If all you want is a window that shows those numbers, why not simply right-click the icon and select "Status"; this will show a window with the bytes transferred, duration and speed of the connection.  Otherwise, you would probably have to find the thread for the internet connection and hope it uses a Public variable that other apps can read.  I would guess that microsoft would NOT make the variables public simply so other apps don't change the value.

This site has a shareware utility that does what you want (and more.)

If you still want to create your own program, I suggest using a winsock control with a callback subroutine, your callback sub will be activated when anything is received on the selected port and you can check the buffer to see how many bytes have been received.  I could probably round up some example links for that.

Are you using a webbrowser control in your program or do you want this to work for any internet transfer?
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

cMhAuthor Commented:
I am aware that this would monitor all transfers including web pages... this is what I would like.

Clicking on the icon is an option but being lazy I would like it to just be updated in the window I am working in (in other words my program window)...

I am interested by the callback option.  Can you see if you can find anything here?  I have looked but can't find anything.

Basically all I want to do is display the details from the DUN icon to a label in my program.
OK, don't worry about using winsock, (but if you are still interested see the bottom of this post...)

I found a related question with code here:
Originally posted at http://www.mvps.org/vbnet/
I think it is from the "FTP: Downloading Files via FTP with Progress Display Callback" page.

The code is a little long, but I think it should do what you want.  Be sure to let me know if this works for you.

more about winsock:

(the callback routine I mentioned is the Winsock1_DataArrival event, however I beleive you will have to initiate the connection with the winsock control and assign a socket, then it will only receive data from that socket - basically you would have to handle all the data with your program which sounds like more than you really need to do.)

'DataArrival event example:
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim DataRecvd as String
    Debug.Print "DataArrival"
    'Recieve the data
    Winsock1.GetData DataRecvd
    Debug.Print "recieved data ="; DataRecvd
    Debut.Print "bytes received =" & Format(bytesTotal)
    'Do something with the data
End Sub

I recommend viewing http://www.vbip.com for more examples/info on using the winsock control, or see the mvps site mentioned above.
cMhAuthor Commented:
Thanks again for your help J-Man but this example seems to be just if you wanted to download via FTP.  It is essentially a download manager.

All I really want is to have the Bytes Sent/Received from the DUN icon placed on a label in my program.

Any other ideas?
OK, one more strategy.  See the page below and download the source code from the link at the top labeled "Download Interfaces Info project".


This program uses the GetIFTable function that you can learn more about here:

When I ran this program, I got an overflow, but it is easy to fix.  The line in CipHelper class that reads:
objInterface.LastChange = .dwLastChange
should be changed to:
objInterface.LastChange = Len(.dwLastChange)

Also, I should remind you that you need to select the correct interface, usually PPP/SLIP interface for dial-up modem.  You can probably do without the combobox and just tell it which adapter/interface to use programatically.

The info you want (bytes sent, bytes received) are in labels at the bottom of the form which differs from the DUN numbers by about 10% (probably due to either packet headers or retransmissions).  I believe the numbers are stored in the variables m_lngBytesReceived and m_lngBytesSent.

You will have to do a lot of cutting and pasting into your program unless you simply add the class files to your program.  You can certainly trim out a lot, but be careful or you will have a lot of debugging to do.  I think you also must have dial-up networking version 1.3 installed.

This should finally be the accepted answer.  ;-)
cMhAuthor Commented:
This isn't correct either as this value shows the total amount downloaded since the computer was switched on and not in the session like I need.  Incidentally I think there is a much simpler way of getting the "total since the computer was switched on value"...

I can't believe moving those numbers from the DUN to my program is so difficult but I have been unable to trak down how it is done as well!
It is correct (my last post).

If you want only the data for the session, then put a commandbutton on your form called "Reset" and click it before you dial, or make a Reset sub and call this upon loading your form then shell the DUN.

Public OldValueSent As Long
Public OldValueRec As Long
Public SessionSent As Long
Public SessionRec As Long

Private Sub Reset_Click()
    OldValueSent = m_lngBytesSent
    OldValueRec = m_lngBytesReceived
End Sub

Private Sub UpdateLabel()
    SessionSent = m_lngBytesSent - OldValueSent
    SessionRec = m_lngBytesReceived - OldValueRec
    MyLabelSent.Caption = Format(SessionSent)
    MyLabelRec.Caption = Format(SessionRec)
End Sub
Hi cMh,
It appears that you have forgotten to close this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept J-Man's comment(s) as an answer.

cMh, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept THIS comment as an answer.
DanRollins -- EE database cleanup volunteer
My last 2 comments work the best.  I have tested the code (with noted change in line 6 of second to last comment.)

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now