Results 1 to 5 of 5

Thread: [RESOLVED] Why does my code not read-in a complete text file ?

  1. #1

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Resolved [RESOLVED] Why does my code not read-in a complete text file ?

    Hi,

    I'm trying to make a test tool to check for errors in a module, (Wordz.vb) the file is huge (1,186Kb) but starts like this:

    Module Wordz

    Public WordX() As String = {"ad", "ah", "am", "an", "as", "at", "au", "aw", "ax", "ay", "be", "bi", "by", "do", "ed",
    "eh", "el", "en", "ex", "go", "he", "hi", "ho", "id", "if", "in", "is", "it", "la", "lo", "ma", "me", "mi", "mu", "my",
    "no", "of", "oh", "ok", "on", "op", "or", "ox", "oz", "pa", "pi", "re", "se", "so", "to", "uh", "um", "up", "us", "we",
    "ye", "yo", "ace", "act", "add", "ado", "ads", "adz", "aft", "age", "ago", "aha", "aid", "ail", "aim", "ain", "air", "ala",
    And finishes like this:
    "american english coonhound", "central asian shepherd dog", "german shorthaired pointer",
    "greater swiss mountain dog", "irish red and white setter", "portuguese podengo pequeno", "staffordshire bull terrier",
    "turkish vana rolling stone", "australian shepherd lab mix", "small munsterlander pointer", "soft coated wheaten terrier",
    "west highland white terrier", "wirehaired pointing griffon", "boston terrier pekingese mix", "petit basset griffon vendeen",
    "bavarian mountain scent hound", "cavalier king charles spaniel", "american staffordshire terrier", "german shepherd rottweiler mix",
    "australian shepherd pit bull mix", "australian stumpy tail cattle dog", "nova scotia duck tolling retriever"}
    End Module
    My plan is to read-in the module to a string, remove everything outside the first and last quotes ("), which I think will just leave me with a string which I can check for missing commas, quotes, spaces etc.

    I'm trying to read it all with this code:
    vb.net Code:
    1. Public Class Form1
    2.  
    3.     ReadOnly filePath As String = "D:\Visual Studio Projects\Projects\CrossWord\CrossWord\Wordz.vb"
    4.  
    5.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    6.         Dim inpt, wrds As String
    7.         FileOpen(1, filePath, OpenMode.Input)
    8.         While Not EOF(1)
    9.             inpt = LineInput(1)
    10.             If inpt.Contains("{") Then inpt = inpt.Substring(InStr(inpt, "{"))
    11.             If inpt.Contains("}") Then inpt = inpt.Substring(0, InStr(inpt, "}") - 1)
    12.             If inpt.Contains(Chr(34)) Then wrds &= inpt
    13.         End While
    14.  
    15.     End Sub
    With a breakpoint at line 15, I can see that the file is not complete, it only gets as far as ' "american english '.

    I don't understand why this should be.


    Poppa
    Last edited by Poppa Mintin; Apr 2nd, 2021 at 08:44 AM. Reason: typo
    Along with the sunshine there has to be a little rain sometime.

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Re: Why does my code not read-in a complete text file ?

    Try using one of the ReadAll methods in
    https://docs.microsoft.com/en-us/dot...e?view=net-5.0
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: Why does my code not read-in a complete text file ?

    Thanks Dbasnett,

    I realised what was wrong...
    I forgot that the module text was broken into hundreds of lines and that I needed a List not a String.
    Change Line 6 to : 'Dim inpt As String, wrds As New List(Of String)'
    Change Line 12 to: 'If inpt.Contains(Chr(34)) Then wrds.Add(inpt)'

    Now I get the whole thing, also, the original string would've been wrong anyway because there would've been no space character where one line ends and the next starts.

    Problem solved.


    Poppa
    Along with the sunshine there has to be a little rain sometime.

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: [RESOLVED] Why does my code not read-in a complete text file ?

    You're using legacy code again, and to be honest it's more difficult using that code, than using readalltext to read the entire file into a string...

  5. #5

    Thread Starter
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    Re: [RESOLVED] Why does my code not read-in a complete text file ?

    Quote Originally Posted by .paul. View Post
    You're using legacy code again, and to be honest it's more difficult using that code, than using readalltext to read the entire file into a string...
    Thanks .Paul,

    Yeah, that's the trouble with being ancient, to be honest I expect I'm still thinking BASIC rather then Visual Basic, or maybe just VB version 3.0.

    You can't teach an old dog new tricks, not even an old sea dog !

    Poppa
    Along with the sunshine there has to be a little rain sometime.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width