Help - Search - Members - Calendar
Full Version: visual basic
Pixel2Life Forum > Help Section > Desktop Programming
sammm
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.
AG Malicious
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

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.