'
'------------------------------------------------------------------------------ '
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ '
' Demonstration: Using Select Case '
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ '
' '
' Purpose : Demonstrates VBScript Select Case '
' ----------------------------------------------------------------------- '
' Creation Date : 09/01/2019 [dd/mm/yyyy] '
' Version : 1.0 '
' Designer : Fabian '
' '
'############################################################################## '
' MODIFICATION HISTORY '
'------------------------------------------------------------------------------ '
' Version : 1:0 09/01/2019 Create the Sample '
' '
'------------------------------------------------------------------------------ '
'
'## Select Case is very useful for handling multiple options in a single variable.
'## using this method, you can work through your task quickly and efficiently.
'
'## I have created a Message box to pose a Vote question with three possible options.
'## The question is: Do you like chocolate ?
'
'## The user can press Yes, No or Cancel on the Message Box. Each scenario
'## will return a confirmation Message box confirming the Vote on chocolate.
'
'
'--------------------------------------------------------------------------------
'
'## Memory Dimension for the Message Box
'
Dim Question 'As VbMsgBoxResult
'
'--------------------------------------------------------------------------------
'
'## Message Box Question
'## Message Box Text: Makes editing very easy when stored in a Const
'
Public Const MSGB_L1 = "Do you like chocolate ?"
Public Const MSGB_L2 = "Press Yes if you Do. Press No if you don't."
Public Const MSGB_L3 = "Press Cancel to Exit."
Public Const MSGB_L4 = "Chocolate Vote."
'
'--------------------------------------------------------------------------------
'
'## Message Box: Cancel or Close without pressing Yes or No will use this Text
'
Public Const MSGErr1 = "You have chosen to exit without voting."
Public Const MSGErr2 = "Good Bye"
'
'--------------------------------------------------------------------------------
'
'## Message Box Vote Confirmation text
'
Public Const VotedYes = "You voted Yes to liking chocolate."
Public Const VotedNo = "You voted No to liking chocolate."
Public Const VoteTop = "Vote Registered"
'
'--------------------------------------------------------------------------------
'
'## Message Box Return is stored in *Question*
'
Question = MsgBox(MSGB_L1 & _
VbCrLf & MSGB_L2 & VbCrLf & VbCrLf & MSGB_L3, _
VbSystemModal + VbExclamation + VbYesNoCancel, _
MSGB_L4)
'
'--------------------------------------------------------------------------------
'
'## Using *Select Case* to check each Message Box Scenario which could be:
'## VbYes | VbNo | VbCancel because of the *VbYesNoCancel* option used.
'
Select Case Question
'
'--------------------------------------------------------------------------------
'
'## Each possible *Case* you want to handle, is written like this. Case VbYes
'## Or Case VbNo and so on...
'
Case VbYes
'
'## Handle the Message Box VbYes option. A simple notify Message to the user.
'## But could call another Sub-Routine here or Event.
'
Msgbox VotedYes, _
VbSystemModal + VbOkOnly + VbInformation, _
VoteTop
'
'--------------------------------------------------------------------------------
'
'## Handle the Message Box VbNo option. Again, a simple notify Message to the user.
'## But could call another Sub-Routine here or Event.
'
Case VbNo
'
Msgbox VotedNo, _
VbSystemModal + VbOkOnly + VbInformation, _
VoteTop
'
Case VbCancel
'
Msgbox MSGErr1, _
VbSystemModal + VbOkOnly + VbInformation, _
MSGErr2
'
'--------------------------------------------------------------------------------
'
'## There are no further Cases needed to be handled, so End the Select.
'## You could add a Case Else statement and it's probably good practice to do
'## that. But I haven't used that here.
'
'--------------------------------------------------------------------------------
'
'Case Else
'
' Msgbox "Some Text", VbMsgBoxStyle, "Msgbox Title"
'
End Select
|