2013-03-03 186 views
0

只是一直在努力解決一個問題,從基於另一個變量名的結構獲取特定...內新的變量名稱中使用外部變量名VB.Net

Sub Main() 

    Dim Testing As Test 
    ReDim Testing.A(15), Testing.B(13), Testing.C(10) 

    Dim Letter As String = Console.ReadLine() 'User Inputs A, B Or C 

    Testing.Letter(3) = "XXXXX" 'Selects the array of the letter the user has input from the Letter variable 

End Sub 

Structure Test 
    <VBFixedString(5)> <VBFixedArray(15)> Dim A() As Integer 
    <VBFixedString(5)> <VBFixedArray(13)> Dim B() As Integer 
    <VBFixedString(5)> <VBFixedArray(10)> Dim C() As Integer 
End Structure 

感謝您尋找任何解決方案建議,非常感謝。

回答

0

我不太確定你在問什麼,但也許你想要一個選擇案例陳述?

Sub Main() 

    Dim Testing As Test 
    ReDim Testing.A(15), Testing.B(13), Testing.C(10) 

    Dim Letter As String = Console.ReadLine() 'User Inputs A, B Or C 

    Select Case Letter.ToUpper 
    Case "A" : Testing.A(3) = "XXXXX" 
    Case "B" : Testing.B(3) = "XXXXX" 
    Case "C" : Testing.C(3) = "XXXXX" 
    End Select 

End Sub 

您也可以使用反射...

+0

德里克,雖然它不是具體是什麼我問它是一個很好的解決我的問題。謝謝! – Tom 2013-03-06 14:41:29