我有一个 Visual Basic 的家庭作业程序。它以并行数组的形式存储 7 个朋友的 7 个电话号码。我正在使用 array.indexof 查看我的输入字符串是否在名称数组中,然后返回完整名称和相应的数字。我不是在寻找海报的答案,只是一些指导或指出我的过度网站。提前致谢。抱歉,如果我的帖子出现乱码或格式不正确,第一次发帖 Robert
Dim intCounter As Integer
Dim strNames() As String = {"BILLY", "JILLY", "MILLY", "PHILLY", "LARRY", "CURLY", "MOE"}
Dim strNumbers() As String = {"313-213-1234", "248-123-3452", "123-321-1234", "987-986-3456", "567-635-7632", "524-456-6782", "918-872-3452"}
Dim strLookFor As String
Dim found As Boolean
strLookFor = InputBox("Type in the person you want to call", "Phone a Friend") 'prompt from user
strLookFor.TrimEnd() 'trim whitespace after entry
strLookFor = strLookFor.ToUpper 'convert to upper case to match
txtResults.Clear() 'clear text box
found = False 'set boolean to false
intCounter = 0 'set intCounter to 0
Do While Not found And intCounter < strNames.Length
Dim intIndex As Integer = Array.IndexOf(strNames, strLookFor) 'SHOULD return a value of 0 or higher if found
If intIndex >= 0 Then 'if loop for value of 0 or higher
found = True
End If
intCounter += 1 'add 1 to intCounter
Loop
If found Then 'display phone match up results
txtResults.Text = ((strNames(intCounter - 1)) & " " & (strNumbers(intCounter - 1)))
Else
txtResults.Text = ("Match not found.")
End If
End Sub