Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

file manipulation

Posted on 2000-02-17
12
Medium Priority
?
167 Views
Last Modified: 2010-05-02
i need to take the trailing empty line from a text file...how do i do this?

also, how do you write to a text file without writing an end of line character?
0
Comment
Question by:Sesh
[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
  • 3
  • 2
  • +3
12 Comments
 
LVL 3

Expert Comment

by:paulstamp
ID: 2533956
Tried using the Trim$ function to remove blanks ?
0
 
LVL 12

Expert Comment

by:roverm
ID: 2534019
Tried the Open statement yet ?

Open "inputfile" For Input As #1
Open "outputfile" For Output As #2

Input #1, strReadLine
'do some stuff
Print #2, strReadLine

Close #1
Close #2

When you read the input file you won't see the end-of-line char !

Good luck !

RoverM
0
 

Author Comment

by:Sesh
ID: 2534075
my problem actually arises from the inability to output a line without it creating an eoln at the end.

for example,
print %1,"hello"

would make the file like so:
--------beginning of file--------
hello(EOLN)
(EOF)
-----------end of file-------------

but i want it to read:
--------beginning of file--------
hello(EOF)
-----------end of file-------------
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:roverm
ID: 2534094
If you are writing AND reading the file why don't you add an 'END-CHAR' ?
When you read it again, YOU know that you can ignore the last character !

Another way: Instead of writing blanks (spaces) why don't you write Chr(0) a couple of times ?

RoverM
0
 
LVL 1

Expert Comment

by:macu
ID: 2534186
Just do:

Open "FileName" For Output As #X
Print #X, "Data";

The ; is the important part.
0
 
LVL 3

Expert Comment

by:Michelt
ID: 2536459
Have You tried to open the File as Binary, then read through the String to remove all the EOF Characters !
and Save it to a New File !


0
 
LVL 54

Expert Comment

by:nico5038
ID: 2538108
Sesh,

A DOS-text file contains normally two bytes to indicate the end of a line:
CarriageReturn and LineFeed. (CR / LF)
With the print statement these are inserted automatically.
When a file only contains LF's (normal for UNIX) it's seen by Notepad as one long string, however Wordpad shows it on different lines!.

To create a file yourself with control about the endofline character(s) you should follow Michelt advice to open the file as Binary and write the full lines with a concatenated vbCRLF variable at the end and "forget it" for the last one.

0
 

Author Comment

by:Sesh
ID: 2541499
hmmm... interesting..

does that:
print #X, data ;  take off the cr/lf from the print?? i havent got the dev studio at this moment (not at home at the moment), so cant test it...

i ended up doing a byte - by - byte get() and put() and testing for multiple eoln s, but would much rather use that print thingy
0
 
LVL 1

Accepted Solution

by:
macu earned 400 total points
ID: 2541544
Using the ; allows you to write something to a file and not move to a new line, so that more data can be added on the same line. It does work, very simple!
0
 

Author Comment

by:Sesh
ID: 2541554
ill take your word on it... thanx a lot!
0
 
LVL 1

Expert Comment

by:macu
ID: 2541570
No problem.
0
 
LVL 54

Expert Comment

by:nico5038
ID: 2543365
Sesh,

It does not take off the CR/LF, but it prevents the placement of it, as the ";" means 'more information has to be added to this string'
The only disadvantage can be that you end up with a string that's too long!
(Check the max string length of your VB version)
That's also why I advised to use the binary file type. Thus no length limit will appear!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

609 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