PDA

View Full Version : Range check error


Actor
07-29-2015, 08:06 PM
I've recently written a program that uses the BRIS comma delimited Single File. It works but about 3% of the time the program crashes with a "range check error." I've traced the problem to fields 846 .. 855 "BRIS Speed Rating." In my program this variable is an untyped integer. Using LibreOffice I've examined the data that causes the crashes. It seems to be caused because the BRIS Speed Rating goes negative. So I changed the variable to a signed integer. That should have cured the problem. It did not.

I've gotten around the problem by turning automatic range checking off. But the problem still bugs me (no pun intended). So does anyone have any ideas of how this problem might defy a cure. I've over and over my code and can find no reason that the problem should exist.

TonyMLake
07-29-2015, 09:57 PM
I've recently written a program that uses the BRIS comma delimited Single File. It works but about 3% of the time the program crashes with a "range check error." I've traced the problem to fields 846 .. 855 "BRIS Speed Rating." In my program this variable is an untyped integer. Using LibreOffice I've examined the data that causes the crashes. It seems to be caused because the BRIS Speed Rating goes negative. So I changed the variable to a signed integer. That should have cured the problem. It did not.

I've gotten around the problem by turning automatic range checking off. But the problem still bugs me (no pun intended). So does anyone have any ideas of how this problem might defy a cure. I've over and over my code and can find no reason that the problem should exist.

Could be several things. For one thing, brisnet does in fact have errors on occasion, just so you know. DRF Formulator has even more errors.

In any case, post your code.

Actor
07-30-2015, 12:39 AM
Could be several things. For one thing, brisnet does in fact have errors on occasion, just so you know. DRF Formulator has even more errors.

In any case, post your code.It's hundreds of lines but ...

846 .. 855 : past[i - 845].speed := abs(get_int(f)) ; // the offending line



function get_int (var f : text) : longint ; // read longint from comma delimited file
CONST
COMMA = ',' ;
var
ch : char ;
err : word ;
i : longint ;
str : string ;
begin // get_int
str := '' ;
repeat
read(f,ch) ;
if ch <> COMMA then
str := str + ch
until ch = COMMA ;
val(str, i, err) ;
if err = 0 then
get_int := i
else
get_int := 0
end ; // get_int

DLigett
07-30-2015, 01:14 PM
Not sure if you're using Delphi or some other version of Pascal. My versions of Delphi want 'err' to be an integer.

ebcorde
07-30-2015, 02:11 PM
Currently I'm using Java, used to use C++. I looked at my code, if it's happening I would have a zero, because I check for a value 0 or less and move on. I could be wrong took me 2 days to write.

Their file is horrendous. Like some kid's software generated the BRIS file.

why would it be a negative number?

A few months ago I noticed their Stud fee's are incorrect. I verified it by comparing the PP generator to my putput and has the same result. If you choose a race where the horses have the same sire. example Empire Maker, he'll have a stud fee for one horse and a stud fee of zero for the other. I called them pointed it out 3 months ago.. NO FIX.

ebcorde
07-30-2015, 02:27 PM
yes, it is possible to have a negative , I have seen it, but I roll it to 0. I dont think it's hurting me. usually I think it means the horse did not finish the race, Jockey fell off .

abs() if you have a -9 you make it a 9.

I guess a negative number means he was that bad? Still do not understand why they go below 0. In your case abs() on a -78 gives you a 78?

Also I believe their Jockey/Trainer combo at the meet and elsewhere are inaccurate, I've compared it to equibase and noticed it does not match up.
They probably have different rules. Equibase will start new stats. Example Mountaineer takes 2 months off and they zero the stats out. WTF
But I have not looked at that in a few years, so who knows maybe it's me.

DLigett
07-30-2015, 03:50 PM
Other things to check:

1) How is '.speed' defined -- can it accept values over 100?

2) How is past[] defined -- subscripts 1..10 or 0..9 or ???

3) What is i when the statement is executed?

4) If the file is a total mess, with 65535 characters before a comma, then 'str' can grow to be over 65535 characters -- and 'err' can't contain a number that large.

5) If the file is a total mess, what happens if you get to the end-of-file without finding a single comma?

What compiler are you using? Do you have a decent debugger?

TonyMLake
07-30-2015, 05:21 PM
Well, the first problem I MIGHT see is that the file is only looking for COMMA, but not looking out for double quotes.

Remember, the comma character does not ALWAYS indicate a new field... when a comma is inside double quotes it doesn't indicate a new field, and thus your field count would be off on the times that there was a sentence like "First time Lasix, under 121 add 2" (any text with a comma in it) preceding your target field because the comma inside the quotation marks... HOWEVER, this may not be a problem. It depends on how you're calling get_int.

Please post the line that calls "get_int".


Thanks

ebcorde
07-30-2015, 05:37 PM
but it's most likely your off by a comma thereby the data set has what appears to be much larger numbers.


I've never seen comma within a string yet, else my program would not be working, it works 99.9% of the time I wrote it 4 years ago. Too lazy to track Bris's mess ups.

when I did write it, they did not fill in data so your file WILL look like this ,,,,,,,, at various points.
there's no terminating character or 0 where a numeric is concerned so you have to check for a NULL after capturing data between the commas. Don't assume there's data there. You probably are already aware of that.

I don't know what language your using , if it's a PHP type language print out the contents of each field say after count 840 to see the contents.

Actor
07-30-2015, 08:53 PM
Not sure if you're using Delphi or some other version of Pascal. My versions of Delphi want 'err' to be an integer.It's Free Pascal. Err is supposed to be type word, i.e., unsigned integer.

Actor
07-30-2015, 09:14 PM
yes, it is possible to have a negative , I have seen it, but I roll it to 0. I dont think it's hurting me. usually I think it means the horse did not finish the race, Jockey fell off .

abs() if you have a -9 you make it a 9.

I guess a negative number means he was that bad? Still do not understand why they go below 0. In your case abs() on a -78 gives you a 78?-78 is bad. +78 may not be very bad depending on the company he's running with. That's why I'd rather use max(speed,0)

TonyMLake
07-30-2015, 09:31 PM
It's likely that it's not looking at the correct field based on the code you posted above. There are literally probably dozens of fields that could have a comma in them on occasion. At one quick glance I see fields 10, 162, 240 - 248, 396-405, and probably lots more wherein a comma MAY not mean a new field, and this is probably the issue.

There's a small possibility you're looking at the correct field when the error occurs and it really is a parsing problem, but that seems less likely... parsers are pretty good if it's "close enough" to a number.

But then, we don't know, so we should check by simply

remember to
uses
Dialogs;


then add
ShowMessage(str);

in your get_int function

So your code would look like


uses
Dialogs;

function get_int (var f : text) : longint ; // read longint from comma delimited file
CONST
COMMA = ',' ;
var
ch : char ;
err : word ;
i : longint ;
str : string ;
begin // get_int
str := '' ;
repeat
read(f,ch) ;
if ch <> COMMA then
str := str + ch
until ch = COMMA ;
val(str, i, err) ;
if err = 0 then
get_int := i
else
get_int := 0
ShowMessage(str)
end ; // get_int


Insert that, then run the app with a known BAD DRF file. Check to make sure what it displays does in fact look like the field you had in mind... I'm betting it's gonna be a blank field, or a text field, or somehow pointing at the wrong field - but even if I'm wrong we'll be able to take a look at what it's choking on.

Run that and let us know what happens....

ebcorde
07-30-2015, 09:34 PM
function get_int (var f : text) : longint ; // read longint from comma delimited file
CONST
COMMA = ',' ;
var
ch : char ;
err : word ;
i : longint ;
str : string ;
begin // get_int
str := '' ;
repeat
read(f,ch) ;

/****************************************
should only be ch 0-9 ans COMMA only if get_int
WHAT HAPPENS IF YOU PULL A COMMA IN WITHOUT LOADING STR?
*****************************/
if ch <> COMMA then
str := str + ch
until ch = COMMA ;
val(str, i, err) ;
if err = 0 then
get_int := i
else
get_int := 0
end ; // get_int


lots of ways to skin this cat
been years since I looked at pascal, but I see nothing wrong, BRIS file does inform you the maxmumn of each field , you could pass it in, in this cas field size max is 3. still think your somehow miscounting comma or some unseen control characters are in the file




this is how I did it in Java. before parsing the field. it's the same as what you did.

// DataBaseModule myDatabaseModule = new DataBaseModule("test","root","hollywood"," ");
//read comma separated file line by line
while( (strLine = br.readLine()) != null)
{
String[] tokens = strLine.split(","); // comma is the separator.
// System.out.println( java.util.Arrays.toString(tokens));
lineNumber++;
st = new StringTokenizer(java.util.Arrays.toString(tokens), ",", false);

while(st.hasMoreTokens())
{
tokenNumber++;
//System.out.println(tokenNumber + " " + lineNumber +" " + st.nextToken());
dc.fill(tokenNumber,lineNumber,st.nextToken());
}
tokenNumber = 0;
}

Actor
07-30-2015, 09:38 PM
Other things to check:

1) How is '.speed' defined -- can it accept values over 100?

type performance = record
date : string[8] ;
race : byte ;
speed : integer ;
// etc, etc
end ;

It's a signed integer -32768 .. 32767

2) How is past[] defined -- subscripts 1..10 or 0..9 or ???0 .. 10. 0 corresponds to today's race. Past[0].speed is always zero since it's not part of the file.

3) What is i when the statement is executed?846 .. 855

4) If the file is a total mess, with 65535 characters before a comma, then 'str' can grow to be over 65535 characters -- and 'err' can't contain a number that large.The string can only grow to a length of 255. Any attempt to make it larger is truncated. A string that large would cause err to be greater than zero and the error handling routine would cause get_int to return 0.

5) If the file is a total mess, what happens if you get to the end-of-file without finding a single comma?It's not happening. I once had a routine that would return a comma should eoln or eof be encountered but eventually decided it was not worth the trouble.

What compiler are you using? Do you have a decent debugger?Free Pascal. No.

TonyMLake
07-30-2015, 09:44 PM
Actor, we're just going to have to know the contents of "str" before the function returns.

See my snippet above.

EDIT: Oh.. and if it's choking BEFORE it returns, put the ShowMessage call before the parsing statement in get_int.

Like

until ch = COMMA ;
ShowMessage(str);
val(str, i, err) ;
if err = 0 then
get_int := i
else
get_int := 0

Actor
07-30-2015, 09:51 PM
Well, the first problem I MIGHT see is that the file is only looking for COMMA, but not looking out for double quotes.If that were the problem then val() would return a value of err that is greater than 0. Err would be the position of the double quote, an illegal character, in the string. The function would than return 0 which is not out of range.

Remember, the comma character does not ALWAYS indicate a new field... when a comma is inside double quotes it doesn't indicate a new field, and thus your field count would be off on the times that there was a sentence like "First time Lasix, under 121 add 2" (any text with a comma in it) preceding your target field because the comma inside the quotation marks... HOWEVER, this may not be a problem. It depends on how you're calling get_int.

Please post the line that calls "get_int".


Thanks

846 .. 855 : past[i - 845].speed := abs(get_int(f)) ; // the offending line

DLigett
07-30-2015, 09:57 PM
So if a comma or two is missing from the file, get_int() might return 999999 (longint) and try to stuff it into a simple integer?

I don't know the size of a longint in Free Pascal.

In get_int() you could test for size 32767 and squawk. Try on a known bad file.

vegasone
07-30-2015, 10:06 PM
One of the tracks, either EMD or EVD (I think) keeps coming up with a funky speed rating something like 1781 which may be causing your problem. I would have to run into it again to know for sure but it is consistently one track.

TonyMLake
07-30-2015, 10:26 PM
If that were the problem then val() would return a value of err that is greater than 0. Err would be the position of the double quote, an illegal character, in the string. The function would than return 0 which is not out of range.



846 .. 855 : past[i - 845].speed := abs(get_int(f)) ; // the offending line



What does this display?

until ch = COMMA ;
ShowMessage(str);
val(str, i, err) ;

DLigett
07-30-2015, 10:44 PM
What does this display?

until ch = COMMA ;
ShowMessage(str);
val(str, i, err) ;

I vote for...

if i > 32767 then ShowMessage(str + ' will break our caller');

TonyMLake
07-31-2015, 12:04 AM
I vote for...

if i > 32767 then ShowMessage(str + ' will break our caller');

Good point, and if that parser throws something "weird" based on it being a garbage input, that could happen.

THEREFORE, call the "ShowMessage" right before the val(str, i, err) ; statement, like the last snippet, up above.

headhawg
07-31-2015, 12:04 AM
I've never seen comma within a string yet, else my program would not be working, it works 99.9% of the time I wrote it 4 years ago. Too lazy to track Bris's mess ups.Bris had in embedded commas in the field that had foreign race comments. (I can't recall the field number.) They would be in some of the Cali track files. I don't know if that's been fixed as it's been years since I looked at it. I think I have also seen them in owner's name or the race name fields as well (can't remember which). It drove me nuts. Wrote a routine to count the number of commas so I knew which files had extras.

TonyMLake
07-31-2015, 12:09 AM
Bris had in embedded commas in the field that had foreign race comments. (I can't recall the field number.) They would be in some of the Cali track files. I don't know if that's been fixed as it's been years since I looked at it. I think I have also seen them in owner's name or the race name fields as well (can't remember which). It drove me nuts. Wrote a routine to count the number of commas so I knew which files had extras.

That's not actually an error (although you're right that Brisnet has a few errors but not as many as Formulator). Commas are legitimate input in .csv files, which is why you need a secondary text delimiter, hence text is enclosed in double quotes to tell applications (or application developers) to ignore the commas within the first and second double quote.

Of course, it doesn't have to be commas, and it doesn't have to be double quotes, but those are common delimiters.

This is common:

32, 45, T, F, "All American Race", 45, 92.3, 0,,,,"First Race Ever, Tired Old Cows", "Scott Stephens", n,,"", *,2

Note the comma in the text field between the double quotes. That's the only way to tell the app it's not a new field, so, it was designed that way.

TonyMLake
08-04-2015, 11:40 PM
Whatever became of this, Actor?

Actor
08-05-2015, 04:35 AM
Whatever became of this, Actor?Sorry if I seem to have dropped out of sight.

I've been forced to put it on hold for a while. The tenant of one of my rental houses has moved out and left the place a mess. You would not believe how much of a mess he left. I've been working trying to clean up the place enough so that I can go to work with a mop and broom, plus repair some damage.

I do appreciate everyone's input.

DJofSD
08-06-2015, 04:38 PM
Here's some code excerpts from an old, old program I wrote years ago using Delphi V1. It reads single file BRIS files. It treats all data tokens as strings and anything that is converted to numeric values is done elsewhere in the app. It has never failed to correctly parse a BRIS data file.


var
Form1: TForm1;
SrcFile: System.Text; {regular ascii text file}
F, revF: String;
s0: string; {initial input string}
ss: array[1..1436] of String; {input string broken out into substrings}
.....

const
NULL: String = ''; // match what BASIC produces
MAXTOKENS: Integer = 1435;
MAXBRISPPRACES: Integer = 10; // BRIS has 10 pace lines per horse
DOT: String = '.';
BLANK: String = ' ';
.....

procedure TForm1.sparser2;
// destructive - modifies string s0
var
sstoken, fchar, endquote, nextcomma: Integer;
ls, lt: Integer;
const
QUOTE: String = #34; { a double quotation mark '"' -- deer track}
COMMA: String = #44;
TERM: String = #34#44; { an end of a string '",' }
begin
fchar := 1;
for sstoken := 1 to MAXTOKENS do begin
ls := Length(s0);
if Copy(s0, 1, 1) = QUOTE then {this token is a BASIC string}
begin
endquote := Pos(TERM, s0); {find matching '",'}
if sstoken = MAXTOKENS then {endquote should be zero}
begin
ss[sstoken] := Copy(s0, 2, ls - 2);
Inc(currentlinetokens);
break; {leave the for loop, clean up and return}
end
else
begin
if endquote - fchar > 1 then {more than just '"",', i.e. not a null}
begin
ss[sstoken] := Copy(s0, 2, endquote - 2);
Inc(currentlinetokens);
{remove token from s0 from '"' to '",' inclusive}
Delete(s0, 1, endquote + 1);
end
else {nothing inbetween, just '"",', assign null }
begin
ss[sstoken] := NULL; // 'NULL STRING ' + IntToStr(sstoken);
Inc(currentlinetokens);
Delete(s0, 1, 3);
end
end
end
else {this token not a BASIC string (no '"' as 1st char);
could be numeric (keep as characters) or null string,
i.e. just a comma}
begin
nextcomma := Pos(COMMA, s0);
lt := nextcomma - 1;
if lt > 0 then
ss[sstoken] := Copy(s0, 1, nextcomma - 1)
else
ss[sstoken] := NULL; // 'NULL TOKEN ' + IntToStr(sstoken);
Inc(currentlinetokens);
Delete(s0, 1, nextcomma);
end
end;
end; // end proc sparser2

procedure TForm1.getallBRISdata;
// read input .DRF file, parse records and insert into StringGrid1 (ALL DATA)
var
icol, j: Integer;
begin
TotalRaces := 0; // before any lines read, no races
while not eof(SrcFile) do begin
Inc(passes); { count the number of times through the loop }
Readln(SrcFile, s0); {read a line}
Inc(TotalBytes, Length(s0)); { count total number of bytes read }
currentlinetokens := 0;
sparser2;
.....

Red Knave
08-07-2015, 03:34 PM
So I changed the variable to a signed integer. That should have cured the problem. It did not.
Not knowing much about this language (although I'm knocked out that it is free with all the bells and whistles it has) is "signed integer" the same as "longint"?
It seems pretty obvious that it is the assignment of the result of the get_int function that is throwing the error so are you sure you changed the type of right var?

Actor
08-07-2015, 10:44 PM
Not knowing much about this language (although I'm knocked out that it is free with all the bells and whistles it has) is "signed integer" the same as "longint"?

Signed integer is 16 bits denoting the range -32768 .. 32767. The language uses integer.
Unsigned integer is 16 bits denoting the range 0 .. 65535. The language uses word.
longint is 32 bits denoting the range -2147483648 .. 2147483647

It seems pretty obvious that it is the assignment of the result of the get_int function that is throwing the error so are you sure you changed the type of right var?Yes.

DLigett
08-08-2015, 12:12 AM
Signed integer is 16 bits denoting the range -32768 .. 32767. The language uses integer.
Unsigned integer is 16 bits denoting the range 0 .. 65535. The language uses word.
longint is 32 bits denoting the range -2147483648 .. 2147483647

Yes.

Right, the function returns a longint, and stuffs it into the integer '.speed' which will fail once in a while.

Red Knave
08-08-2015, 11:44 AM
longint is 32 bits denoting the range -2147483648 .. 2147483647

Can you change the .speed type to longint, turn on range checking, retry with a 'bad' data file and display the results so you can see the offending value?

Actor
08-09-2015, 05:15 AM
I wrote this program specifically to try and find the error. It too crashes with the same error but, like the other program, works if the range checking is turned off, i.e., {$R+} omitted.

Tomorrow I'll try to find time to post the code for comma_delimited_files and tools.

{$R+}
program speeds ; // written specifically to try and debug the range check error
uses comma_delimited_files, tools, crt ;

var
f : text ;
i : 1 .. 855 ;
name : string[25] ;
speed : array[1 .. 10] of integer ;
fname : string ;
begin
if paramcount > 0 then begin
clrscr ;
fname := paramstr(1) ;
writeln(fname) ;
assign(f,fname) ;
reset(f) ;
while not eof(f) do begin
for i := 1 to 855 do begin
case i of
45 : name := get_str(f) ;
846 .. 855 : speed[i - 845] := get_int(f) ;
else
skip(f)
end // case
end ;
readln(f) ;
write(name:25) ;
for i := 1 to 10 do
write(speed[i]:5) ;
writeln
end ;
close(f)
end
else
writeln(QUERY)
end.

TonyMLake
08-09-2015, 07:16 AM
I wrote this program specifically to try and find the error. It too crashes with the same error but, like the other program, works if the range checking is turned off, i.e., {$R+} omitted.

Tomorrow I'll try to find time to post the code for comma_delimited_files and tools.

{$R+}
program speeds ; // written specifically to try and debug the range check error
uses comma_delimited_files, tools, crt ;

var
f : text ;
i : 1 .. 855 ;
name : string[25] ;
speed : array[1 .. 10] of integer ;
fname : string ;
begin
if paramcount > 0 then begin
clrscr ;
fname := paramstr(1) ;
writeln(fname) ;
assign(f,fname) ;
reset(f) ;
while not eof(f) do begin
for i := 1 to 855 do begin
case i of
45 : name := get_str(f) ;
846 .. 855 : speed[i - 845] := get_int(f) ;
else
skip(f)
end // case
end ;
readln(f) ;
write(name:25) ;
for i := 1 to 10 do
write(speed[i]:5) ;
writeln
end ;
close(f)
end
else
writeln(QUERY)
end.


All this may be creating work for no reason. Can we please at least *look* at the value of str before you try the cast to int in the original code block?

What is the output of the showmessage() command I suggested when placed before the attempt to cast it as an int when the parsing fails?

I bet it's not a number at all, so please let's just rule that out.

It'll take five minutes, so let's check that out, please, Actor.

Red Knave
08-09-2015, 11:47 AM
I bet it's not a number at all, so please let's just rule that out.

name : string[25] ;
speed : array[1 .. 10] of integer ; <--SHOULD THIS NOT BE LONGINT?
fname : string ;
Does the minus sign append or prepend the value? VAL should handle it either way but the docs don't say anything about that.
Also, (clutching at straws) would that minus sign require quotes around the value? If so, would the quote screw things up?
As Tony says, knowing what the values are before and after would be useful.

DLigett
08-09-2015, 08:04 PM
I wrote this program specifically to try and find the error. It too crashes with the same error but, like the other program, works if the range checking is turned off, i.e., {$R+} omitted.


Several of us are trying to say the same thing... something like this code will reveal the string that is causing the issue (and then hide the problem, so the caller doesn't know about it).


function get_int (var f : text) : longint ; // read longint from comma delimited file
CONST
COMMA = ',' ;
var
ch : char ;
err : word ;
i : longint ;
str : string ;
begin // get_int
str := '' ;
repeat
read(f,ch) ;
if ch <> COMMA then
str := str + ch
until ch = COMMA ;
val(str, i, err) ;
if err = 0 then
begin
if (i < 0) or (i > 32767) then
begin
ShowMessage('"' + str + '" is negative or won't fit in an integer');

i := 0; // Give our caller something palatable
end;

get_int := i
end
else
get_int := 0
end ; // get_int

Actor
08-10-2015, 05:46 AM
All this may be creating work for no reason. Can we please at least *look* at the value of str before you try the cast to int in the original code block?

What is the output of the showmessage() command I suggested when placed before the attempt to cast it as an int when the parsing fails?

I bet it's not a number at all, so please let's just rule that out.

It'll take five minutes, so let's check that out, please, Actor.I checked it out tonight. It's a number, not surrounded by quotes.

TonyMLake
08-10-2015, 01:51 PM
I checked it out tonight. It's a number, not surrounded by quotes.

Okay, if you used the single line additional piece of code I asked you to use, and you're saying that on the field that it choked on it was a number, what is the EXACT output of the messagebox that appeared when you ran it and it hit the field that it choked on previously... please include things like leading and trailing spaces and anything else that appeared. Please make sure this really is exactly where it choked before.

PS:
By the way, if my initial suspicion is right, the number won't (necessarily) be "surrounded by quotes". The problem with your code is that it will be counting fields incorrectly because commas within quotation marks do not mark the beginning or end of a new field, and thus your code would not be pointing to the field you are expecting it to. Occasionally, Brisnet files have text fields with commas in them, and that is what is screwing your code on occassion. I *could* be wrong about this particular error, but this problem still exists within your code, if I remember correctly, so you're gonna need to correct it eventually anyway.

Actor
08-11-2015, 09:04 AM
Okay, if you used the single line additional piece of code I asked you to use, and you're saying that on the field that it choked on it was a number, what is the EXACT output of the messagebox that appeared when you ran it and it hit the field that it choked on previously... please include things like leading and trailing spaces and anything else that appeared. Please make sure this really is exactly where it choked before.

PS:
By the way, if my initial suspicion is right, the number won't (necessarily) be "surrounded by quotes". The problem with your code is that it will be counting fields incorrectly because commas within quotation marks do not mark the beginning or end of a new field, and thus your code would not be pointing to the field you are expecting it to. Occasionally, Brisnet files have text fields with commas in them, and that is what is screwing your code on occassion. I *could* be wrong about this particular error, but this problem still exists within your code, if I remember correctly, so you're gonna need to correct it eventually anyway.

How is ShowMessage defined? Wouldn't just writeln work?

Declaring speed to be type longint has no effect.

With the exceptions of get_int(f) and get_real(f) all functions in comma_delimited_files handle the comma within quotes. Numeric fields should not be enclosed in quotes so I do not address the comma within quotes possibility in numeric functions. Past attempts to address the possibility that a numeric field is enclosed in quotes has lead to some messy code so I go with the assumption that any comma terminates the numeric field. This has never caused problems before and I don't think that is the problem here since turning off range checking gets rid of the range checking error.

Curiously, the problem seems to be related to fields with negative values but the program continues to run until all 10 values are read, even if the negative value is not the 10th value, then it crashes. :confused: I don't know what to make of that.

DLigett
08-11-2015, 11:41 AM
How is ShowMessage defined? Wouldn't just writeln work?


I don't use FreePascal, but it looks like it is defined in dialogs.pp:
http://wiki.lazarus.freepascal.org/Dialog_Examples

But if you want to use writeln(), that's fine.

I'd like to know what either approach gives you if you use the version of get_int() in msg #34.

TonyMLake
08-11-2015, 12:43 PM
In any case, good luck with it.

Red Knave
08-12-2015, 09:29 AM
Declaring speed to be type longint has no effect.
Okay.

Curiously, the problem seems to be related to fields with negative values but the program continues to run until all 10 values are read, even if the negative value is not the 10th value, then it crashes. :confused: I don't know what to make of that.
Hmmm, are you saying that it always goes through the loop 10 times and only crashes if there is a negative number (or more) somewhere in the array? That sounds like memory outside the array is being overwritten.
Again, my lack of experience with the language may be showing here, but now it seems like either the array index is outside it's bounds (seems unlikely) or memory is being corrupted. I see that the GNU debugger, gdb, can be used with Free Pascal and I would look into figuring out how to use it with your program. The "range check" may actually refer to something else. I know you can bypass this error, but my experience leads me to believe that it will bite you later on.