Solved

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

Posted on 2010-11-18
6
734 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
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 …

919 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now