Solved

Text file

Posted on 1998-06-07
4
135 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
  • 2
  • 2
4 Comments
 

Accepted Solution

by:
vamsi_k earned 20 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

821 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