2013-04-25 90 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)