Solved

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

Posted on 2010-11-18
6
730 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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