?
Solved

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

Posted on 2010-11-18
6
Medium Priority
?
755 Views
Last Modified: 2012-05-10
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.
0
Comment
Question by:mdreed
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 17

Accepted Solution

by:
Zhaolai earned 2000 total points
ID: 34166749
Try this:
Dim FldArray(,) As String

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

Open in new window

0
 

Author Comment

by:mdreed
ID: 34167008
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) ?

0
 
LVL 17

Expert Comment

by:Zhaolai
ID: 34167102
You can change the FldArray declaration back to Object, but I believe it will be fine.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mdreed
ID: 34167195
When attempting 'If FldArray(cx)(0) = "" Then'

I get 'Attempted to operate on an array with the incorrect number of dimensions.'
0
 
LVL 17

Expert Comment

by:Zhaolai
ID: 34167329
Have you tried 'If FldArray(cx, 0) = "" Then'?
0
 

Author Comment

by:mdreed
ID: 34167362
That would make sense, wouldn't it . . .

Thanks for you help.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question