VB怎么实现这个简单的功能?

来源:百度知道 编辑:UC知道 时间:2024/06/22 01:05:56
之前学过VB,不过很久没用,忘光光了。最近搞C语言 - -!

正题:用VB实现以下功能

就是在combo选择框里输入一些人的名字,这个在list属性输入对吧?

然后选择了其中某人的名字后,就在Text1显示这个人的生日。

麻烦提供代码,谢谢。

Private Sub Form_Load()
List1.List(0) = " 张三"
List1.List(1) = " 李四"
End Sub

Private Sub List1_Click()
Select Case List1.ListIndex
Case 0
Text1.Text = "6/5"
Case 1
Text1.Text = "7/8"
End Select
End Sub
我用的是listbox控件

注意要把combo1.sorted属性设为false

Private strNames, strBirth As Variant
Private Sub Combo1_Click()
Text1.Text = strBirth(Combo1.ListIndex)
End Sub
Private Sub Form_Load()
Dim i As Integer
'# 设置combo1和text1
Combo1.Text = "" '清空combo1文本
Text1.Text = ""
'# 初始化数组
strNames = Array("小红", "小明", "小黄") '这里输入姓名
strBirth = Array("3.1", "4.5", "5.6") '这里输入生日 (注意姓名和生日对应)
'# 向combo1中添加项目
For i = 0 To UBound(strNames)
Combo1.AddItem (strNames(i))
Next i
End Sub

Private Sub Comb