Solved

Array Columns

Posted on 2000-03-01
2
140 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 30 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

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

920 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

12 Experts available now in Live!

Get 1:1 Help Now