I am building an application that is to be used for registering students and course management of 1 to 5 courses.
I have a booking table with 2 series of relating fields:
Kx_booked, where x can be 1 to 5
Cx_granted, that relates to the Kx_booked field
There is another field that holds the course indicator K1 through K5.
In a first stage a reservation is made for a certain course and the Kx_booked field is set to true.
At the end of a particular course, when it is confirmed that a student showed up and followed that course, the Cx_granted field is to be set to true. A script will be launched by a button push and will update the Cx_granted fields.
The script works but after having another look I lost some confidence as to the use of the EVAL statement. Using the debugger didn't help me boosting my confidence again.
Script.
dim invh as p
dim tbl as p
dim qry as p
dim numbr as c
dim recs as n
dim kind as c
dim kind2 as c
invh=table.get("courses") 'Parent table in the set
on error goto errors
numbr=invh.Id 'Populate variable with course number fields from the courses table
tbl=table.open("booking") 'One of the child tables in the set
query.filter="Course_Id=var->numbr"
query.order="Pers_id"
query.options="N"
query.decription="Number Item Lines"
qry=tbl.query_create()
recs=qry.records_get()
'ui_msg_box("",str(recs)+"") 'Can be commented out. Shows # child records relating to Invh table
tbl.fetch_first()
'debug(1)
while .not. tbl.fetch_eof()
kind = "C" + right(invh.K_connector,1) + "_granted"
kind2 = alltrim(invh.K_connector)
tbl.change_begin() 'Put child table into change mode
eval("tbl." + var->kind) = var->kind2
tbl.Course_Fin = .T.
tbl.change_end(.t.) 'end the change mode
tbl.fetch_next() 'fetch until last matching child record has been fetched
end while
tbl.close() 'close child table
'set course to finished
if invh.Id = var->numbr
invh.change_begin()
invh.Course_Fin = .T.
invh.change_end(.t.) 'end change mode
end if
end
-----------
The result of the eval statement is .T. but looking at it I would have expected another value stored in kind2 = alltrim(invh.K_connector).
Am I correct in my assuption?
Thanks,
I have a booking table with 2 series of relating fields:
Kx_booked, where x can be 1 to 5
Cx_granted, that relates to the Kx_booked field
There is another field that holds the course indicator K1 through K5.
In a first stage a reservation is made for a certain course and the Kx_booked field is set to true.
At the end of a particular course, when it is confirmed that a student showed up and followed that course, the Cx_granted field is to be set to true. A script will be launched by a button push and will update the Cx_granted fields.
The script works but after having another look I lost some confidence as to the use of the EVAL statement. Using the debugger didn't help me boosting my confidence again.
Script.
dim invh as p
dim tbl as p
dim qry as p
dim numbr as c
dim recs as n
dim kind as c
dim kind2 as c
invh=table.get("courses") 'Parent table in the set
on error goto errors
numbr=invh.Id 'Populate variable with course number fields from the courses table
tbl=table.open("booking") 'One of the child tables in the set
query.filter="Course_Id=var->numbr"
query.order="Pers_id"
query.options="N"
query.decription="Number Item Lines"
qry=tbl.query_create()
recs=qry.records_get()
'ui_msg_box("",str(recs)+"") 'Can be commented out. Shows # child records relating to Invh table
tbl.fetch_first()
'debug(1)
while .not. tbl.fetch_eof()
kind = "C" + right(invh.K_connector,1) + "_granted"
kind2 = alltrim(invh.K_connector)
tbl.change_begin() 'Put child table into change mode
eval("tbl." + var->kind) = var->kind2
tbl.Course_Fin = .T.
tbl.change_end(.t.) 'end the change mode
tbl.fetch_next() 'fetch until last matching child record has been fetched
end while
tbl.close() 'close child table
'set course to finished
if invh.Id = var->numbr
invh.change_begin()
invh.Course_Fin = .T.
invh.change_end(.t.) 'end change mode
end if
end
-----------
The result of the eval statement is .T. but looking at it I would have expected another value stored in kind2 = alltrim(invh.K_connector).
Am I correct in my assuption?
Thanks,
Comment