04-03-2023, 12:23 AM
Step 2:
building a raw menu and output for showing data
this demo shows only different colored output for the different arrays with data
building a raw menu and output for showing data
Code: (Select All)
_Title "GradeBook step 2"
$NoPrefix
Option Explicit
Option ExplicitArray
'-------------------------------------------------------
Type NameListType 'Used for the student name database
PinYinName As String * 20
FirstName As String * 20
MiddleName As String * 20
LastName As String * 20
Year As Integer
Month As Integer
Day As Integer
HouseColor As String * 8
MomName As String * 30
MomPhone As String * 20 'Saved as string to support symbols and international prefixes
MomEmail As String * 38
DadName As String * 30
DadPhone As String * 20
DadEmail As String * 38
UID As Integer
End Type
Type MasterAssignmentType 'Each entry needs to be defined before use with slave
UID As Integer ' UID for distinguish among different assignments made in the same date and class or set of students
ARName As String * 20 'Assignment report name
ADName As String * 10 'Assignment display name (short name)
AType As Unsigned Byte 'Assignment Type (Completeion, formative, summative, etc.)
ACat As String * 20 'Assignment Category (subject, unit, etc)
AColor As Unsigned Byte 'Color coding assignment headers and for grouping for reports
ACode As Unsigned Byte 'Reserved
APts As Unsigned Integer 'Total points allowed
End Type
Type SlaveAssignmentType 'Each student would require one with use with master
UIDm As Integer 'UID shows which MasterAssignment has been used
UIDs As Integer 'UID will match the student name list to match results, negative UID means deleted and we will ignore it on display and reports
MPts As Unsigned Integer 'Points earned for each particular students
Flags As Unsigned Byte 'See below for codes
Flags2 As Unsigned Byte ' Reserved
Notes As String * 512 'Comments for a student's work
End Type
'====================Flag codes====================
'1 - Late (Turned in late) |
'2 - Absent on due date (ignore due date) |
'4 - Incomplete (turned in but not done) |
'8 - Missing (Not turned in) |
'16 - Excused/Exempt |
'32 - Ignore score internally for avg, etc. |
'64 - Remove from reports (ignore externally) |
'128 - Reserved |
'==================================================
' end Data Type definition-------------------------------------
Dim Max As Integer, HowMuch As Long, How As Integer
Max = 1
HowMuch = 0
Dim Students(1 To Max) As NameListType, Assignments(1 To Max) As MasterAssignmentType, Results(1 To Max) As SlaveAssignmentType
GoSub initFilerecords
Open "DatabaseDemo2.txt" For Binary As #1
Cls , 14
Print "Now reading Students..."
GoSub ReadStudents
Print " press a key to continue..."
Sleep
Cls , 13
Print "Now reading Assignments..."
GoSub ReadAssignment
Print " press a key to continue..."
Sleep
Cls , 12
Print "Now reading Results..."
GoSub ReadResults
Close #1
Print " press a key to continue, ESC to quit..."
Sleep
Cls , 2
' here start main window of Gradebook database
Dim choice$
choice$ = " "
While choice$ = " "
Cls , 1
Call MWindow(2, 2, 78, 23, " <GradeBook Menu> ")
Locate 4, 4: Print " Press ESCape to quit";
Locate 6, 4: Print " Press S for Students List ";
Locate 8, 4: Print " Press A for Assignment List ";
Locate 10, 4: Print " Press R for Results List ";
choice$ = LCase$(InKey$)
If choice$ = Chr$(27) Then
Cls , 0:
Print "Quitting"
Exit While
ElseIf choice$ = "a" Then
Cls , 2
Print "Assignments: "
ElseIf choice$ = "s" Then
Cls , 5
Print "Students: "
ElseIf choice$ = "r" Then
Cls , 6
Print "Result: "
End If
Locate 18, 4: Print "press any key to continue...";
Locate 20, 4: Print choice$;
If Len(choice$) > 0 Then While InKey$ = "": Wend
_Limit 10
choice$ = " "
Wend
End '<-------- end of program
' Initialization GOSUB creates file of database reading internal data
initFilerecords:
Open "DatabaseDemo2.txt" For Binary As #1 ' here database file has been created
' writing Students in the file
HowMuch = 10
ReDim Preserve Students(1 To HowMuch) As NameListType
Put #1, , HowMuch
Restore StudentsData
Locate 24, 1: Print " Filling file"
For How = 1 To HowMuch Step 1
Read Students(How).PinYinName, Students(How).FirstName, Students(How).MiddleName, Students(How).LastName, Students(How).Year, Students(How).Month, Students(How).Day, Students(How).HouseColor, Students(How).MomName, Students(How).MomPhone, Students(How).MomEmail, Students(How).DadName, Students(How).DadPhone, Students(How).DadEmail, Students(How).UID
'GoSub ShowStudentRecord
'_Delay 1
Next How
Put #1, , Students()
'write assignments in the file
Cls , 5
HowMuch = 4
ReDim Preserve Assignments(1 To HowMuch) As MasterAssignmentType
Restore AssignmentData
Put #1, , HowMuch
For How = 1 To HowMuch Step 1
Read Assignments(How).UID, Assignments(How).ARName, Assignments(How).ADName, Assignments(How).AType, Assignments(How).ACat, Assignments(How).AColor, Assignments(How).ACode, Assignments(How).APts
'GoSub ShowAssignmentsRecord
'_Delay 1
Next How
Put #1, , Assignments()
'write results in the file
Cls , 4
HowMuch = 35
Restore ResultsData
ReDim Preserve Results(1 To HowMuch) As SlaveAssignmentType
Put #1, , HowMuch
For How = 1 To HowMuch Step 1
Read Results(How).UIDm, Results(How).UIDs, Results(How).MPts, Results(How).Flags, Results(How).Flags2, Results(How).Notes
'GoSub ShowResultsRecord
'_Delay 1
Next How
Put #1, , Results()
Close #1
Cls , 12
Print "File of database done! Ready to start demo."
Print "Please press a key to start..."
Sleep
Return
' END of initialization GOSUB----------------------------------
'----------Loading data from file of database into RAM-------------
ReadStudents:
'reading students from the file
Cls , 3
Print " Reading file for Students"
Get #1, , HowMuch
ReDim Students(1 To HowMuch) As NameListType
Get #1, , Students()
'For How = 1 To HowMuch Step 1
' GoSub ShowStudentRecord
'_Delay 1
'Next How
Return
ReadAssignment:
' reading assignments from the file
Cls , 1
Print " Reading file for Assignments"
Get #1, , HowMuch
ReDim Assignments(1 To HowMuch) As MasterAssignmentType
Get #1, , Assignments()
'For How = 1 To HowMuch Step 1
'GoSub ShowAssignmentsRecord
'_Delay 1
'Next How
Return
ReadResults:
' reading results from the file
Cls , 2
Print " Reading file for Results"
Get #1, , HowMuch
ReDim Results(1 To HowMuch) As SlaveAssignmentType
Get #1, , Results()
'For How = 1 To HowMuch Step 1
'GoSub ShowResultsRecord
'_Delay 1
'Next How
Return
'----OUTPUT GOSUB routines ---- to modify for own need
ShowStudentRecord:
Locate 2, 1: Print Space$(80);
Locate 2, 1: Print Trim$(Students(How).PinYinName); Space$(5); Trim$(Students(How).FirstName); Space$(5); Trim$(Students(How).MiddleName); Space$(5); Trim$(Students(How).LastName);
Locate 4, 1: Print Space$(40);
Locate 4, 1: Print "Birthday: "; Students(How).Year; " "; Students(How).Month; " "; Students(How).Day;
Locate 6, 1: Print "Housecolor: "; Students(How).HouseColor; Space$(10)
Locate 8, 1: Print "Mom data: "; Trim$(Students(How).MomName); "/"; Trim$(Students(1).MomPhone); "/"; Trim$(Students(1).MomEmail); Space$(10)
Locate 10, 1: Print "Dad data: "; Trim$(Students(How).DadName); "/"; Trim$(Students(1).DadPhone); "/"; Trim$(Students(1).DadEmail); Space$(10)
Locate 12, 1: Print "UID of student: "; Students(How).UID
Return
ShowAssignmentsRecord:
Locate 1, 1: Print Assignments(How).UID; Space$(10)
Locate , 1: Print Assignments(How).ARName; Space$(10)
Locate , 1: Print Assignments(How).ADName; Space$(10)
Locate , 1: Print Assignments(How).AType; Space$(10)
Locate , 1: Print Assignments(How).ACat; Space$(10)
Locate , 1: Print "Housecolor: "; Assignments(How).AColor; Space$(10)
Locate , 1: Print "Code: "; Assignments(How).ACode; Space$(10)
Locate , 1: Print "Points: "; Assignments(How).APts
Return
ShowResultsRecord:
Locate 1, 1: Print Results(How).UIDm
Locate , 1: Print Results(How).UIDs
Locate , 1: Print Results(How).MPts
Locate , 1: Print Results(How).Flags
Locate , 1: Print Results(How).Flags2
Locate , 1: Print Results(How).Notes
Return
'--------------------DATA set for database file-----------------
StudentsData:
Data RDJ,Robert,Downing,Junior,2000,2,22,12345600,Julia Concepts,333222111,JConcepts@Yahoo.com,Peter Downing,111222333,PeterD@aol.com,1
Data PJM,Paulus,June,Marcus,1999,3,23,89765909,Maria Capello,444111222,MariaCapello@microsoft.com,Mickie Costello,333222333,Mi_Costello@amazon.com,2
Data TMA,Terrie,Mike,Anderson,2001,12,25,45398758,Stephany Johnson,888999777,StepJo@BBC.com,Frank Boulevard,888777666,FrankBoulevard@microsoft.com,3
Data AJW,Amy,Johnson,Watson,2000,01,04,87543324,Donna Walker,666555333,DonWalk@cisco.com,Walter Bros Julian,888222111,WaltBro@amazon.com,4
Data ERT,Emily,Rose,Tinder,2003,4,15,19045689,Angie Longman,333000999,AngieL@tabloid.com,Donald Foster,444888999,DonaldFoster@cisco.com,5
Data UAB,Ully,Aktick,Brandson,2002,06,09,65498732,Jane Murdock,444555666,JMurdock23@aol.com,Ted Wineger,333444555,TedWineger@cisco.com,6
Data WAS,Wendy,Allison,Singer,2004,6,12,78488922,Melissa Naom,999333999,MeliNaom@yahoo.it,Albert Stone,444000999,ASt456@microsoft.com,7
Data MCS,Molly,Connor,Smith,2001,7,5,54365476,Emily Sandman,099900111,EmilyS@aol.com,Bob Miller,555222111,BMiller567@microsoft.com,8
Data RDJ,Ronny,Dudson,jansenn,2003,8,15,81264554,Jenny Portman,123123123,Jportman@BBC.com,Al Fisherman,678678678,AlFisherman@aol.com,9
Data NK,Nina,Killer,,2000,6,12,65439876,Pauline Arson,567567567,PArson@life.com,Andy Wiley,890890890,Andywiley@micro.com,10
Data "END"
AssignmentData:
Data 1,Mathematical,Math,2,Subject,16,0,20
Data 2,Scientific test,Science,8,Unit,1,0,20
Data 3,English language,English,4,Unit,2,0,20
Data 4,Psycologist test,Psycotest,16,Subject,32,0,20
Data "END"
ResultsData:
Data 1,4,15,0,0,Good Job
Data 1,10,10,0,0,Medium Job
Data 1,2,1,0,0,the worst Job
Data 1,3,5,0,0,Bad Job
Data 1,8,11,0,0,Good Job
Data 1,6,20,0,0,Excellent Job
Data 2,4,15,0,0,Good Job
Data 2,10,8,0,0,Medium Job
Data 2,2,4,0,0,Bad Job
Data 2,3,5,0,0,Bad Job
Data 2,8,11,0,0,Good Job
Data 2,6,20,0,0,Excellent Job
Data 2,9,15,0,0,Good Job
Data 2,1,10,0,0,Medium Job
Data 2,5,1,0,0,the worst Job
Data 2,7,5,0,0,Bad Job
Data 3,8,11,0,0,Good Job
Data 3,6,20,0,0,Excellent Job
Data 3,4,15,0,0,Good Job
Data 3,10,10,0,0,Medium Job
Data 3,2,1,0,0,the worst Job
Data 3,3,5,0,0,Bad Job
Data 3,7,11,0,0,Good Job
Data 3,5,20,0,0,Excellent Job
Data 3,9,15,0,0,Good Job
Data 3,1,10,0,0,Medium Job
Data 4,2,1,0,0,the worst Job
Data 4,3,5,0,0,Bad Job
Data 4,8,11,0,0,Good Job
Data 4,6,20,0,0,Excellent Job
Data 4,4,15,0,0,Good Job
Data 4,10,10,0,0,Medium Job
Data 4,5,1,0,0,the worst Job
Data 4,7,5,0,0,Bad Job
Data 4,9,11,0,0,Good Job
Data "END"
Sub MWindow (Ax As Integer, Ay As Integer, Bx As Integer, By As Integer, Wtitle As String)
Dim Count As Integer
Locate Ay, Ax
Print Space$(Bx - Ax + 1);
Locate Ay, Ax
Print String$(Bx - Ax + 1, "Í");
Locate Ay, Ax:
Print "É";
Locate Ay, Bx:
Print "»";
For Count = 1 To (By - Ay - 1)
Locate Ay + Count, Ax
Print Space$(Bx - Ax + 1);
Locate Ay + Count, Ax: Print "º";
Locate Ay + Count, Bx: Print "º";
Next Count
Locate By, Ax: Print Space$(Bx - Ax + 1);
Locate By, Ax
Print String$(Bx - Ax + 1, "Í");
Locate By, Ax: Print "È";
Locate By, Bx: Print "¼";
Locate Ay, ((Bx - Ax + 1) / 2) - (Len(Wtitle) / 2)
Print Wtitle;
End Sub
this demo shows only different colored output for the different arrays with data