Jump to content

Help with code.... ignoring blank lines and lines starting with a *


dan_g8

Recommended Posts

Hi, as above really, i have written the below code which ignores some of the blank lines lines starting with a * but not all of them.

 

can anyone see whats wrong with my code, it only ignores about half of the items??

 

 

       Dim FILE_NAME As String = "C:\test.dat"
       Dim RES As Boolean
       Dim TextLine() As String
       Dim i As VariantType
       Dim TEMPLINE As String

       i = 0

       If System.IO.File.Exists(FILE_NAME) = True Then

           Dim objReader As New System.IO.StreamReader(FILE_NAME)

           Do While objReader.Peek() <> -1
               TEMPLINE = objReader.ReadLine()

               Dim length As Integer = TEMPLINE.Length

               RES = TEMPLINE.StartsWith(Chr(42))
               If (CStr(RES)) = False Then
                   i = i + 2
                   ReDim Preserve TextLine(0 To i)
                   TextLine(i) = objReader.ReadLine()
                   MsgBox(TextLine(i))
                   'End If
               End If
           Loop



       Else

           MsgBox("File Does Not Exist")

       End If

Link to comment
Share on other sites

forgot to say vb.net visual studio 2010

 

Thank you! :thumbsup:

 

 

 

can anyone see whats wrong with my code, it only ignores about half of the items??

 

Well... It is not written in C#. :rofl: *kidding*

 

In all seriousness, can you post a sample .DAT file for us to test?

 

Cheers

Link to comment
Share on other sites

Like BB said a sample DAT file would be most helpful.

 

I had a similar problem a good while ago and the problem turned out to be the DAT not the code. I was getting the DAT from a third party piece of software and for some reason it was sometimes putting a space at the beginning of just some lines which was causing me all kind of problems. A simple TRIM function on the input string sorted it all out.

 

Have you tried using ("*") instead of (Chr(42))

 

Ben

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...