所以我在表单加载时将并行数组显示在组合框中。用户单击名称,然后显示电话号码。所以一切都很好。我的下一个目标是提示用户输入新联系人,他们在一个文本框中输入一个新名称,然后在另一个文本框中输入一个新数字。然后,联系人姓名将显示在组合框中。当我点击名称时,它会在第一次尝试时给我编号,但随后我输入一个新联系人,每次我输入新联系人时,仍会显示第一个联系人的信息。我不知道为什么,有什么想法吗?
Module
Option Explicit On
Module MainModule
Public strPeople() As String = {"Kyle", "John", "Jake", "Donna", "Carly","Ty", "Mavis"}
Public strPhoneNumbers() As String = {"945-1232", "804-2329", "290-7321", "928-4569", "205-9893", "320-0195", "305-4520"}
Public count As Integer = 0
Public numCount As Integer = 0
End Module
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox1.Items.AddRange(strPeople)
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim strPhoneNums As String = strPhoneNumbers(ComboBox1.SelectedIndex)
Label3.Text = "Phone Number: " & strPhoneNums
End Sub
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
If TextBox1.Text = "" And TextBox2.Text = "" Then
MessageBox.Show("Please Enter Name and Number")
ElseIf TextBox1.Text <> "" And TextBox2.Text = "" Then
MessageBox.Show("Please Enter A Number")
ElseIf TextBox1.Text = "" And TextBox2.Text <> "" Then
MessageBox.Show("Please Enter a Name")
Else
For Each Item As String In TextBox1.Text
count += 1
ReDim Preserve strPeople(6 + count)
strPeople(count) = TextBox1.Text
Next
ComboBox1.Items.Add(strPeople(count))
TextBox1.Clear()
For Each Itm As String In TextBox2.Text
numCount += 1
ReDim Preserve strPhoneNumbers(6 + numCount)
strPhoneNumbers(6 + numCount) = TextBox2.Text
Next
TextBox2.Clear()
End If
End Sub
End Class