我会在vb中为用户输入的ip地址分配什么变量类型? [英] What variable type would i assign a user entered ip address in vb?
本文介绍了我会在vb中为用户输入的ip地址分配什么变量类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我为课堂做了这本书的任务,但是之后我喜欢进入课程结构以外的事情。所以我的想法是添加一个功能,用户输入他/她选择的IP。我已经知道我将如何添加模块,但是我不知道我将为IP地址分配给变量的数据类型。
我尝试过:
So I did this book assignment for class, however I like to go in and do things outside the course structure afterwards. So my idea is to add in a feature where the user inputs an IP of his/her choice. I already know how I'm going to add in the module, However I don't Know what data type I would assign to the variable for the IP Address.
What I have tried:
Module Module1
Sub Main()
Dim pingCounter As Integer = 0
pingCounter = generateRandom(pingCounter)
Console.WriteLine("The server was pinged " & pingCounter & " time(s).")
Console.WriteLine("Press Any key to exit...")
Console.ReadKey()
End Sub
End Module
Module RNG
Function generateRandom(ByRef pingCounter As Integer) As Integer
Dim RN As Integer = 0
Dim Count As Integer = 0
For Count = 1 To 200
RN = Int(Rnd() * 20 + 1)
If RN <> 5 Then
Console.WriteLine("Random number was " & RN & " this was not the target number.")
Console.WriteLine("Re-rolling in 1000 ms...")
ElseIf RN = 5 Then
pingMe()
pingCounter = pingCounter + 1
End If
System.Threading.Thread.Sleep(1000)
Next
Return pingCounter
End Function
End Module
Module Ping
Sub pingMe()
Shell("Ping.exe 127.0.0.1", , True)
Console.Out.WriteLine(" ")
End Sub
End Module
推荐答案
使用string - 它处理IPV4和IPV6,它们的格式非常不同。
IP地址 - 维基百科,免费百科全书 [ ^ ]
另外,还有 IPAddress class [ ^ ]其中也会举行。但是,如果你想将它们存储在任何地方,你必须将它们转换为字符串!
Use string - it copes with IPV4 and IPV6, which are very different in format.
IP address - Wikipedia, the free encyclopedia[^]
Alternatively, there is the IPAddress class[^] which will hold either. However, if you want to store them anywhere, you will have to convert them to strings anyway!
这篇关于我会在vb中为用户输入的ip地址分配什么变量类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文