-
Apr 2nd, 2021, 07:51 AM
#1
Thread Starter
PowerPoster
[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:
Public Class Form1
ReadOnly filePath As String = "D:\Visual Studio Projects\Projects\CrossWord\CrossWord\Wordz.vb"
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim inpt, wrds As String
FileOpen(1, filePath, OpenMode.Input)
While Not EOF(1)
inpt = LineInput(1)
If inpt.Contains("{") Then inpt = inpt.Substring(InStr(inpt, "{"))
If inpt.Contains("}") Then inpt = inpt.Substring(0, InStr(inpt, "}") - 1)
If inpt.Contains(Chr(34)) Then wrds &= inpt
End While
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.
-
Apr 2nd, 2021, 08:13 AM
#2
Re: Why does my code not read-in a complete text file ?
-
Apr 2nd, 2021, 08:41 AM
#3
Thread Starter
PowerPoster
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.
-
Apr 3rd, 2021, 05:27 AM
#4
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...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 3rd, 2021, 05:40 AM
#5
Thread Starter
PowerPoster
Re: [RESOLVED] Why does my code not read-in a complete text file ?
Originally Posted by .paul.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|