Jump to content


Photo

visual basic


  • Please log in to reply
1 reply to this topic

#1 sammm

sammm

    Young Padawan

  • Members
  • Pip
  • 1 posts

Posted 16 May 2008 - 02:44 PM

I had just started learning vb6, and i'm suppose to try and make this thing...

Its a program that will show your grade when you type in your marks.

Here is my code so far...




Private Sub cmdpress_Click()

Dim Marks As Single
Marks = Val(txtresult.Text)
If Marks >= 80 Then
txtresult.Text = "A"
Else
If Marks >= 70 Then
txtresult.Text = "B"
Else
If Marks >= 60 Then
txtresult.Text = "C"

Else
If Marks >= 50 Then
txtresult.Text = "D"

Else
If Marks < 50 Then
txtresult.Text = "You FAIL"

Else
If Marks < 0 Then
txtresult.Text = "Incorrect Marks entered"

Else
If Marks > 100 Then
txtresult.Text = "Incorrect Marks entered"

End If
End If
End If
End If
End If
End If
End If
End Sub





The last 2 incorrect marks entered code dosent work...

And how do i make my program only accept reading numbers from 0-100

And how do i make it give me a message that says "invalid number range entered" if i typed in a number that is not within 0-100.

Please help me and explain it to me as simple as possible as i'm a noob.

Thank you.

Edited by sammm, 16 May 2008 - 02:46 PM.


#2 AG Malicious

AG Malicious

    Young Padawan

  • Members
  • Pip
  • 1 posts

Posted 18 May 2008 - 02:23 PM

There you go complete with error message. The reason the last 2 weren't working is because you need to set the limits first. Otherwise based on your code if you look at the first If statement anything 80+ will be set as "A" and if you look at your statement for "D" it will take everything below 50 including negative values.

Private Sub cmdpress_Click()

Dim Marks As Single
Dim errormessage As Integer

Marks = Val(txtresult.Text)

If Marks < 0 Or Marks > 100 Then
errormessage = MsgBox("Invalid Number Range Entered", vbCritical, "Invalid")
ElseIf Marks >= 80 Then
txtresult.Text = "A"
ElseIf Marks >= 70 Then
txtresult.Text = "B"
ElseIf Marks >= 60 Then
txtresult.Text = "C"
ElseIf Marks >= 50 Then
txtresult.Text = "D"
Else
txtresult.Text = "You FAIL"
End If

End Sub

Edited by AG Malicious, 18 May 2008 - 02:25 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users