Friday, February 11, 2011

If Statements

A conditional expression is formed by relating values, either constants or variables . The comparison is evaluated as Boolean True or False, and the script reacts to that condition. The following script presents a simple example of script decision making, making one decision.
  If Args.CommandName = "Button 1" Then
  
   ButtonResponse.Text = "You clicked Button 1"
  
  End If
  
 End Sub
  
This shows an If statement of either or:
     Dim Message As String
  
     Message = "Skittles is an old form of bowling in which a wooden " & "disk is used to knowck down nine pins arranged in a square."
  
     If txtmessage.Text.ToUpper = "N" Then
  
       MessageBox.Show(Message, "Definition")
  
     End If
  
     txtQuote.Text = "Life ain't all beer and skittles." & " - Du Maurier (1894)"
  
   End Sub
  
 End Class  

This can make many decision depending on what it asks for, here it's honor students according to a certain GPA.
    Dim gpa As Double = CDbl(txtGpa.Text) 
  
    Dim honors As String 
  
    If gpa >= 3.9 Then 
  
     honors = " summa cum laude." 
  
    ElseIf gpa >= 3.6 Then 
  
     honors = " magna cum laude." 
  
    ElseIf gpa >= 3.3 Then 
  
     honors = " cum laude." 
  
    ElseIf gpa >= 2 Then 
  
     honors = "." 
  
    End If 
  
    txtResults.Text = "You graduated" & honors 
  
   End Sub 
  

No comments:

Post a Comment