2013-04-25 65 views
0

有人可以幫助我將其轉換爲vb.net 2010代碼。我有一個具有TextBox1中的窗口,我發現這個代碼BT cldnt圖浩,我可以在vb.net寫2010將傳統的vb轉換爲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 
+0

這已經是* * VB.Net,它的不是傳統的VB。 – RBarryYoung 2013-04-25 20:21:00

+0

附註:'Console.WriteLine'中的'String.Format'是多餘的。它支持已經[**複合格式化**](http://msdn.microsoft.com/en-us/library/txafckwd(v = vs.110).aspx)。 – 2013-04-25 20:25:20

回答

0

它看起來像一個控制檯應用程序,

你可能用的掙扎如何將數據存入您的文本框? 在你的示例中,它正在寫入控制檯窗口。

只需更改THESE行,你應該沒問題。

Console.WriteLine("Monitoring " & instance) 

更改上面:

Texbox1.text = "Monitoring " & instance & vbcrlf 

也會改變該行

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

將其更改爲:

Textbox1.Text = Textbox1.Text & String.Format("Bytes Sent {0}k, Bytes Received {1}k", kbSent, kbReceived)