namedajipai1
2016-11-12 13:42
采纳率: 34%
浏览 2.3k
已采纳

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

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

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • threenewbee 2017-01-10 15:49
    已采纳
    已采纳该答案
    打赏 评论
  • Tiger_Zhao 2016-11-16 01:43

    那么就封装成函数/属性好了。
    '类 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
    
    打赏 评论

相关推荐 更多相似问题