ISM 3230 Introduction to Programming 
Chapter 4 Student Learning OBJECTIVES:

Upon completion of this chapter, you will be able to

1.  Use block Ifs to control the flow of logic.

2.  Understand and use nested Ifs

3.  Read and create flowcharts indicating the logic in a selection process.

4.  Evaluate conditions using the relational operators.

5.   Combine conditions using And and Or.

6.   Test the Value property of option buttons and check boxes.

7.   Perform validation on numeric fields

8.   Call event procedures from other procedures.

9.   Create message boxes to display error conditions.

10. Apply the message box constants.

11. Debug projects using breakpoints, stepping program execution, and displaying intermediate results.

Index: 
  

Decision Making

Single-line IF statement Multi-line IF .. Else statement

If txtUserResponse = “Yes” Then

curTaxableIncome = 0

If intDependentNumber > 2 Then

lblAnswer.caption = “Two Dependents”

Else

lblAnswer.cpation = “Not Two Dependents”

End If

 

Comparison Operators

txtName.text <> "Frockmeister"

Val(txtAge.Text) > 25

optPrintForm.Value = True

chkDiscardStyles.Value = False

txtInterestRate.Text / 12 <= 0.05

 

IF Statement Structure (One-way)

 

IF Statement Structure (Two-way)

Example:

If Val(txtSat.text) > 600 Then

Msgbox “Admit”

Else

Msgbox “Do Not Admit”

End If

 

IF Statement Structure (Multi-way)


If Val(txtSat.text) > 600 Then

If Val(txtGPA) > 3.75 Then

Msgbox "Admit"
Else

Msgbox "Consider"

End if

Else
Msgbox "Do Not Admit"
End If

 

Conditions

Comparing Numeric Variables & Constants

Comparing Strings - the .Text property of text boxes -

 

ASCII Code Table

 

Uppercase / Lowercase Comparisons

will evaluate to false if the txtLastName contains SmITH or smith. A better way is to always do this type of operation:

If Ucase(txtLastName.Text) = "SMITH" Then ···

If Lcase(txtLastName.Text) = "smith" Then ...

 

Compound Conditions

 

If ... / Option Buttons / Check Boxes

Examples:

If chkFlag = True Then

imgFlag.Visible = True

If optDisplayForm Then

frmSecond.Show

Option Button Example Check Box Example

 


Displaying Messages in Message boxes

A Message Box is a special window displaying a message to the user.

Form:

MsgBox “message” [,buttons][, “t.b. caption”]

Example:

MsgBox “Numeric ID only”, vbOkOnly, “Error”

Buttons you can use:

Displaying a Message String

MsgBox stMessage, vbOKOnly, stTitle

 

Dim stMessageString as String

Dim stTitleBarString as String

stMessageString = "The top salary is: " & vbCrLf & curTopSal & " for 2001"

stTitleBarString = "Information for You"

MsgBox stMessageString, vbOkOnly, stTitleBarString

Message Box Return Values


Input Validation

 


Calling Event Procedures


Hands on Programming Example


Debugging VB Projects


Chapter Summary

STATEMENTS

 

FUNCTIONS

Call

 

IsNumeric

If…Then

 

Lcase

Else

 

Ucase

ElseIf

   

End If

   

MsgBox