Monday, January 31, 2011

If Statements

This is a example of a If statement.
  Dim name, correct As String  
     name = "Dalonte"  
     If name = "Dalonte" Then  
       correct = "Yes"  
     End If  
     MessageBox.Show(correct)  

I just basically give name a value and put it in a if statement saying if name = the name i put in then it would output Yes.

This is a example of a If statment where its either or
  Dim name, correct As String  
     name = "Gibson"  
     If name = "Dalonte" Then  
       correct = "yes"  
     Else  
       correct = "no"  
     End If  
     MessageBox.Show(correct)  
This is just like my example above but the only thing i did different is that i added a "ELSE" so that if the name does not match up it was say no

This is a example of a if statement where many decisions are made
  Dim name, As String  
     name = "anderson"  
     If name = "Dalonte" Then  
       MessageBox.Show("First Name")  
     ElseIf name = "Gibson" Then  
       MessageBox.Show("last name")  
     ElseIf name = "anderson" Then  
       MessageBox.Show("Middle Name")  
     End If  
The only thing that i did different on this one is that i added a elseif statement which allows me to make more then 2 decisions.

This is a example of a case statement
 Select [ Case ] testexpression  
   [ Case expressionlist  
     [ statements ] ]  
   [ Case Else  
     [ elsestatements ] ]  
 End Select  

1st you have to make a Select case statement, then from there you can make as many cases as you want followed by a end Select

No comments:

Post a Comment