|
-
Apr 19th, 2000, 12:52 AM
#1
Thread Starter
Member
My assignment says that I can do this through a
"Private Sub txtGrade_LostFocus(Index As Integer)"
procedure... I just don't understand how!
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()
Dim prompt As String
Dim title As String
Dim i As Integer
Dim Amt As Integer
Dim counter As Integer
picDisplay.AutoRedraw = True
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
Public Function GPA() As Single
Dim points As Single
Dim grade As String
Dim TotalPts As Integer
Dim counter As Integer
Dim i As Integer
counter = 0
points = 0
TotalPts = 0
For i = 0 To txtGrade.UBound
grade = UCase(txtGrade(i).Text)
Select Case grade
Case "A", "A+"
points = 4
Case "A-"
points = 3.8
Case "B+"
points = 3.3
Case "B"
points = 3
Case "B-"
points = 2.8
Case "C+"
points = 2.3
Case "C"
points = 2
Case "C-"
points = 1.8
Case "D+", "D", "D-"
points = 1
Case "F"
points = 0
Case Else
points = 0
End Select
TotalPts = points + TotalPts
Next i
GPA = TotalPts / i
End Function
Private Sub ttlPts()
Dim GrdPA As Single
GrdPA = GPA()
picDisplay.Print "Your Grade Point Average is "; GrdPA
If GrdPA >= 3 Then
picDisplay.Print "You have made the honor roll."
Else
picDisplay.Print " Congratulations on completing the semester."
End If
End Sub
Private Sub txtGrade_LostFocus(Index As Integer)
Dim i As Integer
Select Case Index
Case 0
End Select
End Sub
-
Apr 19th, 2000, 02:41 AM
#2
Thread Starter
Member
-
Apr 19th, 2000, 03:05 AM
#3
Thread Starter
Member
-
Apr 19th, 2000, 06:30 AM
#4
Thread Starter
Member
I have yet to understand this???
-
Apr 19th, 2000, 03:22 PM
#5
Fanatic Member
You are not helping any body to help you by not explaining what yoy are trying to do. If i remember the last question, which also wasn't explained very well you could do this.
Code:
Private Sub txtGrade_LostFocus(Index As Integer)"
'set the focus to the txtHours with the same index
txtHours(index).SetFocus
End Sub
Private Sub txtHours_LostFocus(Index As Integer)"
'make sure that this is not the last control in the array
If Index < txtGrade.UBound
'set the focus to txtGrade with the index + 1
txtGrade(index + 1).SetFocus
End If
End Sub
Iain, thats with an i by the way!
-
Apr 19th, 2000, 07:34 PM
#6
Fanatic Member
just had another idea. you could change your loop to look like this. I assume you have one txtGrade and txtHours on your form already. Set there tabIndex to 1 and 2. (or whatever) Then set myTabIndex to the next number (in this case 3.
Code:
Dim myTabIndex as Integer
myTabIndex = 3
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"
'set the tab index's
txtGrade(i).TabIndex = myTabIndex
myTabIndex = myTabIndex + 1
txtHours(i).TabIndex = myTabIndex
myTabIndex = myTabIndex + 1
Next i
Iain, thats with an i by the way!
-
Apr 19th, 2000, 09:10 PM
#7
Thread Starter
Member
You are correct in assuming I already have two txtBoxes on the form.
I have tried both options -
If I use the myTabIndex then the curser automatically appears at the last txtBox.
So I added it to a select case procedure - it just doesn't work. (see below)
Private Sub txtGrade_GotFocus(Index As Integer)
Dim myTabIndex As Integer, i As Integer
Select Case Index
Case 0
myTabIndex = 0
txtGrade(i).TabIndex = myTabIndex
myTabIndex = myTabIndex + 1
txtHours(i).TabIndex = myTabIndex
myTabIndex = myTabIndex + 1
Case 1
myTabIndex = 2
txtGrade(i).TabIndex = myTabIndex
myTabIndex = myTabIndex + 1
txtHours(i).TabIndex = myTabIndex
myTabIndex = myTabIndex + 1
Case 3
myTabIndex = 4
txtGrade(i).TabIndex = myTabIndex
myTabIndex = myTabIndex + 1
txtHours(i).TabIndex = myTabIndex
myTabIndex = myTabIndex + 1
Case 4
myTabIndex = 6
txtGrade(i).TabIndex = myTabIndex
myTabIndex = myTabIndex + 1
txtHours(i).TabIndex = myTabIndex
myTabIndex = myTabIndex + 1
Case 5
myTabIndex = 8
txtGrade(i).TabIndex = myTabIndex
myTabIndex = myTabIndex + 1
txtHours(i).TabIndex = myTabIndex
myTabIndex = myTabIndex + 1
End Select
End Sub
If I use the LostFocus Sub
I keep getting errors.
I'm almost ready to give up.
-
Apr 19th, 2000, 09:54 PM
#8
Fanatic Member
You still haven't explained exactly what you want to achieve, but here is another attempt.
When the form loads up the cursor will be in txtHours(0). Then when you tab the cursor will move to txtGrade(0), then txtHours(1) then txtGrade(1) etc.
set the TabIndex of txtHours(0) = 0
set the TabIndex of txtGrade(0) = 1
now use the following code.
Code:
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()
Dim prompt As String
Dim title As String
Dim i As Integer
Dim Amt As Integer
Dim counter As Integer
Dim myTabIndex As Integer
myTabIndex = 2
picDisplay.AutoRedraw = True
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 + 20
txtGrade(i).Top = txtGrade(i - 1).Top + txtGrade(0).Height + 20
lblHours(i).Top = lblHours(i - 1).Top + lblHours(0).Height + 20
txtHours(i).Top = txtHours(i - 1).Top + txtHours(0).Height + 20
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"
txtHours(i).TabIndex = myTabIndex
myTabIndex = myTabIndex + 1
txtGrade(i).TabIndex = myTabIndex
myTabIndex = myTabIndex + 1
Next i
End Sub
Public Function GPA() As Single
Dim points As Single
Dim grade As String
Dim TotalPts As Integer
Dim counter As Integer
Dim i As Integer
counter = 0
points = 0
TotalPts = 0
For i = 0 To txtGrade.UBound
grade = UCase(txtGrade(i).Text)
Select Case grade
Case "A", "A+"
points = 4
Case "A-"
points = 3.8
Case "B+"
points = 3.3
Case "B"
points = 3
Case "B-"
points = 2.8
Case "C+"
points = 2.3
Case "C"
points = 2
Case "C-"
points = 1.8
Case "D+", "D", "D-"
points = 1
Case "F"
points = 0
Case Else
points = 0
End Select
TotalPts = points + TotalPts
Next i
GPA = TotalPts / i
End Function
Private Sub ttlPts()
Dim GrdPA As Single
GrdPA = GPA()
picDisplay.Print "Your Grade Point Average is "; GrdPA
If GrdPA >= 3 Then
picDisplay.Print "You have made the honor roll."
Else
picDisplay.Print " Congratulations on completing the semester."
End If
End Sub
Iain, thats with an i by the way!
-
Apr 19th, 2000, 10:13 PM
#9
Thread Starter
Member
Well... Iain17, you are a mind reader!!
By changing the myTabIndex=2
we (YOU) have it going!
For not knowing what I was asking, you certainly did show me the solution.
I have been pulling my hair out!! I had tried multiple versions of what you later suggested, but couldn't get it to go!
Life is good again.
Terry
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
|