Solved

Write array to text file in a single line

Posted on 2004-08-24
5
189 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

733 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