converting from a string to an ip address
-
Wednesday, March 14, 2007 2:14 AMhow would i go from a string to an ip address:
Dim ipadd As Net.IPAddress
'i cant do this part
ipadd = console.readline
'the console.readline is by default a string
how would i do this?
All Replies
-
Wednesday, March 14, 2007 5:53 AM
Using the parse method.
Something like
Dim s as string = "1.2.3.4"
Dim hostIPAddress As System.Net.IPAddress = System.Net.IPAddress.Parse(s) -
Wednesday, March 14, 2007 6:00 AMsame error:
Error 1 Value of type 'System.Net.IPAddress' cannot be converted to 'String'. -
Wednesday, March 14, 2007 1:33 PMi dont know why it says it cant go from an ipadd to a string....im not trying to do that
it is the other way -
Wednesday, March 14, 2007 2:58 PM
use spottys code with yours
Dim hostIPAddress As System.Net.IPAddress = System.Net.IPAddress.Parse(console.readline)
'IPaddres Returns a String = error
ipadd = console.readline -
Wednesday, March 14, 2007 3:02 PMHi dakota367, can you post your updated code?
-
Wednesday, March 14, 2007 5:50 PM
Did you do any validation on the code to even verify that a string was present.
The following works just fine taking a string such as 1.2.3.4 and using it to establish a variable of type IPAddress called hostIPAddress,
Module Module1
Sub Main()
Try
Dim strIP As String = Console.ReadLine
If strIP.Trim.Length > 0 Then
Dim hostIPAddress As System.Net.IPAddress = System.Net.IPAddress.Parse(strIP)
Else
MsgBox("No String specified")
End IfCatch ex As Exception
MsgBox(ex.Message)
End Try
End SubEnd Module

