Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Select Case Question in VB6

Options
  • 26-04-2004 8:59am
    #1
    Registered Users Posts: 565 ✭✭✭


    Hey everyone this is a question from an exam paper i was studying
    I have the If statement piece working perfectly and the Select Case one nearly working but i just cant get the Case structures right
    Just wondering if anyone would be able to give it a go or show me where i might be making errors
    Thanks a lot


Comments

  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    FFS people aren't even writing out the questions anymore, just scanning them in.

    You want people to show you what you might of done wrong, post what you have done so far.


  • Registered Users Posts: 565 ✭✭✭Speedway


    ok here's the solution, got it worked out in case anybody is interested

    Option Explicit

    Private Sub cmdCalculate_Click()

    Dim intGrade As Integer
    intGrade = Val(txtGrade.Text)

    Select Case Val(txtGrade.Text)

    Case Len(intGrade) <= 0
    MsgBox "Please enter a grade", vbOKOnly + vbExclamation

    Case Is < 0
    MsgBox "please enter a grade between 0 and 100", vbOKOnly + vbExclamation
    Case Is > 100
    MsgBox "please enter a grade between 0 and 100", vbOKOnly + vbExclamation

    Case 0 To 39
    MsgBox "Fail", vbOKOnly + vbExclamation

    Case 40 To 54
    MsgBox "Pass", vbOKOnly + vbExclamation

    Case 55 To 61
    MsgBox "Lower Second Class Honours", vbOKOnly + vbExclamation

    Case 62 To 69
    MsgBox "Upper Second Class Honours", vbOKOnly + vbExclamation

    Case 70 To 100
    MsgBox "First Class Honours", vbOKOnly + vbExclamation



    End Select








    End Sub


  • Registered Users Posts: 1,421 ✭✭✭Merrion


    Case Len(intGrade) <= 0
    Probably means Len(txtGrade.Text) as an integer always has a non-zero length...


  • Registered Users Posts: 2,781 ✭✭✭amen


    speedway,

    based on the question your answer is wrong.
    You were asked to use and IF and Select Case.
    You have only used the Case
    you should also define a new variable called Message and stuff your message text into this within each case and the call the Msgbox function at then end
    makes the code a bit easier to read and more maintainable


  • Registered Users Posts: 2,781 ✭✭✭amen


    oops

    ignore
    based on the question your answer is wrong.
    I was wrong
    sorry


  • Advertisement
Advertisement