Dim csmc() As String
Dim flag As BooleanPrivate Sub combo1_click()
  If Not flag Then
    Exit Sub
  Else
    For i = 1 To 5
      MsgBox csmc(i)
    Next
  End If
End SubPrivate Sub combo1_dropdown()
  ReDim csmc(1 To 5) As String
  csmc(combo1.ListIndex + 1) = text1.Text
  flag = True
End SubPrivate Sub form_load()
  combo1.ListIndex = 0
End Sub我想要的效果是在鼠标点COMBO后,把TEXT1的当前值贮存起来(dropdown中实现),CLICK后把刚选择项目的值在TEXT1中显示出来。
为什么在CLICK后只能得到最近一个CSMC(i)的值,而其它的值都为""

解决方案 »

  1.   

    ReDim csmc(1 To 5) As String
    修改成 ReDim Preserve csmc(1 To 5) As String
      

  2.   

    1、定义为私有变量
    如:dim a as string
    可通过创建窗体属性来访问

    Public Property Let SetA(ByVal vData As String)
    'used when assigning a value to the property, on the left side of an assignment.
    'Syntax: X.a = 5
        a = vData
    End Property
    Public Property Get GetA() As String
    'used when retrieving value of a property, on the right side of an assignment.
    'Syntax: Debug.Print X.a
        GetA = a
    End Property
    访问时:Form1.GetA
    2、定义为公有变量
    如:public a as string
    可直接访问,如:Form1.a