By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,980 Members | 937 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,980 IT Pros & Developers. It's quick & easy.

Don't save the emty lines, or not to open them?

P: n/a
I have a text file that I want to save from my program. But I don't want to
save the empty lines. I want to delete everything after the last character,
Is that possible?

Then when I read the text file i don't want to read empty lines(If the user
as edit the file in notpad..), sense it makes commas at all new lines and
then split the text at every comma in to an array.
The array will contain empty "slot's" if there is a lot of commas in a raw
(like it will be if there is many empty lines at the end/beginning of the
file)

This is the text file:

http://www.google.com,Google
http://www.dustin.se,Dustin
http://www.Microsoft.com,Microsoft

Yours, Jonas
Jul 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"BadOmen" <ba*******@hotmail.com> wrote in message news:<ex********************@newsb.telia.net>...
I have a text file that I want to save from my program. But I don't want to
save the empty lines. I want to delete everything after the last character,
Is that possible?

Then when I read the text file i don't want to read empty lines(If the user
as edit the file in notpad..), sense it makes commas at all new lines and
then split the text at every comma in to an array.
The array will contain empty "slot's" if there is a lot of commas in a raw
(like it will be if there is many empty lines at the end/beginning of the
file)

This is the text file:

http://www.google.com,Google
http://www.dustin.se,Dustin
http://www.Microsoft.com,Microsoft

Yours, Jonas


Your description is somewhat vague, but if you want to just save the
web pages/bookmarks, then you could do something like read the value
into a string, use Trim$() to remove any blank spaces on either end,
use InStr() to look for the characters you want to remove...
Something like

Left$(strWebAddress,InStr(1,strWebAddress,",")-1)

Then you'd be left with just the address... and once you have that,
you can write it to another text file and then kill the original when
you're done.
Jul 17 '05 #2

P: n/a
I didn't really get it to work, I tried it as simple as this:
tmpShow = Trim$(txtShow.Text)

txtShow is a TextBox with just two words "Hi there" And then I pressed the
Enter button three times and saved it but when I open it the empty lines are
still there, in fact the save function adds an empty line to the text file.
Even if the file did not have an empty line at the end, this function will
give the file an empty line...Even if I skip the Trim$().

Can I use Trim$(txtShow.Text) to do this?
Way does it add an Empty Line at the and with or without the Trim$()??
Dim tmpShow As String
Dim ToSave As String '*** Is set by the open file function.

Private Sub cmdSave_Click()

Dim FileNum As Long
FileNum = FreeFile
tmpShow = Trim$(txtShow.Text)

Open ToSave For Output As #FileNum

Print #FileNum, tmpShow

Close #FileNum

End Sub

Yours, Jonas

"Pieter Linden" <pi********@hotmail.com> skrev i meddelandet
news:bf*************************@posting.google.co m...
"BadOmen" <ba*******@hotmail.com> wrote in message

news:<ex********************@newsb.telia.net>...
I have a text file that I want to save from my program. But I don't want to save the empty lines. I want to delete everything after the last character, Is that possible?

Then when I read the text file i don't want to read empty lines(If the user as edit the file in notpad..), sense it makes commas at all new lines and then split the text at every comma in to an array.
The array will contain empty "slot's" if there is a lot of commas in a raw (like it will be if there is many empty lines at the end/beginning of the file)

This is the text file:

http://www.google.com,Google
http://www.dustin.se,Dustin
http://www.Microsoft.com,Microsoft

Yours, Jonas


Your description is somewhat vague, but if you want to just save the
web pages/bookmarks, then you could do something like read the value
into a string, use Trim$() to remove any blank spaces on either end,
use InStr() to look for the characters you want to remove...
Something like

Left$(strWebAddress,InStr(1,strWebAddress,",")-1)

Then you'd be left with just the address... and once you have that,
you can write it to another text file and then kill the original when
you're done.

Jul 17 '05 #3

P: n/a
"BadOmen" <ba*******@hotmail.com> wrote
I didn't really get it to work, I tried it as simple as this:
tmpShow = Trim$(txtShow.Text)

txtShow is a TextBox with just two words "Hi there" And then I pressed the
Enter button three times and saved it but when I open it the empty lines are
still there, in fact the save function adds an empty line to the text file.
Even if the file did not have an empty line at the end, this function will
give the file an empty line...Even if I skip the Trim$().

To get an idea of what VB is doing, you need to do these kinds of
experiments. But often you can simply read the help file to become informed
about why things happen. When you have trouble with a command, put
the cursor on it in the code window, and press F1. That should take you
directly to the command which you should then read and understand. Also
take note of what is supplied in the See Also links. Do this until you know
what the help file contains about the commands you need help with.

Keep in mind there are still commands I check the help files on, and I have
been at it since 1995. There is nothing wrong, even, with checking help to
verify the proper syntax and use....

Can I use Trim$(txtShow.Text) to do this?
No, Trim is for removing spaces.
Way does it add an Empty Line at the and with or without the Trim$()??


Because you tell it to. Follow the Print command with a semi-colon as
indicated in help. Print #f, "Whatever";

You know the user is capable of editing the file, so you really should
deal with these anomolies when you read the file. You have to write that
code as if you don't know what is in the file because the user can add
whatever they want. It is also a good idea to provide for comments in
case the user wants to add comments to the file. A simple test of the
first character of the string for a comment character would be simple
enough to incorporate....

Good luck!
LFS

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 17 '05 #4

P: n/a
the easiest way to get rid of empty lines (provided that they are really
empty - and that the eol code is vbcrlf) is to use Replace and look for
double vbcrlf's :

text = replace(text, vbcrlf & vbcrlf, vbcrlf)

you may have to loop a few times to get rid of multiple line spaces

swr

"Larry Serflaten" <Ab***@SpamBusters.com> wrote in message
news:40********@corp.newsgroups.com...
"BadOmen" <ba*******@hotmail.com> wrote
I didn't really get it to work, I tried it as simple as this:
tmpShow = Trim$(txtShow.Text)

txtShow is a TextBox with just two words "Hi there" And then I pressed the Enter button three times and saved it but when I open it the empty lines are still there, in fact the save function adds an empty line to the text file. Even if the file did not have an empty line at the end, this function will give the file an empty line...Even if I skip the Trim$().

To get an idea of what VB is doing, you need to do these kinds of
experiments. But often you can simply read the help file to become

informed about why things happen. When you have trouble with a command, put
the cursor on it in the code window, and press F1. That should take you
directly to the command which you should then read and understand. Also
take note of what is supplied in the See Also links. Do this until you know what the help file contains about the commands you need help with.

Keep in mind there are still commands I check the help files on, and I have been at it since 1995. There is nothing wrong, even, with checking help to verify the proper syntax and use....

Can I use Trim$(txtShow.Text) to do this?


No, Trim is for removing spaces.
Way does it add an Empty Line at the and with or without the Trim$()??


Because you tell it to. Follow the Print command with a semi-colon as
indicated in help. Print #f, "Whatever";

You know the user is capable of editing the file, so you really should
deal with these anomolies when you read the file. You have to write that
code as if you don't know what is in the file because the user can add
whatever they want. It is also a good idea to provide for comments in
case the user wants to add comments to the file. A simple test of the
first character of the string for a comment character would be simple
enough to incorporate....

Good luck!
LFS

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----

Jul 17 '05 #5

P: n/a
> the easiest way to get rid of empty lines (provided that they are really
empty - and that the eol code is vbcrlf) is to use Replace and look for
double vbcrlf's :

text = replace(text, vbcrlf & vbcrlf, vbcrlf)

you may have to loop a few times to get rid of multiple line spaces


Correct, to be sure, you have to loop... the above code will only remove one
blank line from three blank lines in a row (Replace is not recursive, so it
won't make use of the collapse blank line it formed from two adjacent blank
lines on a third adjacent blank line). The loop is simple though...

Do While InStr(text, vbCrLf & vbCrLf)
text = Replace$(text, vbCrLf & vbCrLf, vbCrLf)
Loop

Rick - MVP
Jul 17 '05 #6

P: n/a
Sorry that my responds took so long...

Thanx, I will use that so my Array cant be just empty lines :)

Yours, Jonas
"Rick Rothstein" <ri************@NOSPAMcomcast.net> skrev i meddelandet
news:b5********************@comcast.com...
the easiest way to get rid of empty lines (provided that they are really
empty - and that the eol code is vbcrlf) is to use Replace and look for
double vbcrlf's :

text = replace(text, vbcrlf & vbcrlf, vbcrlf)

you may have to loop a few times to get rid of multiple line spaces
Correct, to be sure, you have to loop... the above code will only remove

one blank line from three blank lines in a row (Replace is not recursive, so it won't make use of the collapse blank line it formed from two adjacent blank lines on a third adjacent blank line). The loop is simple though...

Do While InStr(text, vbCrLf & vbCrLf)
text = Replace$(text, vbCrLf & vbCrLf, vbCrLf)
Loop

Rick - MVP

Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.