VB6.0 列表框列表项的分类移动
在vb中,要在两个列表项中移动元素,是一个足球队员出场的课程设计,马上就得交了,急啊要求,在两个列表框中移动元素,list1中有11个元素,5个前锋,6个后卫,移到lis...
在vb 中,要在两个列表项中移动元素,是一个足球队员出场的课程设计,马上就得交了,急啊
要求,在两个列表框中移动元素,list1中有11个元素,5个前锋,6个后卫,移到list2中,但list2中只能有4个前锋,4个后卫,如果超出了人数,就得提示,禁止再选择。提示是定义两个数组,分别存放11个队员的位置和名子,然后移动的时候累加和,但做了一周,还是不行啊。
急啊,谢谢大家帮忙 展开
要求,在两个列表框中移动元素,list1中有11个元素,5个前锋,6个后卫,移到list2中,但list2中只能有4个前锋,4个后卫,如果超出了人数,就得提示,禁止再选择。提示是定义两个数组,分别存放11个队员的位置和名子,然后移动的时候累加和,但做了一周,还是不行啊。
急啊,谢谢大家帮忙 展开
1个回答
展开全部
Option Explicit
Dim d(1 To 11, 1 To 2) As String
Private Sub Command1_Click()
Dim i As Integer
Dim j As Integer
Dim k As Integer
If List1.ListIndex <> -1 Then
For i = 1 To 11
If List1.List(List1.ListIndex) = d(i, 1) & "(" & d(i, 2) & ")" Then
If d(i, 2) = "前锋" Then
For j = 0 To List2.ListCount - 1
If InStr(List2.List(j), "前锋") > 0 Then
k = k + 1
End If
Next j
If k < 4 Then
List1.RemoveItem List1.ListIndex
List2.AddItem d(i, 1) & "(" & d(i, 2) & ")"
Else
MsgBox "禁止再添加前锋了"
End If
End If
If d(i, 2) = "后卫" Then
For j = 0 To List2.ListCount - 1
If InStr(List2.List(j), "后卫") > 0 Then
k = k + 1
End If
Next j
If k < 4 Then
List1.RemoveItem List1.ListIndex
List2.AddItem d(i, 1) & "(" & d(i, 2) & ")"
Else
MsgBox "禁止再添加后卫了"
End If
End If
End If
Next i
Else
MsgBox "请选中一个球员"
End If
End Sub
Private Sub Command2_Click()
Dim s As String
If List2.ListIndex <> -1 Then
s = List2.List(List2.ListIndex)
List2.RemoveItem List2.ListIndex
List1.AddItem s
End If
End Sub
Private Sub Form_Load()
Command1.Caption = "从LIST1移动到LIST2"
Command2.Caption = "从LIST2移动到LIST1"
d(1, 1) = "姓名1": d(1, 2) = "前锋"
d(2, 1) = "姓名2": d(2, 2) = "前锋"
d(3, 1) = "姓名3": d(3, 2) = "前锋"
d(4, 1) = "姓名4": d(4, 2) = "前锋"
d(5, 1) = "姓名5": d(5, 2) = "前锋"
d(6, 1) = "姓名6": d(6, 2) = "后卫"
d(7, 1) = "姓名7": d(7, 2) = "后卫"
d(8, 1) = "姓名8": d(8, 2) = "后卫"
d(9, 1) = "姓名9": d(9, 2) = "后卫"
d(10, 1) = "姓名10": d(10, 2) = "后卫"
d(11, 1) = "姓名11": d(11, 2) = "后卫"
Dim i As Integer
For i = 1 To 11
List1.AddItem d(i, 1) & "(" & d(i, 2) & ")"
Next i
End Sub
Dim d(1 To 11, 1 To 2) As String
Private Sub Command1_Click()
Dim i As Integer
Dim j As Integer
Dim k As Integer
If List1.ListIndex <> -1 Then
For i = 1 To 11
If List1.List(List1.ListIndex) = d(i, 1) & "(" & d(i, 2) & ")" Then
If d(i, 2) = "前锋" Then
For j = 0 To List2.ListCount - 1
If InStr(List2.List(j), "前锋") > 0 Then
k = k + 1
End If
Next j
If k < 4 Then
List1.RemoveItem List1.ListIndex
List2.AddItem d(i, 1) & "(" & d(i, 2) & ")"
Else
MsgBox "禁止再添加前锋了"
End If
End If
If d(i, 2) = "后卫" Then
For j = 0 To List2.ListCount - 1
If InStr(List2.List(j), "后卫") > 0 Then
k = k + 1
End If
Next j
If k < 4 Then
List1.RemoveItem List1.ListIndex
List2.AddItem d(i, 1) & "(" & d(i, 2) & ")"
Else
MsgBox "禁止再添加后卫了"
End If
End If
End If
Next i
Else
MsgBox "请选中一个球员"
End If
End Sub
Private Sub Command2_Click()
Dim s As String
If List2.ListIndex <> -1 Then
s = List2.List(List2.ListIndex)
List2.RemoveItem List2.ListIndex
List1.AddItem s
End If
End Sub
Private Sub Form_Load()
Command1.Caption = "从LIST1移动到LIST2"
Command2.Caption = "从LIST2移动到LIST1"
d(1, 1) = "姓名1": d(1, 2) = "前锋"
d(2, 1) = "姓名2": d(2, 2) = "前锋"
d(3, 1) = "姓名3": d(3, 2) = "前锋"
d(4, 1) = "姓名4": d(4, 2) = "前锋"
d(5, 1) = "姓名5": d(5, 2) = "前锋"
d(6, 1) = "姓名6": d(6, 2) = "后卫"
d(7, 1) = "姓名7": d(7, 2) = "后卫"
d(8, 1) = "姓名8": d(8, 2) = "后卫"
d(9, 1) = "姓名9": d(9, 2) = "后卫"
d(10, 1) = "姓名10": d(10, 2) = "后卫"
d(11, 1) = "姓名11": d(11, 2) = "后卫"
Dim i As Integer
For i = 1 To 11
List1.AddItem d(i, 1) & "(" & d(i, 2) & ")"
Next i
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询