窗体上建立一个简单的组合框,在组合框的文本框的文本框输入数字字符,按回车键后加入到组合框的列表框内

2025-03-02 02:18:41
推荐回答(2个)
回答1:

一楼回答不错,但我想这个应用一般是要去掉重复数据的。因为我这台电脑没有装VB,去重复你的那个For循环可能有点错误,具体需要您在VB环境下调试下。

Private Sub Combo1_KeyPress(KeyAscii As Integer)
dim K as long
If KeyAscii = 13 Then
If IsNumeric(Combo1.Text) Then
for k=0 to combo1.listcount -1
if clng(combo1.list(k))=clng(combo1.text) then exit for
next
if k>= combo1.lsitcount then Combo1.AddItem Combo1.Text
Else
MsgBox Combo1.Text & " 不是数字!"
End If
End If
End Sub

回答2:

Private Sub Combo1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If IsNumeric(Combo1.Text) Then
Combo1.AddItem Combo1.Text
Else
MsgBox Combo1.Text & " 不是数字!"
End If
End If
End Sub