Dim targetString As String
targetString = Console.ReadLine()
targetString = targetString.ToUpper
Select Case targetString
Case "A" To "L"
Console.WriteLine("A to L Executed")
Case "M" To "Z"
Console.WriteLine("M to Z Executed")
Case Else
Console.WriteLine("Else executed")
End Select
Console.ReadLine()
The next tutorial deals with days of the week
Dim strMessage As String
Select Case Now.DayOfWeek
Case DayOfWeek.Monday
strMessage = "Welcome Back!"
Case DayOfWeek.Wednesday
strMessage = "Hump day!"
Case DayOfWeek.Friday
strMessage = "TGIF!"
Case Else
strMessage = "Keep on truckin'!"
End Select
Console.WriteLine(strMessage)
Console.ReadLine()
Here is a tutorial using both fixed and range values.
Dim intInput As Integer
intInput = Console.ReadLine
Select Case intInput
Case 1
Console.WriteLine("Thank you for entering 1")
Case 2 To 10
Console.WriteLine("You entered a number between 2 and 10")
Case Is > 10
Console.WriteLine("That number is greater than 10. Too much!")
End Select
Console.ReadLine()
Here is a tutorial using several cases at once
Dim animal As String
Console.WriteLine("Choose between a snake, a bird, a horse, a cat, a dog, and a centipede.")
animal = Console.ReadLine()
animal = animal.ToUpper
Select Case animal
Case "BIRD"
Console.WriteLine("it has two legs")
Case "HORSE", "CAT", "DOG"
Console.WriteLine("it has four legs")
Case "SNAKE"
Console.WriteLine("it has no legs")
Case "CENTIPEDE"
Console.WriteLine("it has 100 legs")
End Select
Console.ReadLine()
Here is a tutorial I got from you tube on with statements
Public Class Form1
Dim btn1 As New Button
Dim btn2 As New Button
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With Me
.Text = "Working with the With statement."
.Size = New Point(500, 300)
.Location = New Point(400, 400)
End With
With btn1
.Location = New Point(20, 20)
.Text = "Click it"
.Enabled = "True"
.Width = 40
End With
With btn2
.Location = New Point(20, 80)
.Text = "Click it number 2"
.Enabled = False
.Width = 70
End With
Me.Controls.Add(btn1)
Me.Controls.Add(btn2)
End Sub
End Class
Here is a tutorial deal with With and forms
Dim frm As New Form
With frm
.BackColor = Color.Blue
.ForeColor = Color.Red
.Text = "The with statement"
Dim fnt As Font = .Font
MsgBox(fnt.Name)
.Enabled = True
.TopMost = True
.ShowDialog()
End With
Here is the final tutorial for today using a nested With statement
Imports System.Drawing
Imports System.Windows.Forms
Public Class Form1 : Inherits Form
Public Shared Sub Main()
Dim frm As New Form1
Application.Run(frm)
End Sub
Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With Me
.BackColor = Color.Gray
.ForeColor = Color.Red
.Text = "The with statement"
.Enabled = True
.TopMost = True
.MinimizeBox = False
For Each ctrl As Control In .Controls
With ctrl
.BackColor = SystemColors.Window
.AutoSize = False
End With
Next
End With
End Sub
End Class
No comments:
Post a Comment