Solved

Text file

Posted on 1998-06-07
4
133 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now