Console.Write to TextBox
-
Hello In the below code I found on the internet I would like to use in a vb app and have the result in a multi line text box but I Console.Write line gives me an error. I Tryed
Textbox1.Text = ("IP Address {0}: {1} ", i, IpA(i).ToString)& VbCrlf
Any thoughts? If there is better code out there that might also get subnet and gateway that would be great. Thanks Heaps'To get local address Dim sHostName As String Dim i As Integer sHostName = Dns.GetHostName() Dim ipE As IPHostEntry = Dns.GetHostByName(sHostName) Dim IpA() As IPAddress = ipE.AddressList For i = 0 To IpA.GetUpperBound(0) Console.Write("IP Address {0}: {1} ", i, IpA(i).ToString) Next
When people make you see red, be thankful your not colour blind.
-
Hello In the below code I found on the internet I would like to use in a vb app and have the result in a multi line text box but I Console.Write line gives me an error. I Tryed
Textbox1.Text = ("IP Address {0}: {1} ", i, IpA(i).ToString)& VbCrlf
Any thoughts? If there is better code out there that might also get subnet and gateway that would be great. Thanks Heaps'To get local address Dim sHostName As String Dim i As Integer sHostName = Dns.GetHostName() Dim ipE As IPHostEntry = Dns.GetHostByName(sHostName) Dim IpA() As IPAddress = ipE.AddressList For i = 0 To IpA.GetUpperBound(0) Console.Write("IP Address {0}: {1} ", i, IpA(i).ToString) Next
When people make you see red, be thankful your not colour blind.
It would have been a lot helpful if you had mentioned anything about what kind of error you get. The call to Console.Write uses formatting, so you have to use String.Format when you want to do the same:
Textbox1.Text = String.Format("IP Address {0}: {1} ", i, IpA(i).ToString) & VbCrlf
--- b { font-weight: normal; }
-
Hello In the below code I found on the internet I would like to use in a vb app and have the result in a multi line text box but I Console.Write line gives me an error. I Tryed
Textbox1.Text = ("IP Address {0}: {1} ", i, IpA(i).ToString)& VbCrlf
Any thoughts? If there is better code out there that might also get subnet and gateway that would be great. Thanks Heaps'To get local address Dim sHostName As String Dim i As Integer sHostName = Dns.GetHostName() Dim ipE As IPHostEntry = Dns.GetHostByName(sHostName) Dim IpA() As IPAddress = ipE.AddressList For i = 0 To IpA.GetUpperBound(0) Console.Write("IP Address {0}: {1} ", i, IpA(i).ToString) Next
When people make you see red, be thankful your not colour blind.
japel wrote:
Any thoughts?
First, if you get an error, tell us what it is.
japel wrote:
Textbox1.Text = ("IP Address {0}: {1} ", i, IpA(i).ToString)& VbCrlf
That's never going to work. Console.Write obviously has an overload to take a formatted string. Textbox1.Text = string.Format(
"IP Address {0}: {1} ", i, IpA(i).ToString) Will put one IP address in there. Use a string builder to build a string of multiple addresses and set that to the textbox text, using string.Format as I have done. Overall, I suggest instead of looking for code on the web, you work through a book and learn some basic programming. A basic understannding of VB.NET would have made clear to you what was happening here, that you can't format a string that way, without calling a format method ( as Console.WriteLine is doing ).
Christian Graus - C++ MVP