Saving String Data that may include a carriage return

Posted on 2011-04-20
Last Modified: 2013-12-25
I use the following code to write data to a file opened for Append
       Write #F, SerialNo; fn; fs, fb; fi; fu; ft; tc; tb; n; TDNtext; SaveFlag
The variable TDNtext is a string read from a TextBox control (Multiline = True).
My problem is that if the user uses a carriage return in the text he is entering this seems to function as an end / new record when the data is written to file.
I can see one way around this by use of a Rich Text Box in place of a normal text box, but I want to avoid that if at all possible
Question by:BigOldDog
    LVL 85

    Accepted Solution

    One solution is to replace vbCrLf with something else that won't appear in the TextBox.  You could use an unlikely sequence like "|*|*|vbCrLf|*|*|.  Just change it back after you read it from the file.
    LVL 16

    Expert Comment

    I don't understand how a Rich Text Box is going to help you.  If the Rich Text Box is Multiline, you're still going to get a CrLf pair between lines.

    What are your constraints?  Do your records need to account for line breaks that were in the original text box?  If so, then I would say that "Replace vbCrLf with something else" is not "one solution", but the ONLY solution since a "Record" in your data file appears to be deliniated by new lines.

    Author Closing Comment

    Works fine in VB6 but I do not think that this command exists in VB5. I am just migrating from 5 to 6 so that's not a problem.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
    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…

    779 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

    19 Experts available now in Live!

    Get 1:1 Help Now