I am porting Excel VBA to VB.NET. I have a function that takes a selection of data, and it may be one dimensional or two. VBA code is quite fluid about using a variable as either a 1-D or 2-D array, but VB.NET marks it as an error.
Here is the reduced code:
Public Function Stat(ByVal Data As Range) As Object
Dim Y() As Object
Dim Appp As New Application() ''// Very annoying
''//Convert worksheet range into array vector
Y = Appp.WorksheetFunction.Transpose(Appp.WorksheetFunction.Transpose(Data))
Dim dimensions As Integer : dimensions = NumberOfArrayDimensions(Y)
If dimensions > 1 Then
For i = LBound(Y) To UBound(Y)
If VarType(Y(i, 1)) <> 0 Then
It fails with "number of indices exceeds the number of dimensions of the indexed array" on the last line.
Edit: So the question is something like, "How can I use a single variable in VB.NET as I can in Excel VBA -- having ambiguous/flexible dimensionality?" Failing that, "How would you recommend changing the code to be most natural in VB.NET?"