vb 列表框程序如下,运行该程序时提示变量未定义,如何定义变量?
PrivateSubform_load()'装载窗体时,给列表中的元素赋值’list1.AddItem"china"list1.AddItem"america"list1...
Private Sub form_load()
'装载窗体时,给列表中的元素赋值’
list1.AddItem "china"
list1.AddItem "america"
list1.AddItem "japan"
list2.AddItem "soccer"
list2.AddItem "tennis"
list2.AddItem "basketball"
End Sub
Private Sub lefttorightcmd_click()
'将左边列表中所选元素移动到右边列表'
If list1.ListIndex >= 0 Then
'在右边列表中增加新元素'
list2.AddItem list1.Text
'删除左边列表中的所选元素'
list1.RemoveItem list1.ListIndex
End If
End Sub
Private Sub list1addcmd_click()
Dim listitem As String
listitem = InputBox("在列表中增加新项目")
'向列表中加入新项目'
If Trim(listitem) <> "" Then
'trim ()作用是清除listitem字符串内的空格'
list1.AddItem listitem
End If
End Sub
Private Sub list1clearcmd_click()
'晴空列表'
list1.Clear
End Sub
Private Sub list1movecmd_click()
Dim i As Integer
'判断列表筐是否只有一个项目被选中'
If list1selcount = 1 Then
list1.RemoveItem list1.ListIndex
ElseIf list1.ListCount > 1 Then
'删除列表中所选多个项目'
For i = list1.ListCount - 1 To 0 Step -1
'listcount返回列表矿中的项目总数’
'listcount-1是列表矿中最后一个项目的所以好'
'判断该项目是否被选中,selected()返回布尔只'
If list1.Selected(i) Then
'删除缩影号为i的项目'
list1.RemoveItem i
End If
Next
End If
End Sub
Private Sub list2addcmd_click()
'定义变量,以接受输入的字符串'
Dim listitem As String
listitem = InputBox
If Trim(listitem) <> "" Then
list2.AddItem listitem
End If
End Sub
Private Sub list2clearcmd_click()
list2.Clear
End Sub
Private Sub list2movecmd_click()
Dim i As Integer
If list2.SelCount = 1 Then
list2.RemoveItem list2.ListIndex
ElseIf list2.ListCount > 1 Then
For i = list2.ListCount - 1 To 0 Step -1
If list2.Selected(i) Then
lsit2.RemoveItem i
End If
Next i
End If
End Sub
Private Sub righttoleftcmd_click()
Dim i As Integer
If list2.SelCount = 1 Then
lsit1.AddItem list2.Text
list2.RemoveItem list2.ListIndex
ElseIf list2.SelCount > 1 Then
For i = list2.ListCount - 1 To 0 Step -1
If list2.Selected(i) Then
list1.AddItem list2.List(i)
list2.RemoveItem i
End If
Next i
End If
End Sub 展开
'装载窗体时,给列表中的元素赋值’
list1.AddItem "china"
list1.AddItem "america"
list1.AddItem "japan"
list2.AddItem "soccer"
list2.AddItem "tennis"
list2.AddItem "basketball"
End Sub
Private Sub lefttorightcmd_click()
'将左边列表中所选元素移动到右边列表'
If list1.ListIndex >= 0 Then
'在右边列表中增加新元素'
list2.AddItem list1.Text
'删除左边列表中的所选元素'
list1.RemoveItem list1.ListIndex
End If
End Sub
Private Sub list1addcmd_click()
Dim listitem As String
listitem = InputBox("在列表中增加新项目")
'向列表中加入新项目'
If Trim(listitem) <> "" Then
'trim ()作用是清除listitem字符串内的空格'
list1.AddItem listitem
End If
End Sub
Private Sub list1clearcmd_click()
'晴空列表'
list1.Clear
End Sub
Private Sub list1movecmd_click()
Dim i As Integer
'判断列表筐是否只有一个项目被选中'
If list1selcount = 1 Then
list1.RemoveItem list1.ListIndex
ElseIf list1.ListCount > 1 Then
'删除列表中所选多个项目'
For i = list1.ListCount - 1 To 0 Step -1
'listcount返回列表矿中的项目总数’
'listcount-1是列表矿中最后一个项目的所以好'
'判断该项目是否被选中,selected()返回布尔只'
If list1.Selected(i) Then
'删除缩影号为i的项目'
list1.RemoveItem i
End If
Next
End If
End Sub
Private Sub list2addcmd_click()
'定义变量,以接受输入的字符串'
Dim listitem As String
listitem = InputBox
If Trim(listitem) <> "" Then
list2.AddItem listitem
End If
End Sub
Private Sub list2clearcmd_click()
list2.Clear
End Sub
Private Sub list2movecmd_click()
Dim i As Integer
If list2.SelCount = 1 Then
list2.RemoveItem list2.ListIndex
ElseIf list2.ListCount > 1 Then
For i = list2.ListCount - 1 To 0 Step -1
If list2.Selected(i) Then
lsit2.RemoveItem i
End If
Next i
End If
End Sub
Private Sub righttoleftcmd_click()
Dim i As Integer
If list2.SelCount = 1 Then
lsit1.AddItem list2.Text
list2.RemoveItem list2.ListIndex
ElseIf list2.SelCount > 1 Then
For i = list2.ListCount - 1 To 0 Step -1
If list2.Selected(i) Then
list1.AddItem list2.List(i)
list2.RemoveItem i
End If
Next i
End If
End Sub 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询