|
Home
Up
Grades Script
My Opinion
|
|
 |
Putting grades up in an Excel or html table makes a page
that takes a long time to load, which is a hassle when students want to see
them quickly. So, I put them up in a plain text listing with the
column headers repeated every 10 lines. They are maintained in an ASA
database using PowerBuilder. Here is the script that puts them into
the text file for quick posting to the web. If any of you young dogs
see how this old one could do it any easier please let me know. I'm
always sure there's a 'less procedural' way to do anything I attempt by
brute force...
|
//declare variables
datetime GradeDateTime
string CrLf, Last4, GradeString, GradeFileName, Notes, LastName, GradeCol[10], ColumnHeader
real P[5], Q[3], Indep, TotalGrade
integer GradeFile, Counter, Id, I
CrLf = char(13) + char(10)
//Connect to the database
CONNECT USING SQLCA;
IF SQLCA.SQLCODE <> 0 and SQLCA.SQLCODE <> -1 THEN
MessageBox("SQLCODE ->" + STRING(SQLCA.SQLCODE) + "<-",SQLCA.SQLERRTEXT)
halt
END IF
//Declare CURSOR sorted by Last 4 digits of ssn
DECLARE Grades CURSOR FOR SELECT
RIGHT("students"."ssn",4),
"students"."p1",
"students"."p2",
"students"."p3",
"students"."p4",
"students"."p5",
"students"."q1",
"students"."q2",
"students"."q3",
"students"."independent_effort",
"students"."notes"
FROM "students"
ORDER BY RIGHT("students"."ssn",4)
USING SQLCA;
//Open the cursor and halt with any error message
OPEN Grades;
FETCH Grades INTO :Last4, :P[1], :P[2], :P[3], :P[4], :P[5], :Q[1], :Q[2], :Q[3], :Indep, :Notes;
if SQLCA.SQLCode <> 0 then
messagebox("SQL Error","SQLCode returned was " + string(SQLCA.SQLCode) + " " +
SQLCA.SQLErrText)
halt
end if
//Setup the column header & page header
ColumnHeader = "SS#. Proj1 Proj2 Proj3 Proj4 Proj5 Quiz1 Quiz2 Quiz3 Indep Total Notes........"
GradeDateTime = DateTime(Today(),Now())
GradeString = "Grades posted as of " + string(GradeDateTime, "hh:mm dd mmm yyyy") + ":" + CrLf + CrLf
GradeString += ColumnHeader + CrLf + CrLf
//Format the record into fixed width columns, placing a column header each 10 lines
do while SQLCA.SQLCode = 0
Counter += 1
if mod(Counter,10) = 0 then GradeString += CrLf + ColumnHeader + CrLf + CrLf
TotalGrade = 0
For I = 1 to 5
TotalGrade += P[I]
GradeCol[I] = right("
" + string(P[I],"#0.00"),7)
next
For I = 1 to 3
TotalGrade += Q[I]
GradeCol[5 + I] = right("
" + string(Q[I],"#0.00"),7)
next
TotalGrade += Indep
GradeCol[9] = right("
" + string(Indep,"#0.00"),7)
GradeCol[10] = right("
" + string(TotalGrade,"##0.0"),8)
GradeString += Last4 + " "
for I = 1 to 10
GradeString += GradeCol[I]
next
GradeString += " " + Notes + CrLf
FETCH Grades INTO :Last4, :P[1], :P[2], :P[3], :P[4], :P[5], :Q[1], :Q[2], :Q[3], :Indep, :Notes;
loop
CLOSE Grades;
//Write the text file
GradeFileName = "d:\!465SU00\!Grades.txt"
GradeFile = FileOpen(GradeFileName, StreamMode!, Write!, LockWrite!, Replace!)
if GradeFile = -1 then
messagebox("File Open Error","Got " + string(GradeFile) + "at open of " + GradeFileName)
halt
end if
FileWrite(GradeFile,GradeString)
messagebox("File Written",GradeFileName + " has been written...")
|