VB编写文本框text1中输入一个数字然后

VB编写
文本框text1中输入一个数字然后点击"添加"按钮,使用列表框控件的additem方法
将该数学添加到列表框控件list1中.依此添加若干数字.

第1个回答  2015-05-04
Private Sub Command1_Click()
List1.AddItem Trim(text1.Text)
End Sub追问

错误的,如果text输入5,单击第二次还会输入5,相同数字不输入LISTBOX

追答

??老兄你出题的时候说全,不输入相同字,加判断,我比较懒,知道你问的麻烦就不答了,给你写全吧:
Private Sub Command1_Click()
Dim i As Integer
If List1.ListCount > 0 Then
Dim temBol As Boolean
temBol = False
For i = 1 To List1.ListCount
If Val(List1.List(i - 1)) = Val(Text1.Text) Then
temBol = True
End If
Next i
If Not temBol Then
List1.AddItem Trim(Text1.Text)
Else
MsgBox "数字已存在,不能添加!"
End If
Else
List1.AddItem Trim(Text1.Text)
End If
End Sub

追问

好高手

本回答被提问者采纳
相似回答