急性胰腺炎的征兆:关于VB列表框(ListBox)

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/05 05:44:54
如何做才能做到:
当我按下按钮1(command1)时,如果输入的数值(Text1.Text)等于列表框中存在的任何一个项目(注意:我在这里指的是“任何一个项目”!并非选定的项目),程序即会弹出对话框?
(如果不明白,没关系,请提出来,我将在问题补充里告诉你)
(为了确保有回答率,从而不丢失我的积分,我采取先回答,后赠分“政策”!^_^!)

' --- 完整程序如下, VB6 ---
'添加1个Form,Name=Form1
'添加1个ListBox, Name=List1
'添加1个TextBox, Name=Text1

Option Explicit

Private Sub Form_Load()
List1.AddItem "item1"
List1.AddItem "item2"
List1.AddItem "item3"
End Sub

Private Sub Command1_Click()
Dim N As Integer
For N = 0 To List1.ListCount - 1
If Text1.Text = List1.List(N) Then
'--- 显示对话框 ---
MsgBox "Item found! Index = " + CStr(N)
Exit For
End If
Next N
End Sub
' --- 完整程序如上, VB6 ---

Private Sub Command1_Click()
For i = 0 To List1.ListCount - 1
If List1.List(i) = Text1 Then
MsgBox List1.List(i)
Exit For
End If
Next i
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i As Integer

For i = 0 To Me.ListBox1.Items.Count()
If Me.TextBox1.Text = Me.ListBox1.Items.Item(i) Then
MsgBox(Me.TextBox1.Text)
GoTo aaa
End If
Next
aaa:
End Sub
在VB.NET下调试通过。