tbl = table.open("hours")
indx = tbl.index_get("rchk1")
tbl.index_primary_put(indx)
tbl.fetch_last()
fld = tbl.field_get("rchk")
var->LastCheck = fld.value_get()
indx = tbl.index_get("rchk0")
tbl.index_primary_put(indx)
rec_count = indx.records_get()
fld = table.field_get("rchk")
tbl.fetch_first()
tbl.change_begin()
for x = 1 to rec_count
fld.value_put(var->LastCheck + x)
tbl.change_end()
tbl.fetch_next()
tbl.change_begin()
Next
tbl.change_end()
tbl.close()I am trying to assign check numbers to records that do not have numbers assigned. The "hours" table has a field "rchk" that holds the check numbers, numeric 5/0.
I have indexed this field using rchk1 and rchk0. I can step through the attached script and do not get an index error but when I run it, I get "invalid key length". The first part of the script puts the records in check number order so that I may retrieve the last check number using tbl.fetch_last(), then assign this number to a variable. The next section, using the index rchk0 finds only the records that have no check number and do have netpay >0. This is set up in the index definition. When I look at the results in the expression builder (for index) it shows me a four digit check number followed by a decimal point and six zeros. I don't understand why the decimal and zeros and if this is the cause of the key length error. I barely know how to write xbasic and this has me baffled (as usual).
indx = tbl.index_get("rchk1")
tbl.index_primary_put(indx)
tbl.fetch_last()
fld = tbl.field_get("rchk")
var->LastCheck = fld.value_get()
indx = tbl.index_get("rchk0")
tbl.index_primary_put(indx)
rec_count = indx.records_get()
fld = table.field_get("rchk")
tbl.fetch_first()
tbl.change_begin()
for x = 1 to rec_count
fld.value_put(var->LastCheck + x)
tbl.change_end()
tbl.fetch_next()
tbl.change_begin()
Next
tbl.change_end()
tbl.close()I am trying to assign check numbers to records that do not have numbers assigned. The "hours" table has a field "rchk" that holds the check numbers, numeric 5/0.
I have indexed this field using rchk1 and rchk0. I can step through the attached script and do not get an index error but when I run it, I get "invalid key length". The first part of the script puts the records in check number order so that I may retrieve the last check number using tbl.fetch_last(), then assign this number to a variable. The next section, using the index rchk0 finds only the records that have no check number and do have netpay >0. This is set up in the index definition. When I look at the results in the expression builder (for index) it shows me a four digit check number followed by a decimal point and six zeros. I don't understand why the decimal and zeros and if this is the cause of the key length error. I barely know how to write xbasic and this has me baffled (as usual).
Comment