Klaus Nji
Klaus Nji

Reputation: 18857

VB.NET 1D array access using 2 indices

Trying to port over some legacy VB.NET code to C# and running into syntax issues with array indexing.

Within a VB method, called, Get_Coverage_Percentage, is a line of code that looks like this:

 Dim RS_Activation_List = Get_Activation_List(Company_ID, Start_Date, End_Date, 0)

where RS_Activation_List was initialized in method Get_Activation_List as

 Dim Activation_List(ds.Tables(0).Rows.Count) As Activation_List

Based on my current understanding of VB.NET syntax, that above translated to a 1D array. However, later in Get_Coverage_Percentage, is a line that accesses Activation_List array as follows:

  RS_Prorated_Activation = FormatNumber(RS_Activation_List(RS_Sum_Activation, 5), 2)

How can one be accessing a 1D array using 2 indices? Activation_List itself is a simple structure that is defined as follows:

  Structure Activation_List
        Dim Mobile_ID As Integer
        Dim Radio_Address As Double
        Dim Activation_Date As Date
        Dim Pro_Rated_Fee As Integer
        Dim Sum_Pro_Rated_Fee As Integer
    End Structure

VB pro, what am I looking at here?

*Update: * Method *Get_Activation_List* looks like this, with some parts taken out:

 Public Function Iridium_Get_Activation_List(ByVal Company_ID, ByVal Start_Date, ByVal End_Date, ByVal Access_Fee) As Array
        Dim vNumOfDaysInMonth = Get_Number_Of_Day_In_Month(Start_Date)
        Dim SQL = "SELECT * from assMobileRadio;"

        Dim drDataRow As DataRow
        Dim ds As DataSet = GetData(SQL)
        Iridium_Get_Activation_List = Nothing
        Dim Activation_List(ds.Tables(0).Rows.Count) As Activation_List  
        Dim vSumofProrated = 0
        Dim vRow = 0
        For Each drDataRow In ds.Tables(0).Rows
             'missing code
            vRow = vRow + 1
        Next
        Return Activation_List
    End Function

and yes, the code does not compile.

Upvotes: 0

Views: 130

Answers (1)

Matt Wilko
Matt Wilko

Reputation: 27322

This line is declaring a new variable array of type Activation_List

Dim Activation_List(ds.Tables(0).Rows.Count) As Activation_List

This line declares a different variable of a different type:

Dim RS_Activation_List = Get_Activation_List(Company_ID, Start_Date, End_Date, 0)

We don't know what type this is from your code, but given this line works ok it is a 2d array of some custom type:

RS_Prorated_Activation = FormatNumber(RS_Activation_List(RS_Sum_Activation, 5), 2)

Hover over RS_Activation in VS and see what type it says it is. Also make sure you have Option Strict On.

Upvotes: 2

Related Questions