This is a fairly simple conversion program that takes a TAB delimited file and converts it to a fixed format. It skips the first record (Header) and then reads the next 2 records fine. However, on record number 4, the entire program aborts to windows. I have not really changed any code, but I have updated to the most current version of the compiler.
Any idea what might have happened?
I am including my source code and a mocked up sample data file.
Thanks,
Bill
Sure,
Debugging shows it failing on line 102. Where you are doing this:
DDC.CRLF = chr$(13) + chr$(10)
Which creates a string 3 characters long, as it is NULL terminated. In your UDT you are only allocating two. If you only wanted two characters, and aren't treating it as a string, then just access the istring array directly.
Otherwise increase the size by 1. Such as:
def CRLF[3] as istring
You always have to account for the NULL terminator with strings, otherwise you'll be overwriting memory.
Paul.
That would make sense, if it aborted on the first 2 lines, but it aborts on the third, after it has already written 2 lines. I am trying to write a fixed format record, forcing the Carriage Return/Line Feed at the end of the line. This was working a few months ago and now it aborts on the 4th record.
Is there some other way of doing this, other than thru an UDT? I need each of the defined fields to be that specific length, as llast is Last Name for 16 chars, lfirst is First Name for 14 chars, lid is record ID for 9 chars, laddr1 is first address for 30 chars, laddr2 is second address for 30 chars, lcity is city for 16 chars, etc.
type FixedFormat
def lid[9] as istring
def lprefix[5] as istring
def lfirst[14] as istring
def lmiddle as char
def llast[16] as istring
def lsuffix[6] as istring
def laddr1[30] as istring
def laddr2[30] as istring
def lcity[16] as istring
def lstate[2] as istring
def lzip[5] as istring
def lplus4[4] as istring
def CRLF[2] as istring
endtype
Thanks,
Bill
Bill,
You're overwriting memory, which will randomly crash you program depending on what addresses are involved at the time, on my machine it crashed on the 1st record. Run it through the debugger and look at the exception. Very common, more so than you might realize.
You have to account for the NULL. No other way about it if you are using strings, so llast can be a maximum of 15 alphanumerics plus the NULL with the way your UDT is written.
If you must have fixed length fields, without any kind of termination character, then you'll have to write it one character at a time into the UDT arrays. Which would be kind of unusual, except when dealing with C and the windows API
Paul.