You are on page 1of 6

If-Then-Else

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load

End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles TextBox1.TextChanged

If Val(TextBox1.Text) >= 0 Then


TextBox2.Text = " Vision: St. Anthony's College is a Catholic Educational
institution committed to holistic human formation through Spirituality, Academic
Excellence and Community Service."
Else
TextBox2.Text = " Mission: To provide quality, holistic and relevant
educational programs and experiences for our students and other stakeholders in Antique
and the larger community."
End If
End Sub
End Class

If-Then-ElseIf
Public Class Form1

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles TextBox1.TextChanged
If Val(TextBox1.Text) >= 90 Then
TextBox2.Text = "A"

ElseIf Val(TextBox1.Text) >= 80 And Val(TextBox1.Text) <= 89 Then


TextBox2.Text = "B"

ElseIf Val(TextBox1.Text) >= 70 And Val(TextBox1.Text) <= 89 Then


TextBox2.Text = "C"

ElseIf Val(TextBox1.Text) >= 60 And Val(TextBox1.Text) <= 89 Then


TextBox2.Text = "D"
Else
TextBox2.Text = "F"
End If
End Sub
End Class

Public Class Form1

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text = "B" Or TextBox1.Text = "b" Then
TextBox2.Text = "Blue"
ElseIf TextBox1.Text = "R" Or TextBox1.Text = "r" Then
TextBox2.Text = "Red"
ElseIf TextBox1.Text = "G" Or TextBox1.Text = "g" Then
TextBox2.Text = "Green"
ElseIf TextBox1.Text = "Y" Or TextBox1.Text = "y" Then
TextBox2.Text = "Yellow"
Else
TextBox2.Text = "Unknown Color"

Select Case

Public Class Form1

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles TextBox1.TextChanged
Dim Hershey As String
Hershey = TextBox1.Text
Select Case Hershey
Case "B", "b"
TextBox2.Text = "Blue"
Case "R", "r"
TextBox2.Text = "Red"
Case "G", "g"
TextBox2.Text = "Green"
Case "Y", "y"
TextBox2.Text = "Yellow"
Case Else
TextBox2.Text = "Unknown Color"

End Select
End Sub
End Class

Public Class Form1

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles TextBox1.TextChanged
Dim Hershey As String
Hershey = TextBox1.Text
Select Case Hershey
Case "C", "c"
TextBox2.Text = "Cheese-Php. 145"
Case "P", "p"
TextBox2.Text = "Pepperoni- Php. 155"
Case "H", "h"
TextBox2.Text = "Ham and Bacon- Php. 170"
Case "S", "s"
TextBox2.Text = "Supreme- Php. 190"
Case "O", "o"
TextBox2.Text = "Overloaded- Php. 210"
Case Else
TextBox2.Text = "Not Included on the Menu"

End Select
End Sub
End Class

For Next (Loop)


Increment

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click
ListBox1.BeginUpdate()
Dim nCounter As Integer
For nCounter = 5 To 30 Step 5
ListBox1.Items.Add("Loop " & nCounter.ToString())
Next nCounter
ListBox1.EndUpdate()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button2.Click
Form2.Show()
Me.Hide()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button3.Click
Close()
End Sub
End Class

Decrement

Public Class Form2


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
ListBox1.BeginUpdate()
Dim nCounter As Integer
For nCounter = 30 To 5 Step -5
ListBox1.Items.Add("Loop " & nCounter.ToString())
Next nCounter
ListBox1.EndUpdate()

End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button2.Click
Form1.Show()
Me.Hide()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button3.Click
Close()
End Sub

End Class
Do While (Loop)

FORM 1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Form2.Show()
Me.Hide()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button2.Click
Form3.Show()
Me.Hide()
End Sub

Increment (Form 2)
Public Class Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click
ListBox1.BeginUpdate()
Dim nCounter As Integer
nCounter = 3
Do While nCounter <= 24
ListBox1.Items.Add("Loop " & nCounter.ToString())
nCounter = nCounter + 3
Loop
ListBox1.EndUpdate()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button2.Click
Form1.Show()
Me.Hide()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button3.Click
Close()
End Sub
End Class

Decrement (Form 3)
Public Class Form3

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click
ListBox1.BeginUpdate()
Dim nCounter As Integer
nCounter = 24
Do While nCounter >= 1
ListBox1.Items.Add("Loop " & nCounter.ToString())
nCounter = nCounter - 3
Loop
ListBox1.EndUpdate()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button2.Click
Form1.Show()
Me.Hide()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button3.Click
Close()
End Sub
End Class

List Box
Public Class Form1

Private Sub ListBox1_DoubleClick(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles ListBox1.SelectedIndexChanged
TextBox1.Text = ""
TextBox1.Text = ListBox1.Text
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load
ListBox1.Text = ""
TextBox1.Text = ""
ListBox1.Items.Add("Chicken")
ListBox1.Items.Add("Beef")
ListBox1.Items.Add("Pork")
ListBox1.Items.Add("Fish")
ListBox1.Items.Add("Vegetables")
End Sub
End Class

List Box2
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load
TextBox1.Text = ""
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click
ListBox1.Items.Add(TextBox1.Text)
TextBox1.Text = ""
TextBox1.Focus()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button2.Click
If ListBox1.Items.Count = 0 Then
MsgBox("No More Items")
Else
ListBox1.Items.RemoveAt(0)
End If
End Sub
End Class

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load
TextBox1.Text = ""

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click
ListBox1.Items.Add(TextBox1.Text)
TextBox1.Text = ""
TextBox1.Focus()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button2.Click
If ListBox1.Items.Count = 0 Then
MsgBox("No More Items")
Else
ListBox1.Items.RemoveAt(0)
End If
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button3.Click
If ListBox2.Items.Count = 0 Then
MsgBox("No More Items")
Else
ListBox2.Items.RemoveAt(0)
End If
End Sub

Private Sub ListBox2_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs)


Handles ListBox1.SelectedIndexChanged
ListBox2.Items.Add(ListBox1.Text)
ListBox2.Text = ""
ListBox2.Focus()

End Sub

End Class

You might also like