tcount := 0;
tempTable.IndexFieldNames:= 'RID;VarOrderStr;ROrder';
tempTable.Filtered:= True;
AssignFile(f, fname);
Rewrite(f);
write(f, 'SID,RID,STATUS,IVID,Start,Last,');
for ti := 0 to OrderedVarList.Count-1 do begin
AVar := OrderedVarList.Data[ti];
if AVar.MaxCount + AVar.MaxOpenCount = 1
then Write(f, AVar.VarName(0), ',')
else begin
for tj := 1 to AVar.MaxCount do Write(f, AVar.VarName(tj), ',');
for tj := 1 to AVar.MaxOpenCount do Write(f, AVar.VarName(-tj), ',');
end;
end;
Writeln(f);
trRes.First;
while not trRes.Eof do begin
with trRes do begin
trid:= FieldByName('rid').AsInteger;
ts:= Format('%s,%d,%s,%s,"%s","%s",',
[FieldByName('sid').AsString,
trid,
FieldByName('Status').AsString,
FieldByName('Ivid').AsString,
FieldByName('Created').AsString,
FieldByName('LTime').AsString]);
end;
write(f, ts);
TempTable.Filter:= Format('RID=%d', [trid]);
tempTable.first;
ti := 0;
ts := tempTable.FieldByName('VarOrderStr').AsString ;
while (not tempTable.Eof) and (ti < OrderedVarList.Count) do begin
AVar := OrderedVarList.Data[ti];
tss := OrderedVarList.Keys[ti];
for tj := 1 to AVar.MaxCount do begin
if (ts = tss) then begin
write (f, temptable.FieldByName('rcode').AsInteger);
temptable.next;
if temptable.eof then break
else ts := tempTable.FieldByName('VarOrderStr').AsString ;
end;
write (f, ',');
end;
if tempTable.EOF then break;
for tj := 1 to AVar.MaxOpenCount do begin
if (ts = tss) then begin
write (f, temptable.FieldByName('rcode').AsInteger);
temptable.next;
if temptable.eof then break
else ts := tempTable.FieldByName('VarOrderStr').AsString ;
end;
write (f, ',');
end;
inc(ti);
end;
writeln(f);
trRes.Next;
tcount += 1;
if Assigned(SendMessage) then
if (tcount mod 50) = 0 then SendMessage(Format('%d respondents processed', [tcount]));
Application.ProcessMessages;
end;
Close(f);