dim trv_name[64] as char dim trv_from[20] as int sub trv_open(s[] as char, trv as int) dim x as int dim x_points as int dim points as int 'inline TRACE(">trv_open"); trv_name = s open s for read as trv if error then x = dialog(s, "File not found - Exiting") exit program endif points = -1 for i=0 to trv_nquestions(trv)-1 x_points = trv_points(trv, i) if x_points > points then trv_from[x_points] = i points = x_points endif next trv_from[x_points+1] = i-1 'inline TRACE("trv_close"); close trv 'inline TRACE("trv_nquestions=%d",n); trv_nquestions = n 'inline TRACE("trv_points"); posn = 2+n*12 get trv,posn,points 'inline TRACE("n=%d,posn=%ld,points=%ld",n,posn,points); trv_points = points 'inline TRACE("trv_usage"); posn = 2+n*12+8 get trv,posn,usage 'inline TRACE("n=%d,posn=%ld,usage=%d",n,posn,usage); trv_usage = usage 'inline TRACE("trv_inc_usage"); usage = trv_usage(trv, n) close trv open trv_name for append as trv posn = 2+n*12+8 usage=usage+1 put trv,posn,usage 'inline TRACE("n=%d,posn=%ld,usage=%d",n,posn,usage); close trv open trv_name for read as trv 'inline TRACE("trv_find"); min_usage = 1000 trv_find = -1 bottom=trv_from[points] top=trv_from[points+1]-1 for i=bottom to top if trv_usage(trv, i) < min_usage then min_usage = trv_usage(trv, i) next ''inline TRACE("points=%ld bottom=%d top=%d min_usage=%d", points, bottom, top, min_usage); while true select = rnd(top-bottom)+bottom ''inline TRACE("..select=%d", select); if trv_usage(trv, select) <= min_usage then exit while wend trv_find = select 'inline TRACE("trv_nanswers"); n=-2 posn = 2+i*12+4 get trv,posn,offset get trv,offset 'inline TRACE("i=%d,posn=%ld,offset=%ld",i, posn, offset); while(true) get trv,,x if x=0 then exit while inline x = x ^ 0xAA; if x=\|\ then n=n+1 wend trv_nanswers = n 'inline TRACE("trv_getstring"); n=0 while(true) get trv,,x if x=0 then exit while inline x=x^0xAA; if x=\|\ then exit while s[n] = x s[n+1] = 0 n=n+1 wend 'inline TRACE("trv_answers"); n=-3 correct = 0 posn = 2+i*12+4 get trv,posn,offset get trv,offset while(true) get trv,,x if x=0 then exit while inline x = x ^ 0xAA; if x=\|\ then n=n+1 if n=j then trv_getstring(trv, s) if s[0] = \*\ then correct=1 inline strcpy(s, s+1); endif exit while endif wend trv_answers = correct 'inline TRACE("trv_question"); trv_answers(trv, i, -1, s) 'inline TRACE("trv_category"); trv_answers(trv, i, -2, s) 'inline TRACE("