- Information
- AI Chat
Was this document helpful?
VB - download
Course: Civil Engineering (BSCE 01)
136 Documents
Students shared 136 documents in this course
University: Ateneo de Davao University
Was this document helpful?
VB: Program Flow Alteration
Decision-making is not only for humans who consider result of the decision before
putting it into action. Yet, it is also an important part in programming. Decision-making
process helps to resolve problems to provide the appropriate output using conditions.
Essential Knowledge
Conditions (also called as conditional expressions or conditional statements) are used to
determine which code should be processed next, to control the program flow and make
decisions. An action is only performed when a particular condition exists in the
program. Otherwise, no action will be performed
IF…Then Statement
If…Then statement is the most used condition which is equivalent to English phrase “If
such-and-such is true, then do so-and-so.” It is a single path statement which executes a
statement or a block of statements only if the condition is true. Otherwise, when the
condition is false, no action will be performed.
The basic syntax of If…Then statement is:
If (condition) Then
Statement
End If
For example:
“If the digit is 1-9, then it is less than 10. Else, it is greater than 10”
If digit < 10 Then
Msgbox(“Less than 10!”)
End If
Where the first line contains the condition: if the digit is less than 10; the second line
contains the ‘what to do’ statement if first line met the condition, wherein a message box
will appear with a statement of “Less than 10!”; the third line tells VB that the statement
ends here. Otherwise, no action will be performed when greater or equal to 10.
IF…Then…Else Statement
If…Then…Else statement is used to provide choices on the program flow. This
conditional statement will perform an action specified by the condition statement which
is true. Otherwise, an alternative action will be executed when the condition is false.
The basic syntax for If…Then…Else statement is:
If condition Then
Statement -True Condition
Else
Statement -False Condition
End If
For example:
“If the digit is 1-9, then it is less than 10. Else, it is greater than 10”
If digit < 10 Then
Msgbox(“Less than 10!”)
Else