你在窗口插入以下控件,combox、listbox、text、command然后复制以下代码即可
Dim
strTemp1()
As
String
Dim
strTemp2()
As
String
Private
Sub
Combo1_Click()
If
Combo1.Text
=
"选项一"
Then
If
UBound(strTemp1)
=
0
Then
List1.Clear
Else
List1.Clear
For
i
=
0
To
UBound(strTemp1)
List1.AddItem
strTemp1(i)
Next
End
If
End
If
If
Combo1.Text
=
"选项二"
Then
If
UBound(strTemp2)
=
0
Then
List1.Clear
Else
List1.Clear
For
i
=
0
To
UBound(strTemp2)
List1.AddItem
strTemp2(i)
Next
End
If
End
If
End
Sub
Private
Sub
Command1_Click()
List1.AddItem
Text1.Text
If
Combo1.Text
=
"选项一"
Then
ReDim
Preserve
strTemp1(List1.ListCount)
strTemp1(List1.ListCount
-
1)
=
List1.List(List1.ListCount
-
1)
End
If
If
Combo1.Text
=
"选项二"
Then
ReDim
Preserve
strTemp2(List1.ListCount)
strTemp2(List1.ListCount
-
1)
=
List1.List(List1.ListCount
-
1)
End
If
End
Sub
Private
Sub
Form_Load()
'设置combo1的Style属性为2
ReDim
Preserve
strTemp1(0)
ReDim
Preserve
strTemp2(0)
Combo1.AddItem
"选项一"
Combo1.AddItem
"选项二"
Combo1.Text
=
"选项一"
End
Sub