Solved

Write array to text file in a single line

Posted on 2004-08-24
5
185 Views
Last Modified: 2010-05-02
I have a multi-dimensional array data. The array is in
I wish to write it to a text file in a single line, which means in this format
"1","2","3".....

but not this format:
"1",
"2",
"3"

i try to loop through the array and store in a single string b4 write to file, but the output is not what I want...
"1,2,3,4,".....

I am using the write# function. any better suggestions? any idea to get the ideal output?
Thanks in advance.
0
Comment
Question by:joyceooi
  • 3
5 Comments
 
LVL 14

Accepted Solution

by:
Farzad Akbarnejad earned 50 total points
ID: 11889717
Hi,

Private Sub Command1_Click()
    Dim i As Integer
    Dim a(10) As Integer
    Dim s(10) As String
   
    Dim filename As String
   
    filename = App.Path & "\file.txt"
   
    For i = 1 To 10
        a(i) = i
        s(i) = Mid(Str(a(i)), 2)
    Next i
   
    Open filename For Output As #1
   
    For i = 1 To 10
        Write #1, s(i);
    Next i
   
    Close #1
End Sub

The point is using ; after  write #1  statement to be in one line.

-FA
0
 
LVL 7

Expert Comment

by:_agj_
ID: 11889757
Use the Print #1, Yourstring

0
 

Author Comment

by:joyceooi
ID: 11889786
Thanks FA
it works...
but there is an extra "," after the last data
0
 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 11889804
   For i = 1 To 10
        If i <> 10 Then
            Write #1, s(i);
        Else
            Write #1, s(i)
        End If
    Next i


-FA
0
 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 11889813
Or it is better:

    For i = 1 To 9
        Write #1, s(i);
    Next i
    Write #1, s(i)
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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

896 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

11 Experts available now in Live!

Get 1:1 Help Now