homecode zoneQuick Codedownloadssubmit codeabout usfeedbackscontact ussitemap
 
Beginners
Database
File System Object
General
Graphics
Multimedia
Networking
Shell Object
Timer
Array
Date/Time
Declaration
Error Handling
File/Folder
Logic
Loops & Conditional
Math
Miscellaneous
Strings
Values
Pro - Languages
C/C++
Java
Visual basic
asp
vb.net 2003/2005
asp.net
Quick Code
SUBMIT CODE
Mail List
LINKS
Submit LINK
 
ProgrammerGuide.net - VB Loops & Conditional.
Home » VB Zone » Loops & 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:

Part Description
condition Required. 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.
   
statements Optional 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.
else Optional. 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:

Statement Description
End Terminates 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 Function Required to end a Function statement.
End If Required to end a block If…Then…Else statement.
End Property Required 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 Type Required to end a user-defined type definition (Type statement).
End With Required 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

« Previous 1 2 3 4 5 6 Next »

Viewers: 16
Visitors:127291
Last Updated on:Sunday, January 17, 2010
Home | About us | Feedback | Contact us | Sitemap
Copyright © 2008 ProgrammerGuide.net. All rights reserved.
This site is best viewed in IE 6.0, Firefox 1.5 and above with screen resolution of 1024 X 768.