Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Write array to text file in a single line

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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 …
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…

856 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