Solved

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

Posted on 2010-11-18
6
742 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 500 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Studios 1 90
How to seperate number and letters from a string 3 26
YouTube API get the Video Tags - vb.net 7 33
Stop Git from being my repository 1 26
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 …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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