0

Can someone help me to convert this to vb.net 2010 code. I have a window that has textbox1, i found this code bt cldnt figure ho i can write it in vb.net 2010

Imports System.Diagnostics

Module Module1
    Sub Main()
        Dim pc As New PerformanceCounterCategory("Network Interface")
        Dim instance As String = pc.GetInstanceNames(0)
        Dim bs As New PerformanceCounter("Network Interface", "Bytes Sent/sec", instance)
        Dim br As New PerformanceCounter("Network Interface", "Bytes Received/sec", instance)
        Console.WriteLine("Monitoring " & instance)
        Do
            Dim kbSent As Integer = bs.NextValue() / 1024
            Dim kbReceived As Integer = br.NextValue() / 1024
            Console.WriteLine(String.Format("Bytes Sent {0}k Bytes Received {1}k", kbSent, kbReceived))
            Threading.Thread.Sleep(1000)
        Loop
    End Sub
End Module
Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250
  • This already *is* VB.Net, it's not tradtional VB at al. – RBarryYoung Apr 25 '13 at 20:21
  • Side-note: `String.Format` in `Console.WriteLine` is redundant. It supports already [**composite formatting**](http://msdn.microsoft.com/en-us/library/txafckwd(v=vs.110).aspx). – Tim Schmelter Apr 25 '13 at 20:25

1 Answers1

0

It looks like a console app,

What you may be struggling with is how to get the data into your textbox? Where-as in your sample it was being written to the console window.

Simply change THESE lines and you should be fine.

Console.WriteLine("Monitoring " & instance)

Change the above for:

Texbox1.text = "Monitoring " & instance & vbcrlf

Also change this line

Console.WriteLine(String.Format("Bytes Sent {0}k Bytes Received {1}k", kbSent, kbReceived))

change it to:

Textbox1.Text = Textbox1.Text & String.Format("Bytes Sent {0}k, Bytes Received {1}k", kbSent, kbReceived)
Zeddy
  • 2,079
  • 1
  • 15
  • 23