|
-
Apr 17th, 2000, 11:34 AM
#1
Thread Starter
Member
Assignment goes like this:
*write a program to compute a student's GPA.
* Use InputBox in the Form_Load to request number of courses to be averaged.
*Create elements in two text box control arrays to hold the grade and semester hours.
*Function to compute GPA
*Sub procedure to display GPA
I am having problems BIG TIME.
msgbox is fine - it displays correct arrays.
I cannot figure out how to read the correct lines -
my
For i = 2 to amt
causes the program to start with #2 - I have to have the number of classes input by the user and am not sure that I am referencing this correctly. HELP!!!!!
Dim TotalPts As Integer
Dim counter As Integer
Dim Amt As Integer
Dim prompt As String
Dim title As String
Dim grade As String
Dim i As Integer
Dim points As Single
Dim Index As Integer
Option Explicit
Private Sub cmdCalculate_Click()
picDisplay.Cls
Call ttlPts
picDisplay.Print "Have a merry vacation."
End Sub
Private Sub cmdExit_Click()
End
End Sub
Private Sub Form_Load()
title = "Number of Courses to Average"
prompt = "Enter number of courses to average the grade point"
Amt = InputBox(prompt, title)
For i = 2 To Amt
Load lblGrade(i)
Load txtGrade(i)
Load lblHours(i)
Load txtHours(i)
lblGrade(i).Top = lblGrade(i - 1).Top + lblGrade(1).Height
txtGrade(i).Top = txtGrade(i - 1).Top + txtGrade(1).Height
lblHours(i).Top = lblHours(i - 1).Top + lblHours(1).Height
txtHours(i).Top = txtHours(i - 1).Top + txtHours(1).Height
lblGrade(i).Visible = True
txtGrade(i).Visible = True
lblHours(i).Visible = True
txtHours(i).Visible = True
lblGrade(i).Caption = "Course #" & i & " Grade"
lblHours(i).Caption = "Credit Hours"
Next i
End Sub
Public Function GPA() As Single
counter = 0
points = 0
TotalPts = 0
For i = 2 To Amt
grade = UCase(txtGrade(i).Text)
If grade = "A" Or "A+" Then
points = 4
ElseIf grade = "A-" Then
points = 3.8
ElseIf grade = "B+" Then
points = 3.3
ElseIf grade = "B" Then
points = 3
ElseIf grade = "B-" Then
points = 2.8
ElseIf grade = "C+" Then
points = 2.3
ElseIf grade = "C" Then
points = 2
ElseIf grade = "C-" Then
points = 1.8
ElseIf grade = "D+" Or "D" Or "D-" Then
points = 1
ElseIf grade = "F" Then
points = 0
Else
points = 0
End If
counter = counter + 1
TotalPts = points + TotalPts
Next i
GPA = TotalPts / counter
End Function
Private Sub ttlPts()
picDisplay.Print "Your Grade Point Average is "; GPA
If GPA >= 3 Then
picDisplay.Print "You have made the honor roll."
Else
picDisplay.Print " Congratulations on completing the semester."
End If
End Sub
-
Apr 17th, 2000, 02:42 PM
#2
Frenzied Member
koperski the problem is that the first control (probably) has an inedex of 0 nad you are starting at 2
your options would be to set the first element index to 1 or
loop from 1 (the prefered option)
secondly, the first element is already loaded so set the value of that outside the loop
Code:
Private Sub Form_Load()
title = "Number of Courses to Average"
prompt = "Enter number of courses to average the grade point"
Amt = InputBox(prompt, title)
i = 0
lblGrade(i).Caption = "Course #" & i + 1 & " Grade"
lblHours(i).Caption = "Credit Hours"
For i = 1 To Amt - 1
Load lblGrade(i)
Load txtGrade(i)
Load lblHours(i)
Load txtHours(i)
lblGrade(i).Top = lblGrade(i - 1).Top + lblGrade(0).Height
txtGrade(i).Top = txtGrade(i - 1).Top + txtGrade(0).Height
lblHours(i).Top = lblHours(i - 1).Top + lblHours(0).Height
txtHours(i).Top = txtHours(i - 1).Top + txtHours(0).Height
lblGrade(i).Visible = True
txtGrade(i).Visible = True
lblHours(i).Visible = True
txtHours(i).Visible = True
lblGrade(i).Caption = "Course #" & i + 1 & " Grade"
lblHours(i).Caption = "Credit Hours"
Next i
End Sub
you'll need to change your GPA function as well to match
I don't know how much of this is your own work or wether you've had to modify an example but...
personally I would use a "Select Case" in GPA because they are much easier to read
another improvement would be to have
Dim TotalPts As Integer
Dim counter As Integer
Dim grade As String
Dim points As Single
delcared locally in GPA()
and
Dim prompt As String
Dim title As String
declared locally in Form_Load
-
Apr 17th, 2000, 07:43 PM
#3
Thread Starter
Member
becoming very frustrated.
I did start my index at 1 and have made the above changes. This causes 1 too few labels and texts to print.
I am really stuck!
I can take off the -1 for the
For i = 2 to amt -1
but then this causes the first set of information to be referenced by the function to be the second array (2).
Of course this causes the function to want to read one more array than has been printed - which errors.
I had originaly set it up with cases. But thought that I was having a problem there too.
-
Apr 17th, 2000, 08:02 PM
#4
Frenzied Member
email me your form and I'll fix it for you
-
Apr 17th, 2000, 08:06 PM
#5
Frenzied Member
email me your form and I'll fix it for you
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|