'第11题
Private Sub Command1_Click() '>按钮
flag = True
For i = List1.ListCount - 1 To 0 Step -1
If List1.Selected(i) Then
List2.AddItem List1.List(i)
List1.RemoveItem i
flag = False
End If
Next i
If flag Then MsgBox "应该先选中左边项目", vbOKOnly, "提示"
End Sub
Private Sub Command2_Click() '>>按钮
For i = List1.ListCount - 1 To 0 Step -1
List2.AddItem List1.List(i)
List1.RemoveItem i
Next i
End Sub
Private Sub Command3_Click() '<按钮
flag = True
For i = List2.ListCount - 1 To 0 Step -1
If List2.Selected(i) Then
List1.AddItem List2.List(i)
List2.RemoveItem i
flag = False
End If
Next i
If flag Then MsgBox "应该先选中右边项目", vbOKOnly, "提示"
End Sub
Private Sub Command4_Click() '<<按钮
For i = List2.ListCount - 1 To 0 Step -1
List1.AddItem List2.List(i)
List2.RemoveItem i
Next i
End Sub
Private Sub Form_Load()
List1.AddItem "语文"
List1.AddItem "数学"
List1.AddItem "英语"
List1.AddItem "生物"
List1.AddItem "化学"
List1.AddItem "物理"
List1.AddItem "体育"
List1.AddItem "美术"
List1.AddItem "音乐"
List1.AddItem "计算机"
End Sub
'第12题
Private Sub Command1_Click() '添加
flag = True
For i = List1.ListCount - 1 To 0 Step -1
If List1.List(i) = Text1.Text Then
flag = False
Exit For
End If
Next i
If flag Then
List1.AddItem Text1.Text
Else
MsgBox "列表已经有该项目", vbOKOnly, "提示"
End If
End Sub
Private Sub Command2_Click() '删除
flag = True
For i = List1.ListCount - 1 To 0 Step -1
If List1.Selected(i) Then
List1.RemoveItem i
flag = False
End If
Next i
If flag Then MsgBox "删除前先选中项目", vbOKCancel, "提示"
End Sub
Private Sub Command3_Click() '清空
For i = List1.ListCount - 1 To 0 Step -1
List1.RemoveItem i
Next i
End Sub
温馨提示:答案为网友推荐,仅供参考