Link to home
Start Free TrialLog in
Avatar of mdreed
mdreedFlag for United States of America

asked on

How to define a 2-dimensional lookup array in VB.NET.

I have an array of static data that I use in VB6 to define the format and contents of a datagrid.  The code is shown below and works fine in VB6, but I don't know how to define this same array content in VB.NET.

Dim FldArray As Object

FldArray = Array( _
           Array("RecUPC", "UPC", 85, "L"), _
           Array("RecDescr", "Description", 140, "L"), _
           Array("RecQty", "Qty", 35, "R"), _
           Array("RecSysCost", "E1 Cost", 50, "R"), _
           Array("RecNewCost", "Invoice Cost", 55, "R"), _
           Array("RecRetail", "Retail", 50, "R"), _
           Array("RecExtCost", "Ext Cost", 60, "R"), _
           Array("RecError", "Errors", 125, "L"))

I then pass the FldArray object (array), the form name, and grid name to a procedure to format the grid.   For example,
.DataColumn.DataField = FldArray(i)(j)

Anyway, I can't seem to figure out how to define the array in .NET.
ASKER CERTIFIED SOLUTION
Avatar of Zhaolai
Zhaolai
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mdreed

ASKER

The definition you provided seems to be error free, but I need to see if it flows correctly to the called procedure.  Previously, FldArray argument was also declared as Object in the called procedure such as the following:

Public Sub Format_grid(ByVal MyForm As Form, ByVal FldArray As Object, ByVal MyGrid As C1.Win.C1TrueDBGrid.C1TrueDBGrid)

How should it be declared in the procedure and how should it be referenced in code in order to accommodate the VB6 syntax of .DataColumn.DataField = FldArray(i)(j) ?

You can change the FldArray declaration back to Object, but I believe it will be fine.
Avatar of mdreed

ASKER

When attempting 'If FldArray(cx)(0) = "" Then'

I get 'Attempted to operate on an array with the incorrect number of dimensions.'
Have you tried 'If FldArray(cx, 0) = "" Then'?
Avatar of mdreed

ASKER

That would make sense, wouldn't it . . .

Thanks for you help.