Quantcast
Viewing all articles
Browse latest Browse all 27400

Same Project, different approach, different result.

Hi, I'm trying to go back to learn the basics of VB.NET as opposed to muddling on with my own, ancient, subset of VB code.

I have reached the section concerned with 'Text Files' and following this chapter have the following snippet of code:
vb.net Code:
  1. Dim FilePath As String = "C:\TmpTest\Place_Names.txt"
  2.       Dim Strg As String
  3.  
  4.       If System.IO.File.Exists(FilePath) Then
  5.          Dim oRead As New System.IO.StreamReader(FilePath)
  6.          Do While objRead.Peek <> -1
  7.             Strg = objRead.ReadLine
  8.             ListBox1.Items.Add(Strg)
  9.          Loop
  10.          objRead.Close()
  11.       Else
  12.          MsgBox("Can't find file " & FilePath)
  13.       End If

This works to a certain extent, but when I read the text in ListBox1, I find some characters have not been read-in correctly, it's true that some of them are accented characters but most frequently they are just a space (Chr 32) and all are usually replaced by ? (Chr 63).

Going back to my ancient subset, I re-wrote the code thus:
vb.net Code:
  1. Dim FilePath As String = "C:\TmpTest\Place_Names.txt"
  2.       Dim Strg As String
  3.  
  4.       If System.IO.File.Exists(FilePath) Then
  5.          FileOpen(1, FilePath, OpenMode.Input)
  6.          While Not EOF(1)
  7.             Strg = LineInput(1)
  8.             ListBox1.Items.Add(Strg)
  9.          End While
  10.          FileClose(1)
  11.       Else
  12.          MsgBox("Can't find file " & FilePath)
  13.       End If

Running this code produces no errors at all...

I think I've copied anything as instructed so I'm wondering why there are errors in the first results.


Poppa.

Viewing all articles
Browse latest Browse all 27400


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>