Solved

Text file

Posted on 1998-06-07
4
132 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
Comment Utility
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
Comment Utility
Can you write a code?
0
 

Author Comment

by:gima
Comment Utility
vamsi_k
Can you write a vb code?
0
 

Expert Comment

by:vamsi_k
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

772 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

14 Experts available now in Live!

Get 1:1 Help Now