Solved

Write array to text file in a single line

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

760 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

23 Experts available now in Live!

Get 1:1 Help Now