Please help me debug my code...
Hi,
Can someone please show me how to do this properly? I have 2 classes, one called CStudent, the other is called CCourse. Below is the main form. I am trying to put classCourse to classStudent.CourseList but it's failing... (last line of the main form). It might be easier to put the whole code to run in VB... Thanks for any help you will be able to suggest.
CStudent Class Code
Private mstrNumber As String
Private mstrName As String
Private mintGPA As Integer
Private mcCourseList As CCourse
Public Property Let Number(pstrNumber As String)
mstrNumber = pstrNumber
End Property
Public Property Get Number() As String
Number = mstrNumber
End Property
Public Property Let Name(pstrName As String)
mstrName = pstrName
End Property
Public Property Get Name() As String
Name = mstrName
End Property
Public Property Get GPA() As Integer
Dim clsCcourse As CCourse
GPA = clsCcourse.Credit * clsCcourse.Grade
End Property
Public Property Let CourseList(pcCourseList As CCourse)
Set mcCourseList = New CCourse
mcCourseList = pcCourseList
End Property
Public Property Get CourseList() As CCourse
CourseList = mcCourseList
End Property
CCourse Class Code
Private mstrCourseNum As String
Private mintGrade As Integer
Private mintCredit As Integer
Public Property Let CourseNum(pstrCourseNum As String)
mstrCourseNum = pstrCourseNum
End Property
Public Property Get CourseNum() As String
CourseNum = mstrCourseNum
End Property
Public Property Let Grade(pintGrade As Integer)
mintGrade = pintGrade
End Property
Public Property Get Grade() As Integer
Grade = mintGrade
End Property
Public Property Let Credit(pintCredit As Integer)
mintCredit = pintCredit
End Property
Public Property Get Credit() As Integer
Credit = mintCredit
End Property
Main Form
Dim classCourse As CCourse
Dim classStudent As CStudent
Private Sub CommandButton1_Click()
Set classCourse = New CCourse
Set classStudent = New CStudent
classStudent.Number = TextBox1.Text
classStudent.Name = TextBox2.Text
classCourse.CourseNum = TextBox3.Text
classStudent.CourseList = classCourse
End Sub
How to retain variables' values
Hi gxpark,
Sorry to be bugging you again, but for the life of me I still can't get my GPA calculation to work properly.
GPA calculation is calculated as total(credit*grade)/# of credits.
Example as follows:
Course Grade Credits
1st Course - 100 * 3 = 300
2nd Course- 98 * 3 = 294
----------
594/6 = 99
where 99 is the GPA grade.
What happens to me is that I'm having problems trying to retain the values of my totalgrade and numberofcredits variables. After hitting on the cmdOk button, these values revert back to 0, so it loses track of old values... What am I doing wrong?
Thanks in advance!
VB Code:
Public Property Get GPA() As Integer
Static totalgrade As Integer
Static numberofcredits As Integer
totalgrade = totalgrade + (mcCourseList.Credit * mcCourseList.Grade)
numberofcredits = numberofcredits + mcCourseList.Credit
GPA = totalgrade / numberofcredits
End Property
1 Attachment(s)
Still couldn't quite get it
gxpark, thanks for your input. I understand what you meant by creating the new student class everytime :D
However, i found out i was doing this the hard way, you know, lethal is right, why not just use a collection object, which will be easier. I tried this for learning purposes, and I find this is easier. However, still couldn't get GPA to work successfully. I'm not sure how to write the Property Get for my GPA (it should be a read only property). I'm really sorry to bug you guys again on this, but for a novice like me, all this stuff is really difficult to understand (especially if your teacher doesn't seem to be teaching it properly :rolleyes: )
Anyways, if you still want to help me, I zipped up my code again (for the nth time), this time I'm using collection instead of class inside a class.
Thanks!