I am trying to write a program in VBA to calculate GPA.
The form has a listbox to slect grades and a textbox for users to enter the credits.
I need to store the grades in an array once btnrecord is clicked and once user clicks BtnCalculate, I want to calculate the GPA and display the result in another textbox.
I am getting "Subscript out of range error" in the array with the following code.
Private Sub btnRecord_Click()
Dim x As Long
Dim temparray() As Variant
If (IsNumeric(TextBox1.Text) = False) Then
MsgBox "You must enter an integer number"
Exit Sub
End If
ReDim temparray(1 To TextBox1.Text)
For I = 1 To TextBox1.Text
Select Case Me.ListBox1.Value
Case "A+"
temparray(x) = (4.33 * n)
Case "A"
temparray(x) = (4 * n)
Case "A-"
temparray(x) = (3.67 * n)
Case "B+"
temparray(x) = (3.33 * n)
Case "B"
temparray(x) = (3 * n)
Case "B"
temparray(x) = (2.67 * n)
Case "C+"
temparray(x) = (2.33 * n)
Case "C"
temparray(x) = (2 * n)
Case "C-"
temparray(x) = (1.67 * n)
Case "D+"
temparray(x) = (1.33 * n)
Case "D"
temparray(x) = (1 * n)
Case "D-"
temparray(x) = (0.67 * n)
End Select
Next I
ReDim Preserve temparray(x)
End Sub
Please help.
Thanks,
Blyzzard
Bookmarks