2016-04-25 134 views
2

我的數組大小由其他函數決定。但是當我試圖用我收到錯誤的變量來定義數組的大小「常量表達式必需」如何在變量中定義數組大小

我想定義數組

Option Explicit 
Sub Abcd() 
    Dim n_variables As Integer 
    n_variables = def() 
    MsgBox "n_variables" & n_variables 
    Dim abc(1 To n_variables) As Integer 
End Sub 
Function def() 
    def = 100 
End Function 

的大小有什麼辦法,我可以以變​​量格式定義數組大小? 任何人都請幫助我。

+1

您可以隨時使用'Redim'來更改數組大小。 –

+0

謝謝Pankaj ... – surendra

回答

2
Dim n_variables As Integer 
n_variables = def() 
MsgBox "n_variables" & n_variables 
Dim abc() As Integer 
Redim abc(1 To n_variables) As Integer 
相關問題