ProgrammerGuide.Net | Step by Step Programmer Guide

VB-Loop conditional

Loop conditional,

If…Then…Else Statement
Conditionally executes a group of statements, depending on the value of an expression.

Syntax
If condition Then [statements] [Else elsestatements]
Or, you can use the block form syntax:
If condition Then
[statements]
[ElseIf condition-n Then
[elseifstatements] …
[Else
[elsestatements]]
End If
The If…Then…Else statement syntax has these parts:

PartDescription
conditionRequired. One or more of the following two types of expressions:A numeric expression or string expression that evaluates to True or False.If condition is  Null, condition is treated as False An expression of the form TypeOf objectname Is objecttype. TheObjectname is any object reference and objecttype is any valid object type.The expression is True if    objectname is of the object type specified by objecttype; otherwise it is False.
  
statementsOptional in block form; required in single-line form that has no Else clause.One or more statements separated by colons; executed if condition is True.
condition-n Optional. Same as condition.
elseif Optional. One or more statements executed if associated condition-n is True.
elseOptional. One or more statements executed if no previous condition expression is True.

Example:
Dim Number, Digits, MyString
Number = 53 ‘ Initialize variable.
If Number < 10 Then
Digits = 1
ElseIf Number < 100 Then

‘ Condition evaluates to True so the next statement is executed.
Digits = 2
Else
Digits = 3
End If

End Statements
Ends a procedure or block.
Syntax : End, End Function, End If, End Property, End Select, End Sub, End Type, End With

Remarks
When executed, the End statement resets all module-level variables and all static local variables in all modules. To preserve the value of these variables, use the Stop statement instead. You can then resume execution while preserving the value of those variables.
The End statement syntax has these forms:

StatementDescription
EndTerminates execution immediately. Never required by itself but may beplaced anywhere in a Procedure to end code execution, close files openedwith the Open statement and to clear
End FunctionRequired to end a Function statement.
End IfRequired to end a block If…Then…Else statement.
End PropertyRequired to end a Property Let, Property Get, or Property Set procedure.
End Select Required to end a Select Case statement.
End Sub Required to end a Sub statement.
End TypeRequired to end a user-defined type definition (Type statement).
End WithRequired to end a With statement.

Example:
 Sub Form_Load
 Dim Password, Pword
 PassWord = “Swordfish”
 Pword = InputBox(“Type in your password”)
 If Pword <> PassWord Then
 End
 End If
 End Sub

Please click here for related products on Amazon!

Jayashee

Add comment

Want to Check Celebrities News?