Solved

Parsing a file

Posted on 1998-10-14
2
131 Views
Last Modified: 2010-04-30
Hi,
   I need to be able to parse a file so that it adds four charactors to the end of each line as it stores the file into a variable named CTEXT... any ideas?

Kind Regards,
Rob Green.
0
Comment
Question by:robjgreen
2 Comments
 
LVL 3

Accepted Solution

by:
traygreen earned 60 total points
Comment Utility
If the file has carriage return/line feed characters in it(or any other identifiable line delimiter character in it) you can run through the file one character at a time.  You can build the output string as you go and replace or append the four characters everytime you hit the delimiter character.

eg.

const cAPPEND_CHARS = "1234"
Dim Char
dim CText as string
 
Open "FILE" For Input As #1      ' Open file.
Do While Not EOF(1)      ' Loop until end of file.
  Char = Input(1, #1)      ' Get one character.
  if asc(Char)<> 13     ' cr/lf
     CText = CText & Char
  else
     CText = CText & cAPPEND_CHARS
  end if      
Loop
Close #1      ' Close file.
0
 

Author Comment

by:robjgreen
Comment Utility
I actually cracked it before you sent the reply, but thanks for replying so quickly anyway :o)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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 …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

771 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

9 Experts available now in Live!

Get 1:1 Help Now