[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 142
  • Last Modified:

Text file

How Can I delete an Empty line in Vb  from an open text file?
0
gima
Asked:
gima
  • 2
  • 2
1 Solution
 
vamsi_kCommented:
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
 
gimaAuthor Commented:
Can you write a code?
0
 
gimaAuthor Commented:
vamsi_k
Can you write a vb code?
0
 
vamsi_kCommented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now