Smart questions
Smart answers
Smart people
Join Tek-Tips Forums
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Removing a empty line from a Text fileHelpful Member! 

Howlingmad (IS/IT--Management) (OP)
31 Dec 04 4:46
Can some one help me?  Im using VBscript to remove a Character from a Text file (see below script).  The problem i have is that when the character is removed the line it was on remains, which mean there is a gap in the text.  Is there anyway i can remove then empty line?

Const ForReading = 1
Const ForWritting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutputFile = objFSO.CreateTextFile("C:\Tolisbon\output.txt")

Set objTextFile = objFSO.OpenTextFile("c:\emigrants\btd04.dat", ForReading)

strText = objTextFile.ReadAll
strText = Replace(strText, "", "")
objTextFile.Close
objOutputFile.WriteLine strText

Set objTextFile = objFSO.OpenTextFile("C:\Tolisbon\btd04.txt ", ForReading)

strText = objTextFile.ReadAll
objTextFile.Close
objOutputFile.WriteLine strText

objOutputFile.Close
tsuji (TechnicalUser)
31 Dec 04 5:28
Hello Howlingmad,

May be a bit shaky... try this?

strText = objTextFile.ReadAll
strText = Replace(strText, "", "")
strText = Replace(strText, vbcrlf & vbcrlf, vbcrlf)

regards - tsuji
tsuji (TechnicalUser)
31 Dec 04 5:44
Further notes:

Maybe this is more correct?

strText = objTextFile.ReadAll
strText = Replace(strText, "" & vbcrlf, "")

- tsuji
Howlingmad (IS/IT--Management) (OP)
31 Dec 04 6:19
Thanks for replying tsuji, but this doesnt appear to work
tsuji (TechnicalUser)
31 Dec 04 6:26
howlingmad,

First, why the character appear at all? Is it due to wrong setting of opentextfile with default format ascii on a unicode text file?

Second, linefeed and carriage-return may not always be use as vbcrlf, may well be vblf, or vblf & vbcr or whatever...

So to see what's going on, display the whole .readall in escaped form. Then, you can read out what's happening.
    wscript.echo escape(strText)
or if it is too big, write it out to some file. No need to speculate/imagine further.

- tsuji
Howlingmad (IS/IT--Management) (OP)
31 Dec 04 6:42
The character is a stop character for a BAC's file.  If a file wasnt sent the day before i need the program to combine the two files remove the stop character.  Which what i got at the moment does.  It just leaves that pesky empty line which means the file isnt read properly.
MakeItSo (Programmer)
4 Jan 05 9:47
Hi Howlingmad,

the box character only says: cannot display this. You cannot search for it like that.
You need to replace the respective ASCii value. I suggest, you open the file in an editor with hex view and find out the character value. Then:

strText = objTextFile.ReadAll
strText = Replace(strText, chr(whatevercode) & vbcrlf, "")

Hope this helps.

Regards,
Andy

An eye for an eye only ends up making the whole world blind. - "Mahatma" Mohandas K. Gandhi

Helpful Member!  cornboy88 (Programmer)
5 Jan 05 7:50
try this:

CODE

Const ForReading = 1
Const ForWritting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutputFile = objFSO.CreateTextFile("C:\Tolisbon\output.txt")

Set objTextFile = objFSO.OpenTextFile("c:\emigrants\btd04.dat", ForReading)


Do While objTextFile.AtEndOfStream <> True
    strText = objTextFile.ReadLine
          if strText = chr(127) then
    else
        objOutputFile.WriteLine strText
    end if
    
   Loop

objTextFile.Close

Set objTextFile = objFSO.OpenTextFile("C:\Tolisbon\btd04.txt ", ForReading)

strText = objTextFile.ReadAll
objTextFile.Close
objOutputFile.WriteLine strText

objOutputFile.Close
Howlingmad (IS/IT--Management) (OP)
5 Jan 05 8:38
Thanks very much Cornboy88 it worked Perfectly after i changed chr(127) to ""

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close