Solved

Array Columns

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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 …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

743 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

14 Experts available now in Live!

Get 1:1 Help Now