Wednesday, February 2, 2011

Using If and Case statements

1. Shipping Costs

 Public Class Form1
  
   Private Sub btnTotal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTotal.Click
  
     Dim itemscost As String
  
     Dim totalcost As Integer
  
     itemscost = txtItemsCost.Text
  
     If itemscost >= 50 Then
  
       totalcost = itemscost
  
     ElseIf itemscost < 50 Then
  
       totalcost = itemscost + 5
  
     End If
  
     MessageBox.Show(totalcost)
  
   End Sub
  
 End Class  

2. Temperature Control App

 Public Class Form1
  
   Private Sub btnTotal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTotal.Click
  
     Dim temp As Integer = txtTemp.Text
  
     Dim AC As Integer = 76
  
     Dim heat As Integer = 72
  
     If temp < heat Then
  
       MessageBox.Show("Heat Turned On")
  
     ElseIf temp > AC Then
  
       MessageBox.Show("AC Turned on")
  
     ElseIf temp <> heat And AC Then
  
       MessageBox.Show("Temperature Perfect")
  
     End If
  
   End Sub
  
 End Class  

3. Sock Size by Age
 Public Class Form1
  
   Private Sub btnTotal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSize.Click
  
     Dim size As String
  
     Dim age As String = txtAge.Text
  
     Select Case age
  
       Case 0 To 2
  
         size = "XS"
  
       Case 3 To 4
  
         size = "S"
  
       Case 5 To 8
  
         size = "M"
  
       Case 9 To 12
  
         size = "L"
  
       Case 13 To 20
  
         size = "XL"
  
     End Select
  
     MsgBox(size)
  
   End Sub
  
 End Class  

No comments:

Post a Comment