[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Write array to text file in a single line

Posted on 2004-08-24
5
Medium Priority
?
193 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
[X]
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
  • 3
5 Comments
 
LVL 14

Accepted Solution

by:
Farzad Akbarnejad earned 150 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…
Suggested Courses

656 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