BetaONE will rise again!

BetaONE will rise again! (http:\\b1.hcanet.com\forum/index.php)
-   Software Support (http:\\b1.hcanet.com\forum/forumdisplay.php?f=45)
-   -   VB6 Question... (http:\\b1.hcanet.com\forum/showthread.php?t=6835)

Sephiroth 23rd Feb 03 06:47 PM

I'm not sure if anybody here is good in VB or not other than Lucky who I dunno if will be on today or Zone-MR who is on vacation, but if so, can anybody tell me what I'm doing wrong in this bit of code?

Quote:


Private Sub cmdCalculate_Click()
   
   If txtName.Text = "" Then
       MsgBox "Please enter a student name."
   End If
   
   If ValidGrade(txtT1.Text) = False Then
       MsgBox "Please enter a number between 0 and 100 into Test 1."
   End If
   
   If ValidGrade(txtT2.Text) = False Then
       MsgBox "Please enter a number between 0 and 100 into Test 2."
   End If
   
   If ValidGrade(txtT3.Text) = False Then
       MsgBox "Please enter a number between 0 and 100 into Test 3."
   End If
   
   Dim pstrCGrade As Integer
   pstrCGrade = (Val(txtT1.Text) + Val(txtT2.Text) + Val(txtT3.Text)) / 3
   
   Select Case pstrCGrade
       Case "pstrCGrade = 100 To 90"
           MsgBox "Test A"
       Case "pstrCGrade = 79 To 89"
           MsgBox "Test B"
       Case "pstrCGrade = 69 To 78"
           MsgBox "Test C"
       Case "pstrCGrade = 59 To 68"
           MsgBox "Test D"
       Case "pstrCGrade = 0 To 58"
           MsgBox "Test F"
   End Select

End Sub

You enter a numeric into 3 text boxes... it tests they are numbers, and computes an average, that part works, but then the select case statement is what i'm having problems with.... it either gives me a type mismatch error or just doesn't do anything :angry:

Sephiroth 23rd Feb 03 06:58 PM

nevermind, this fixed it

Quote:


Private Sub cmdCalculate_Click()
   
   If txtName.Text = "" Then
       MsgBox "Please enter a student name."
   End If
   
   If ValidGrade(txtT1.Text) = False Then
       MsgBox "Please enter a number between 0 and 100 into Test 1."
   End If
   
   If ValidGrade(txtT2.Text) = False Then
       MsgBox "Please enter a number between 0 and 100 into Test 2."
   End If
   
   If ValidGrade(txtT3.Text) = False Then
       MsgBox "Please enter a number between 0 and 100 into Test 3."
   End If
   
   Dim pstrCGrade As Integer
   pstrCGrade = (Val(txtT1.Text) + Val(txtT2.Text) + Val(txtT3.Text)) / 3
   
   Select Case pstrCGrade
       Case 100 To 90
           lblCGrade.Caption = "A"
       Case 79 To 89
           lblCGrade.Caption = "B"
       Case 69 To 78
           lblCGrade.Caption = "C"
       Case 59 To 68
           lblCGrade.Caption = "D"
       Case 0 To 58
           lblCGrade.Caption = "F"
   End Select

End Sub



All times are GMT +1. The time now is 07:38 PM.

Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.