473,327 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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

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
6 3519
"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
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
"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
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
> 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Andras Gilicz | last post by:
Hi VB fans I'm working on a relatively large project in VB6 with about a dozen forms, including graphs, labels, text boxes, etc. The software itself is actually a flow simulator with more or...
303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
22
by: Ling Lee | last post by:
Hi all. I'm trying to write a program that: 1) Ask me what file I want to count number of lines in, and then counts the lines and writes the answear out. 2) I made the first part like this: ...
6
by: Mike | last post by:
can i open the save file dialog box from a asp.net web page? thx
19
by: LP | last post by:
I am using (trying to) CR version XI, cascading parameters feature works it asks user to enter params. But if page is resubmitted. It prompts for params again. I did set...
6
by: Michael Groeger | last post by:
Hi, I have an aspx page which generates an excel document and transfers it to the browser as attachment. Normally, once the document is transferred the open save dialog prompts to open or save...
4
by: Jonny | last post by:
Hello Group How do I open a Save File Dialog from an ASPX page behind a browse button? Any help would be fantastic!! I am using ASP.NET 1.1 using VB.NET as the coding language TIA
0
by: Vader | last post by:
I am new to this forum. Thanks in advance for and help. The following is what I am looking for: 1. I need help with VB code to open a MS Word (.doc) file. 2. Read lines from the MS Word (.doc)...
3
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have a question for you. I have a .csv file which has many lines of data. Each line has many data fields which are delimited by ",". Now I need to extract part of data from this...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.