Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange event surrounding non-numeric value - any explanations?

Status
Not open for further replies.

CHeighlund

Programmer
Jun 11, 2007
163
US
I've been requested to work on a Delphi program designed to process the results from a text file and transform it into a .csv file format. I am not completely certain (I didn't write the program), but it appears that the data is also being sent through an access database as well.

There are three values on each line of the input file, separated by commas. The first is one of three or four types of numeric value (exact type depends on the length of the string, but they're all supposed to be purely numeric), the second is a date string, the last a time string.

I've been given a set of seven files ([name]1 - [name]7) that have thrown errors recently. In the [name]2 file, the numeric field on one of the lines is eight characters long, and the last three characters are 0Z5. Yes, that's a Z; it got placed into the field by accident apparently. That's why this record failed. Thing is, it's not failing the way I'd expect a non-numeric value to fail.

There was a quick and dirty 'isnumeric' function in the code, a try/except block with an inner StrToInt() called on the value passed to it. I've replaced it with the one I use, which looks to see if any of the characters in the string have a chr() value other than in the 48-57 range. Neither of these tests is flagging on the problem code, for some reason. Setting a breakpoint at the first line of the routine shows the code execution appears to be hitting it, but then passing through. And the error when the program finally does blarg is something along the lines of "Syntax error (missing operator) in query expression '0Z5'".

Does anyone have a clue (and is willing to share it) as to why the 'Z' seems to be passing in, or what the error's trying to tell me? The only thing that comes to mind for me is that some languages treat hexadecimal numbers as 0xFFFF format, and I'm wondering if the '0Z' in the string might be getting interpeted similarly somehow. I don't know how likely it is; as I said, it's simply the only thing that comes to mind for me.

Anyone have any idea what's going on here?
 
Got no clue. The preferred way to check for 'IsNumeric' is to use the TryStrToInt function which returns a Boolean as well as the value as integer, without throwing exceptions.

Shows us some of the processing code if you can, it sounds like there's something in that that's causing this to happen.
 
Thanks for the information on the TryStrToInt function; that's now replacing the original IsNumeric function.

Found the solution to my original problem buried elsewhere in the code; the original code didn't send the whole item along, merely the first character for validation...and in this case, the first item was a number, so it didn't trigger. This has been corrected so that the entire item gets passed to the function. I probably should have caught that yesterday; I'm sorry for bringing the issue up when common sense should have been able to handle it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top