先构造一个类,属性有姓名性别之类。还是要用数据库,不是要存在文本文件里吧。VB 有类的模板,但是内容还是你自己做吧……才 10 分啊
创新互联公司专注于华池网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供华池营销型网站建设,华池网站制作、华池网页设计、华池网站官网定制、成都微信小程序服务,打造华池网络公司原创品牌,更为您提供华池网站排名全网营销落地服务。
你可以定义一个数组,其中每一个元素都是一个结构,在每一个结构中存放每一个人的姓名、年龄等信息。这需要用到类。
创建类,然后定义结构中包含的所有数据,然后在程序中创建数组,定义每一个数组的元素都是一个这样的类,并且在定义后使用New子句将其实力化.关于类,你可以参考你的学习用书,定义应该不成问题,关键看这种思路吧.
例如定义类,内容:
Public Class VarClass
Public Class Student
Public Name As String
Public NamePass As String
Public Number As UInt16
Public Dis, Stu As New Collection
Public ToDis, ToStu As Decimal
End Class
End Class
然后在程序代码中:Public People(10) As Object
注意一定要先定义Object,因为数组无法使用New子句
然后实例化:
For a = 0 To (My.Forms.Form1.StuNum - 1)
People(a) = New VarClass.Student
Next
定义完成!
For a=0 to 10 do
If People(a).Name=Name(选中的名字) then
textbox1.text=People(a).Age
exit for
End if
然后根据ListBox中选中项的Text,使用For.Each(在数量无法确定的情况下)或者For.do语句,遍历数组中每个元素,即结构中的姓名域,如果找到,就把该结构中的其它几项内容分别赋给TextBox的Text,并且用Exit For跳出For语句.
成功!
.net中不用mscomm 而改用 searport
AxMSComm1.Input 只能一次,会把输入缓冲区的内容全都读出来并清空
如果没有产生Oncomm事件,你可以把输入经部区的大小改一下改成1就行了
用 vb.net socket通信
Dim th As Threading.Thread
2 Dim tcpl As System.Net.Sockets.TcpListener
3
4 Private Sub Form1_Load()Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
5 th = New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf MyListen))
6 th.Start()
7 End Sub
8
9 Public Sub SendMessage()Sub SendMessage(ByVal IP As String, ByVal SendMsg As String)
10 Try
11 If IP "" Then
12 Dim tcpc As New System.Net.Sockets.TcpClient(IP, 5656)
13 Dim tcpStream As Net.Sockets.NetworkStream = tcpc.GetStream
14 Dim reqStream As New IO.StreamWriter(tcpStream)
15 reqStream.Write(SendMsg)
16 reqStream.Flush()
17 tcpStream.Close()
18 tcpc.Close()
19 End If
20 Catch ex As Exception
21 MsgBox(ex.Message.ToString)
22 End Try
23 End Sub
24 Private Sub MyListen()Sub MyListen()
25 Try
26 Dim ipAddress As System.Net.IPAddress = System.Net.Dns.Resolve(System.Net.Dns.GetHostName).AddressList(0)
27 tcpl = New System.Net.Sockets.TcpListener(ipAddress, 5656)
28 tcpl.Start()
29 While True
30 Dim s As System.Net.Sockets.Socket = tcpl.AcceptSocket()
31 Dim MyBuffer(1024) As Byte
32 Dim i As Integer
33 i = s.Receive(MyBuffer)
34 If i 0 Then
35 Dim lstrRec As String
36 Dim j As Integer
37 For j = 0 To i - 1
38 TextBox1.Text += Chr(MyBuffer(j)) ","
39 Next
40 End If
41 End While
42 Catch ex As Exception
43 MsgBox(ex.Message.ToString)
44 End Try
45 End Sub
46
47 Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
48 SendMessage("192.168.0.61", TextBox2.Text)
49 End Sub