Hi folks,
I was looking at the 'Code Indirection' example in the manual and rather than setting variables to the values in fields, I was trying to go the other way round.
My script works if I name each variable-field pair explicitly e.g.
t.Company = cCompany
t.StartDate = dStartDate etc
...but if I try to refer to them indirectly as in the manual example, I get an assortment of errors (var mismatch etc) depending on what code I try. I have searched and searched for an example but cannot find one. I know I should teach myself how to use the debugger, and I will, but in the meantime, any help would be greatly appreciated.
I will be happy to post my code, but it might be easier just to work from a slightly modified version of the example in the book which for your convenience is below. Note also that I am trying to do this for a series of records, not just one as in the book, hence the need to amend the example code slightly.
Thanks for your time.
MS
CODE INDIRECTION EXAMPLE FROM THE MANUAL
'Next line removed as my script is not a function
'function xlookup as L(tablename as C, rec as N)
'Next line added as example did not specify the table
tablename = Table.actual_filename_get("cleaner upper")
t = table.open(tablename)
t.index_primary_put()
'Next line changed to point to 1st rec
t.fetch_first()
num_fields = t.fields_get()
'Next two lines added to handle multiple recs
for rec = 1 to 20
t.change.begin()
for I = 1 to num_fields
f = t.field_get(I)
evaluate_template("dim global " + f.name_get() + " as " + f.type_get())
eval(f.name_get()) = f.value_get()
next I
'Next two lines added line to close the multiple recs 'for' loop
t.change.end(.t.)
next rec
t.close()
end function
I was looking at the 'Code Indirection' example in the manual and rather than setting variables to the values in fields, I was trying to go the other way round.
My script works if I name each variable-field pair explicitly e.g.
t.Company = cCompany
t.StartDate = dStartDate etc
...but if I try to refer to them indirectly as in the manual example, I get an assortment of errors (var mismatch etc) depending on what code I try. I have searched and searched for an example but cannot find one. I know I should teach myself how to use the debugger, and I will, but in the meantime, any help would be greatly appreciated.
I will be happy to post my code, but it might be easier just to work from a slightly modified version of the example in the book which for your convenience is below. Note also that I am trying to do this for a series of records, not just one as in the book, hence the need to amend the example code slightly.
Thanks for your time.
MS
CODE INDIRECTION EXAMPLE FROM THE MANUAL
'Next line removed as my script is not a function
'function xlookup as L(tablename as C, rec as N)
'Next line added as example did not specify the table
tablename = Table.actual_filename_get("cleaner upper")
t = table.open(tablename)
t.index_primary_put()
'Next line changed to point to 1st rec
t.fetch_first()
num_fields = t.fields_get()
'Next two lines added to handle multiple recs
for rec = 1 to 20
t.change.begin()
for I = 1 to num_fields
f = t.field_get(I)
evaluate_template("dim global " + f.name_get() + " as " + f.type_get())
eval(f.name_get()) = f.value_get()
next I
'Next two lines added line to close the multiple recs 'for' loop
t.change.end(.t.)
next rec
t.close()
end function
Comment