0
我想基於讀取文件ReDim成員數組。我無法弄清楚如何去做。這是我試過的,但它不起作用。編程的VB成員字段ReDim
Public Class BS
Public A() As String
Public B() As Double
Public C() As Double
End Class
Public Class SB
Public MyBS() As BS
'ReadFieldString is a function that returns a string of the field name of Class BS,
'i.e., A, B or C. For test purpose, retun a constant
Public Function ReadFieldString() As String
Return "B"
End Function
'GetArrayDim is a function that returns an integer, which is the size of the array
'of that field name. For test purpose, retun a constant
Public Function GetArrayDim() As Integer
Return 1
End Function
Public Sub DimArrays()
ReDim MyBS(3)
Dim i As Integer
For i = 0 To MyBS.Length - 1
'Try to ReDim the member of MyBS
ReDim MyBS(i).GetType.GetField(ReadFieldString)(GetArrayDim)
Next()
End Sub
End Class
ReDim語句有錯誤「表達式是一個值,因此不能作爲賦值的目標。」 在此先感謝。
我不確定你想用get類型來完成什麼,但是redim應該只針對數組和新元素。 http://msdn.microsoft.com/en-us/library/w8k3cys2(v=vs.100).aspx – Wade73 2013-03-04 21:42:33
我想設置成員的數組大小。但成員「名稱」和數組的大小從文件中讀取。我如何根據從文件中讀取的字符串來引用成員?這是一個例子,真正的「BS」類擁有數百名成員,因此做一些「如果」這樣的事情是不現實的。 – scriptOmate 2013-03-04 21:48:41