关于VB噶问题

来源:百度知道 编辑:UC知道 时间:2024/09/25 01:27:16
在窗体上画一个名称为Combo1的组合框,画两个名称分别Label1和Label2及Caption属性分别为“城市名称”和空白的标签。程序运行后,当在组合框中输入一个新项后按回车键时,如果输入的项在组合框的列表中不存在,则自动添加到组合框的列表中,并在Label2中给出提示“已成功添加
Private Sub Combo1_(11) (KeyAscii As Integer)
If KeyAscii = 13 Then
For i = 0 To Combo1.ListCount - 1
If Combo1.Text = _(12)_ Then
Label2.Caption = "输入项己在组合框中"
Exit Sub
End If
Next i
Label2.Caption = "已成功添加输入项"
_(13)_ Combo1.Text
End If
End Sub

Private Sub Combo1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
For i = 0 To Combo1.ListCount - 1
If Combo1.Text = Combo1.List(i) Then
Label2.Caption = "输入项己在组合框中"
Exit Sub
End If
Next i
Label2.Caption = "已成功添加输入项"
Combo1.AddItem Combo1.Text
End If
End Sub