Monday, February 14, 2011

Practice 2 assignment

1.
 Public Class Form1  
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click  
     Dim total, cost As Integer  
     cost = 60  
     If cost < 50 Then  
       total = cost + 5  
     ElseIf cost > 50 Then  
       total = cost  
     End If  
     MessageBox.Show(total)  
   End Sub  
 End Class  

2.
 Public Class Form1  
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click  
     Dim temp As Integer  
     temp = 72  
     If temp < 72 Then  
       MessageBox.Show("The Heat is on")  
     ElseIf temp > 76 Then  
       MessageBox.Show("The AC is on")  
     ElseIf temp > 77 & temp < 71 Then  
       MessageBox.Show("Idle")  
     End If  
   End Sub  
 End Class  

3.
 Public Class Form1  
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click  
     Dim size As String  
     Dim shirt As String  
     size = 5  
     shirt = size  
     Select Case shirt  
       Case 0 To 2  
         size = "XS"  
       Case 3 To 5  
         size = "S"  
       Case 6 To 8  
         size = "M"  
       Case 9 To 11  
         size = "L"  
       Case Is < 11  
         size = "XL"  
     End Select  
     MessageBox.Show(size)  
   End Sub  
 End Class  

No comments:

Post a Comment