Program Structure and Flow

1.25 Program Structure and Flow

Call Statement

 


[Call] procedurename[(argumentlist)]

 

procedurename required; n/a

The name of the subroutine being called

argumentlist optional; any

A comma-delimited list of arguments to pass to the subroutine being called

Description

Passes execution control to a procedure, function, or DLL procedure or function.

CallByName Function

Microsoft.VisualBasic.Interaction


CallByName(Object, ProcName, UseCallType, Args(  ))

 

Object required; Object

A reference to the object containing the procedure being called.

ProcName required; String

The name of the procedure to call.

UseCallType required; CallType constant

A constant of type CallType indicating what type of procedure is being called. The CallType constants are:

Constant

Value

Description

Method

1

The called procedure is a method

Get

2

The called procedure retrieves a property value

Let

4

The called procedure sets the value of a property

Args optional; any

A ParamArray argument representing the arguments required by the procedure being called.

Named Arguments

Yes, if Args( ) is omitted

Return Value

Depends on the return value (if any) of the called procedure

Description

Provides a method for calling a class member by name.

Since ProcName is a string expression, rather than the literal name of a routine, it is possible to call routines dynamically at runtime using a string variable to hold the various procedure names.

Do...Loop Statement

 


 
Do [{While | Until} condition]  Syntax 1.
  [statements]
[Exit Do]
  [statements]
Loop
Do  Syntax 2.
  [statements]
[Exit Do]
  [statements]
Loop [{While | Until} condition]

 

condition optional; Boolean expression

An expression that evaluates to True or False

statements optional

Program statements that are repeatedly executed while, or until, condition is True

Description

Repeatedly executes a block of code while or until a condition becomes True.

End... Statement

 


 
End
End Class
End Enum
End Function
End Get
End If
End Interface
End Module
End Namespace
End Property
End Select
End Set
End Structure
End Sub
End SyncLock
End Try
End With
End While

 

Description

Ends a procedure or a block of code.

Exit . . . Statement

 


 
Exit Do
Exit For
Exit Function
Exit Property
Exit Select
Exit Sub
Exit Try
Exit While

 

Description

Prematurely exits a block of code.

For . . . Next Statement

 


 
For counter = initial_value To maximum_value _
  [Step stepcounter]  
 'code to execute on each iteration
  [Exit For]
Next [counter]

 

counter required (optional with Next statement); any valid numeric variable

A variable that serves as the loop counter

initial_value required; any valid numeric expression

The starting value of counter for the first iteration of the loop

maximum_value required; any valid numeric expression

The value of counter during the last iteration of the loop

stepcounter optional (required if Step is used); any valid numeric expression

The amount by which counter is to be incremented or decremented on each iteration of the loop

Description

Defines a loop that executes a given number of times, as determined by a loop counter.

To use the For...Next loop, you must assign a numeric value to a counter variable. This counter is either incremented or decremented automatically with each iteration of the loop. In the For statement, you specify the value that is to be assigned to the counter initially and the maximum value the counter will reach for the block of code to be executed. The Next statement marks the end of the block of code that is to execute repeatedly, and it also serves as a kind of flag that indicates that the counter variable is to be modified.

For Each...Next Statement

 


 
For Each element In group
[statements]
[Exit For]
[statements]
Next [element]

 

element required; Object or any user-defined object type

An object variable to which the current element from the group is assigned

group required

An object collection or array

statements optional

A line or lines of program code to execute within the loop

Description

Loops through the items of a collection or the elements of an array.

GoTo Statement

 


GoTo label

 

label required; string literal

A subroutine name

Description

Passes execution to a specified line within a procedure.

If...Then...Else Statement

 


 
Standard syntax:
If condition Then
  [statements]
[ElseIf condition-n Then
  [elseifstatements] ...
[Else
  [elsestatements]]
End If
 
One-line syntax:
If condition Then [statements] [Else elsestatements]

 

condition required; Boolean

An expression returning either True or False or an object type

statements optional

Program code to be executed if condition is true

condition-n optional

Same as condition

elseifstatements optional

Program code to be executed if the corresponding condition-n is True

elsestatements optional

Program code to be executed if the corresponding condition or condition-n is False

Description

Executes a statement or block of statements based on the Boolean (True or False) value of an expression.

Return Statement

 


Return  In a subroutine
Return ReturnValue  In a function

 

ReturnValue required; any

The return value of the function

Description

Returns to the calling program from a subroutine or function.

Select Case Statement

 


 
Select Case testexpression
  [Case expressionlist-n
  [statements-n]] ...
  [Case Else
  [elsestatements]]
End Select

 

testexpression required; any

Any numeric or string expression whose value determines which block of code is executed.

expressionlist-n required; any

Comma-delimited list of expressions to compare values with testexpression

statements-n optional

Program statements to execute if a match is found between any section of expressionlist and testexpression

elsestatements optional

Program statements to execute if a match between testexpression and any expressionlist cannot be found

expressionlist can use any (or a combination of any) of the following:

expressionlist syntax

Examples

expression

iVar - iAnotherVar
iVar
expression To expression
5 To 10 
8 To 11, 13 to 15
"A" To "D"
Is comparisonoperator expression
Is = 10

Description

Allows for conditional execution of a block of code, typically out of three or more code blocks, based on some condition. Use the Select Case statement as an alternative to complex nested If...Then...Else statements.

Stop Statement

 


Stop

 

Description

Suspends program execution.

While...End While Statement

 


 
While condition
  [statements]
[Exit While]
[statements]
End While

 

condition required; Numeric or String

An expression evaluating to True or False

statements optional

Program statements to execute while condition remains True

ExitWhile optional; Keyword

Exits the While loop

Description

Repeatedly executes program code while a given condition remains True.

 



VB. NET Language Pocket Reference
VB.NET Language Pocket Reference
ISBN: 0596004281
EAN: 2147483647
Year: 2002
Pages: 31

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net