?
Solved

Text file

Posted on 1998-06-07
4
Medium Priority
?
138 Views
Last Modified: 2010-05-03
How Can I delete an Empty line in Vb  from an open text file?
0
Comment
Question by:gima
[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
  • 2
  • 2
4 Comments
 

Accepted Solution

by:
vamsi_k earned 40 total points
ID: 1462707
Actually, the solution is that, after  opening the text file, through VB code, we can call the  complete line at a time.  So, in a loop, call each line, find out its length.  In another loop, within this loop, check for each character of this line, and if it is null till u reached the line break character, then ignore this line, else, put this line in another file, which u have to open to write output.

Hope u go the point, what I said.  If u have more doubts, let me know.
0
 

Author Comment

by:gima
ID: 1462708
Can you write a code?
0
 

Author Comment

by:gima
ID: 1462709
vamsi_k
Can you write a vb code?
0
 

Expert Comment

by:vamsi_k
ID: 1462710
Try the following code :

Dim sFileName as String 'source file
Dim iFileName as Integer
Dim dFileName as String ' destination file
Dim oFileName as Integer

iFileName = FreeFile
oFileName = FreeFile

sFileName = "Path where your text file is located"
dFileName = "Path of file where to send the contents"

Open sFileName For Input As #iFileName
Open dFileName For Output As #oFileName

Do While Not EOF(iFileName)
str = ""
   Line Input #iFileName sData 'Here sData contains the line of text
   LineLen = Len(sData)
   For i = 1 to LineLen
       str[i] = ""
   Next i
   If (sData <> str) Then
      Print #oFileName, sData
   End If  
Loop

Close #iFileName
Close #oFileName

End Sub

Note: I am describing here what the code does.  Opening two files, one for reading input from and the other for writing the contents.  The paths have to be specified in the code where it is meant for.  In the Do loop, it is calling each line, finding its length, and in the for loop, it is assigning null upto the number of characters the line contains, and compares if these two strings are equal, i.e., sData and str.  If they are not equal, then place this line into the output file, else ignore that.

You may have to make little modifications here and there, because I wrote this code directly, and did not try it out using VB.  But this will work, and should work.

If You have any doubts or problems contact me.

 
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

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