In: Computer Science
Create code In visual Basic, Windows forms that uses case statements to convert the day of the week (entered by the user into an integer. (Sunday = 1, Monday = 2, etc.) For this code, think about error checking. What will your code do if the user enters “dog” for example (which is not a day of the week)? What will your code do if the user enters a number or other incorrect input?
Program:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim day As String
day = InputBox("Enter a day of the week: ")
Select Case day.ToLower
Case "sunday"
MessageBox.Show("Converted " & day & " of the week into
Integer: " & 1)
Case "monday"
MessageBox.Show("Converted " & day & " of the week into
Integer: " & 2)
Case "tuesday"
MessageBox.Show("Converted " & day & " of the week into
Integer: " & 3)
Case "wednesday"
MessageBox.Show("Converted " & day & " of the week into
Integer: " & 4)
Case "thursday"
MessageBox.Show("Converted " & day & " of the week into
Integer: " & 5)
Case "friday"
MessageBox.Show("Converted " & day & " of the week into
Integer: " & 6)
Case "saturday"
MessageBox.Show("Converted " & day & " of the week into
Integer: " & 7)
Case Else
MessageBox.Show("Incorrect Day!! " & vbNewLine & day &
" is not a day!!")
End Select
End Sub
End Class
Outputs: