I'm trying to create VBA for a simple grading system. User enters score in text box...if they input letters message box asking for numbers only appears,
would like also for them only to input numbers between 0 and 100 with message box if they put higher or lower values in. I cant get the later working. wondering if its as simple as my code being wrong?
Private Sub cmdCalculate_Click() Dim Num1 As Single Dim Num2 As Single Dim Num3 As Single Dim Answer As Single Num1 = Val(txtEnglish.Text) Num2 = Val(txtMaths.Text) Num3 = Val(txtScience) Answer = (Num1 + Num2 + Num3) / 3 TxtAnswer.Text = Str(Answer) If Not (IsNumeric(txtEnglish.Text & txtMaths.Text & txtScience.Text)) Then MsgBox ("Please enter numeric scores only") txtEnglish.Text = "" txtMaths.Text = "" txtScience.Text = "" If Not (IsNumeric(txtEnglish.Value & txtMaths.Value & txtScience.Value >0 & <100 txtEnglish.Text & txtMaths.Text & txtScience.text)) Then MsgBox ("Scores between 0 and 100 only") txtEnglish.Text = "" txtMaths.Text = "" txtScience.Text = "" End If If TxtAnswer.Text >= 50 Then lblPassFail.Caption = "PASS" If TxtAnswer.Text <= 49 Then lblPassFail.Caption = "FAIL" End Sub
Bookmarks