1. ## [RESOLVED] Problem to read minimum value of input file

I have a program to read 5000 points of xyz coordinates. I'm using the code below to read and calculate the minimum and maximum value of the coordinates but the code doesn't seems to give the correct output. It didn't display the correct xmin and ymin. Can anybody help to see what wrong with the code or maybe suggest a better way to do this? Thanks a lot VB Code:
```npnt = 1
Open "c:\PSM\Data\pnt.dat" For Input As #1
Input #1, Point.X, Point.Y, Point.Z
xmin = Point.X
ymin = Point.Y
xmax = Point.X
ymax = Point.Y
infolist.AddItem "Calculating min and max xy..."
'Loop to read every line of points
While Not EOF(1)
Input #1, Point.X, Point.Y, Point.Z
If (xmin > Point.X) Then
xmin = Point.X
End If
If (ymin > Point.Y) Then
ymin = Point.Y
End If
If (xmax < Point.X) Then
xmax = Point.X
End If
If (ymax < Point.Y) Then
ymax = Point.Y
End If

npnt = npnt + 1

Wend```  Reply With Quote

2. ## Re: Problem to read minimum value of input file

i've tried ur codes and it worked just well..to be sure, sort the data using MS excel...however, i've tried to compare it when i wrote it again using c++ codes and the result are slightly different. I think thats because in c++, it eliminates the embedded values..Ur codes are good though, nothing's wrong there.  Reply With Quote

3. ## Re: Problem to read minimum value of input file

Thanks for your ideas. I tried to read the points in C++ and compares the xmin and ymin values. You're right, the points was truncated. So, that's mean the vb code is ok and I don't need to worry about the result. Actually, I try to translate a c++ code into vb, and the way I wrote the code is actually the same way as the cpp code. I just wonder why the result is not the same as vb does. Here's the code I wrote in cpp

Code:
```   // reads the file header
XYZfile >> charX >> charY >> charZ;

npnt = 1;
XYZfile >> Point.x >> Point.y >> Point.z;

// to calculate min xy, max xy
xmin = Point.x;
ymin = Point.y;
xmax = Point.x;
ymax = Point.y;

do
{
printf("\r");
cout << "Reading points ... " << npnt;

XYZfile >> Point.x >> Point.y >> Point.z;
if (xmin > Point.x)
xmin = Point.x;

if (ymin > Point.y)
ymin = Point.y;

if (xmax < Point.x)
xmax = Point.x;

if (ymax < Point.y)
ymax = Point.y;
npnt ++;
} while (! XYZfile.eof());

xlength = xmax - xmin;
ylength = ymax - ymin;
maxpnt = npnt - 1;
XYZfile.close();
getch();
}```  Reply With Quote

4. ## Re: Problem to read minimum value of input file

as i said, i also wrote it in c++ to compare it with ur vb codes and the results is slightly different..i've tried it using the dataset that u've provided..i dont know what datatype did u used but i used Double..even though both in vb and c++ the variables type is double, but still in c++ it truncated the embedded values..but when u sort the dataset using MS excel, the results is the same as in vb..so in my opinion, the result in vb code is the accurate 1..maybe other people have other opinion..  Reply With Quote

5. ## Re: Problem to read minimum value of input file

Thanks a lot pal   Reply With Quote

#### Posting Permissions

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