i need a whole function of this part of program . plz code it. plzs

This code does not do want i want it to do.

plz code it correct plz.

test average grade
90-100 A
80-89 B
70-79 C
60-69 D
50-59 F

If value > 90 Then
Me.GradeLabel.Text = "A"
ElseIf value >= 80 & value <= 89 Then
Me.GradeLabel.Text = "B"
ElseIf value >= 70 & value <= 79 Then
Me.GradeLabel.Text = "C"
ElseIf value >= 60 & value <= 69 Then
Me.GradeLabel.Text = "D"
ElseIf value >= 50 & value <= 59 Then
Me.GradeLabel.Text = "F"
End If


Jakob Mall

Comments

  • : This code does not do want i want it to do.
    :
    : plz code it correct plz.
    :
    : test average grade
    : 90-100 A
    : 80-89 B
    : 70-79 C
    : 60-69 D
    : 50-59 F
    :
    : If value > 90 Then
    : Me.GradeLabel.Text = "A"
    : ElseIf value >= 80 & value <= 89 Then
    : Me.GradeLabel.Text = "B"
    : ElseIf value >= 70 & value <= 79 Then
    : Me.GradeLabel.Text = "C"
    : ElseIf value >= 60 & value <= 69 Then
    : Me.GradeLabel.Text = "D"
    : ElseIf value >= 50 & value <= 59 Then
    : Me.GradeLabel.Text = "F"
    : End If
    :
    :
    : Jakob Mall
    :
    [red]#############################################################[/red]

    Try this:

    [code]

    Value = Val(txtTextBox.Text)

    Select Case Value

    Case 90 to 100
    Me.GradeLabel.Text = "A"
    Case 80 to 89
    Me.GradeLabel.Text = "B"
    Case 70 to 79
    Me.GradeLabel.Text = "C"
    Case 60 to 69
    Me.GradeLabel.Text = "D"
    Case Else
    Me.GradeLabel.Text = "F"
    End Select[/code]

    [blue]**Remember that if you are getting the grades via a textbox, they are coming in as strings even though they are numbers.




  • [b][red]This message was edited by jbassmanp at 2005-5-26 21:5:20[/red][/b][hr]
    [b][red]This message was edited by jbassmanp at 2005-5-12 19:13:16[/red][/b][hr]
    : This code does not do want i want it to do.
    :
    : plz code it correct plz.
    :
    : test average grade
    : 90-100 A
    : 80-89 B
    : 70-79 C
    : 60-69 D
    : 50-59 F
    :
    : If value > 90 Then
    : Me.GradeLabel.Text = "A"
    : ElseIf value >= 80 & value <= 89 Then
    : Me.GradeLabel.Text = "B"
    : ElseIf value >= 70 & value <= 79 Then
    : Me.GradeLabel.Text = "C"
    : ElseIf value >= 60 & value <= 69 Then
    : Me.GradeLabel.Text = "D"
    : ElseIf value >= 50 & value <= 59 Then
    : Me.GradeLabel.Text = "F"
    : End If
    :
    :
    : Jakob Mall
    :
    Change the & to AND and operation works also last check could just be :
    else
    Me.GradeLabel.Text = "F"

    I agree that the CASE method is better/faster I was just pointing out that the coded didn't work because of the & command instead of the AND






  • : [b][red]This message was edited by jbassmanp at 2005-5-12 19:13:16[/red][/b][hr]
    : : This code does not do want i want it to do.
    : :
    : : plz code it correct plz.
    : :
    : : test average grade
    : : 90-100 A
    : : 80-89 B
    : : 70-79 C
    : : 60-69 D
    : : 50-59 F
    : :
    : : If value > 90 Then
    : : Me.GradeLabel.Text = "A"
    : : ElseIf value >= 80 & value <= 89 Then
    : : Me.GradeLabel.Text = "B"
    : : ElseIf value >= 70 & value <= 79 Then
    : : Me.GradeLabel.Text = "C"
    : : ElseIf value >= 60 & value <= 69 Then
    : : Me.GradeLabel.Text = "D"
    : : ElseIf value >= 50 & value <= 59 Then
    : : Me.GradeLabel.Text = "F"
    : : End If
    : :
    : :
    : : Jakob Mall
    : :
    : Change the & to AND and operation works also last check could just be :
    : else
    : Me.GradeLabel.Text = "F"
    :
    :
    :
    :
    :
    :
    The best, fastest and easiest way do do this is to use a select statement. If this was my program I would make it a function (because you probably need it in more than one place, entering, displaying, etc.), then just call the function to get the value and display it

    Public Function getGrade (ByRef value as Integer) as String
    Select Case value
    Case>100
    'display some sort of error message, value is to high, or
    'maybe a bonus mark given higher than A, such as A++
    Case>=90
    getGrade="A"
    Case>=80
    getGrade="B"
    Case>=70
    getGrade="C"
    Case>=60
    getGrade="D"
    Case>=50
    getGrade="F"
    Case Else
    'display error message, value is too low, but personally I
    'would make below 50 the F mark, the case else will perform
    'an action if no other action is peformed, so you can use it
    'to take any action you wish if the mark is below 50
    End Select
    End Function

    Now just put the function in a module or something and then just call it when you need the value like this whenever you need it:

    Me.GradeLabel.Text=getGrade(intValue)



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories