namedajipai1
namedajipai1
采纳率34%
2016-11-12 13:42

怎么在VB中给数组元素的每个下标一个变量名,就像定义参数一样?

已采纳

怎么在VB中给数组元素的每个下标一个变量名,就像定义参数一样?不同的下标表示不同的变量名在VB的实现是?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • caozhy 从今以后生命中的每一秒都属于我爱的人 4年前
    点赞 评论 复制链接分享
  • Tiger_Zhao Tiger_Zhao 5年前

    那么就封装成函数/属性好了。
    '类 Table
    Option Explicit
    Option Base 1

    Private m_Cells() As Long
    
    Public Sub DefineSize(ByVal RowCount As Long, ByVal ColCount As Long)
        ReDim m_Cells(RowCount, ColCount)
    End Sub
    
    Public Property Get Cells(ByVal Row As Long, ByVal Col As Long) As Long
        Cells = m_Cells(Row, Col)
    End Property
    
    Public Property Let Cells(ByVal Row As Long, ByVal Col As Long, ByVal RHS As Long)
        m_Cells(Row, Col) = RHS
    End Property
    

    调用
    Option Explicit

    Sub Main()
        Dim t As Table
        Set t = New Table
        Call t.DefineSize(2, 3)
        t.Cells(1, 2) = 3 '<-这里自动提示参数'
    End Sub
    
    点赞 评论 复制链接分享

相关推荐