Posted By

jimmykobe48 on 10/07/10


Tagged


Versions (?)

Case Statment


 / Published in: Visual Basic
 

  1. Select Case decPostDiscoutCost
  2. Case Is <= 1000D
  3. IntConfirmExit = MessageBox.Show("This amount qualifies for A100 frequent flier miles.", _
  4. "", _
  5. MessageBoxButtons.OK, _
  6. MessageBoxIcon.Information, _
  7. MessageBoxDefaultButton.Button1)
  8. If IntConfirmExit = vbOK Then
  9. Me.Close()
  10. End If
  11. Case 1000D To 1500D
  12. IntConfirmExit = MessageBox.Show("This amount qualifies for B500 frequent flier miles.", _
  13. "", _
  14. MessageBoxButtons.OK, _
  15. MessageBoxIcon.Information, _
  16. MessageBoxDefaultButton.Button1)
  17. If IntConfirmExit = vbOK Then
  18. Me.Close()
  19. End If
  20. Case 1500D To 2500D
  21. IntConfirmExit = MessageBox.Show("This amount qualifies for C750 frequent flier miles.", _
  22. "", _
  23. MessageBoxButtons.OK, _
  24. MessageBoxIcon.Information, _
  25. MessageBoxDefaultButton.Button1)
  26. If IntConfirmExit = vbOK Then
  27. Me.Close()
  28. End If
  29.  
  30. Case Is > 2500D
  31. IntConfirmExit = MessageBox.Show("This amount qualifies for D850 frequent flier miles.", _
  32. "", _
  33. MessageBoxButtons.OK, _
  34. MessageBoxIcon.Information, _
  35. MessageBoxDefaultButton.Button1)
  36. If IntConfirmExit = vbOK Then
  37. Me.Close()
  38. End If
  39.  
  40. End Select

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: oscarius on November 9, 2010

Wouldn't it be more legible to refactor it to the following:

     Dim strMileCount As String  'add a variable declaration to hold the frequent flyer miles awarded

    Select Case decPostDiscoutCost
        Case Is  2500D
            strMileCount = "D850"

    End Select

    strMileCount = "This amount qualifies for " & strMileCount & " frequent flyer miles."
    IntConfirmExit = MessageBox.Show(strMileCount, _
                                        "", _
                                        MessageBoxButtons.OK, _
                                        MessageBoxIcon.Information, _
                                        MessageBoxDefaultButton.Button1)
    If IntConfirmExit = vbOK Then
        Me.Close()
    End If
Posted By: oscarius on November 9, 2010

hmmm... something went a bit wrong there. here's the complete listing...

Dim strMileCount As String

Select Case decPostDiscoutCost Case Is 2500D strMileCount = "D850"

End Select

strMileCount = "This amount qualifies for " & strMileCount & " frequent flier miles." IntConfirmExit = MessageBox.Show(strMileCount, _ "", _ MessageBoxButtons.OK, _ MessageBoxIcon.Information, _ MessageBoxDefaultButton.Button1)

If IntConfirmExit = vbOK Then Me.Close() End If

You need to login to post a comment.