Re: Extra zeroes at EOF when Inputing numbers in a NotePad file.txt into a VB program.

Hi All,

It sure looks like I am picking up unwanted carriage control or other non viewable characters as a zero or as two zeroes, when I enter a list of numbers (a sample) using NotePad and then read and print ("echo") the data in a Visual Basic program, using the steps and VB code described below.

OpenNotePad & enter a list of numbers separated by spaces, & Save as "SampleData.txt"
That is, NotePad file looks like:

12.0 13.4 23.0 47.1
11.8 23.4 26.7 91.8

Save above file if numbers. Then go to Visual Basic 6, open a program with the code below associated with a command button, run the program, click on the command button to read & echo the data:

Private Sub cmdBegin_Click()
Dim x As Single ' x is a sample observation
Open App.Path & "/SampleData.txt" For Input As #1
Do While Not EOF(1)
Input #1, x
picSample.Print x
Loop ' Do While Not EOF(1)
Close #1
End Sub

That is, when I view the NotePad file, I see the sample points up to the last number, but no zeroes. When I read & print the NotePad file, two zeroes appear on the Visual Basic picture box where the sample points are printed.

I am not above or beyond some how mistakenly including a print of undeclared (via Dim .. etc.) erroneous variable with a default value of zero, but have checked & double checked & see nothing like this. And reading and echoing data simply is not that complicated, as the above programming shows. Hence am pulling my hair out over this, but that's not helping either.

So where are these phantom zero(es) coming from?

Will appreciate any help on this!


Jay Weber

This is because VB6 calculates the ENTIRE number. Use format to get to only 2 decimals etc -

picSample.Print Format (x, "### ##0.00")

My apologies, added, change your statement of -

Dim x As Single ' x is a sample observation

to -

Dim x As Integer' x is a sample observation
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.