Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Array Columns

Posted on 2000-03-01
2
Medium Priority
?
151 Views
Last Modified: 2010-05-02
How do you make an array show as a table? Mine show up as

Peas
1.00
10
Jam
2.00
5
I want it to look like this:

Sampl:
Name Cost code
Peas 1.00 P
Jam  2.00 J

0
Comment
Question by:mad3654
2 Comments
 
LVL 2

Accepted Solution

by:
alokanant earned 90 total points
ID: 2575208
hi mad3654,
here is the code -

Dim a(6) As Variant
    Dim i As Integer
   
    a(0) = "JIM"
    a(1) = "100"
    a(2) = "C"
    a(3) = "TIM"
    a(4) = "200"
    a(5) = "D"
   
    Open "C:\ALOKTEMP\TESTFILE" For Output As #1
    i = 0
    Print #1, "Name Cost Code"
    While i < UBound(a)
        Print #1, a(i); "   "; a(i + 1); "   "; a(i + 2)
        i = i + 3
    Wend

hth
alok
0
 

Expert Comment

by:ramaswamy_ravi
ID: 2575223
mad3654 ,
Method 1
========
Dim I%, J%
Dim X(0 TO 6) As String
Dim Y(0 To 1, 0 To 1, 0 To 1) As String
For I = 0 To 5 Step 3
  J = J + 1
  X(J, 0, 0) = Y(I)
  X(J, 0, 1) = Y(I + 1)
  X(J, 1, 0) = Y(I + 2)
Next I

Method 2
========
Type TYPE_X
 strName As String
 sglCost As Single
 strCode As String
End Type

Dim Item(0 To 1) As TYPE_X

For I = 0 To 5 Step 3
  J = J + 1
  With Item(J)
    .strName = X(I)
    .sglCost = X(I + 1)
    .strCode = X(I + 2)
  End With
Next I

I prefer method 2 since you are not dealing with multi-dim arrays.

Hope this answers your question. If so, please convert this as an answer.

Please let me know.

Cheers,
Ravi
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

916 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