Solved

Writing to a text file

Posted on 2006-11-22
2
195 Views
Last Modified: 2010-04-30
Hi,
I am trying to write a string to a text file.  I am using:
WriteLine(1, strgName)
Is there another way to write a string to a text file without the parenthesis showing?
Each strgName is supposed represent a data record, so I would to ensure a CR is present also.
Any help would be appreciated.
0
Comment
Question by:VBStudent
2 Comments
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 17997796
WriteLine 1, strgName

As long as you have a space after the WriteLine you should be fine.

If you want CR before the 1 and or anything else then just add it in.

Im assuming that the strgName is a variable which you have not shown us and that 1 is a numerical value, if you want the 1 to be a string then just put "" around it ie "1"

As for the CR, I think you will have to have quotes around that since it is a string.

Maybe you can show us how you want this to be displayed when it is written to the text file and also what strgName is etc
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 17998025
This will write an array as text lines to a file:

Sub WriteFile(strArray() As String)
    Dim f As Integer
    Dim i As Integer
   
    f = FreeFile
    Open "C:\MyPath\MyFile.txt" For Output As #f
        For i = 0 To UBound(strArray)
            Print #f, strArray(i)
        Next i
    Close #f
End Sub

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 In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…

867 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

20 Experts available now in Live!

Get 1:1 Help Now