Running statements if a condition is true, Visual Basic Programming

To run only one statement while a condition is True, employ the single-line syntax for the If...Then...Else statement. The following instance shows the single-line syntax. Notice that this instance omits the Else keyword.

Sub FixDate() Dim myDate

myDate = #2/13/95#

If myDate < Now Then myDate = Now

End Sub

To run more than one line of code, you have to employ the multiple-line (or block) syntax. This syntax comprises the End If statement, as illustrated in the given example:

Sub AlertUser(value)

If value = 0

Then

AlertLabel.ForeColor = vbRed AlertLabel.Font.Bold = True AlertLabel.Font.Italic = True

End If

End Sub

Running particular Statements if a Condition is True & Running Others if a Condition is False

You can employ an If...Then...Else statement to define two blocks of executable statements: one block to run if the condition is True, the other block to run if condition is False.

Sub AlertUser(value) If value = 0 Then

AlertLabel.ForeColor = vbRed

AlertLabel.Font.Bold = True

AlertLabel.Font.Italic = True

Else

AlertLabel.Forecolor = vbBlack AlertLabel.Font.Bold = False AlertLabel.Font.Italic = False

End If

End Sub

 

The following flow chart explained the flow of the above example.

207_Running Statements if a Condition is True.png

Posted Date: 4/18/2013 5:39:50 AM | Location : United States







Related Discussions:- Running statements if a condition is true, Assignment Help, Ask Question on Running statements if a condition is true, Get Answer, Expert's Help, Running statements if a condition is true Discussions

Write discussion on Running statements if a condition is true
Your posts are moderated
Related Questions
Aim: To exhibit what is the day when the second command button is clicked and to clear the screen when the first command button is clicked. The functioning of this program is

The View: The view is used for visualising. For illustration, while performing word processing, the user works on a sequence of words which compose the text. If a user is perf

You are asked to create the LOTO game customized according to the following constraints: 1. Create a grid containing 20 numbers (20 buttons: button1, button2, …button20) 2. When t

Question 1 Create a VB application to make the text bold, italic, underlined and also color the text (using checkbox, option button, textbox controls) Question 2 Create a

STEPS TO CREATE A RECTANGLE IN THE CLIENT REGION 1. Generate a SDI application and name it as a brush. 2. Handle the WM_LBUTTONDOWN message for the CBrushView object id.

VISUAL INTERFACE DESIGN Instead of the graphic nature of the program, only the visualness of the inter action is important. The program must not focus on the GUI. On the other


ILLUSTRATION OF MDI APPLICATION USING A PROJECT 1. Choose the MDI option while generating the project by using the Appwizard. 2. Add the WM_LBUTTONDOWN message for the view

Adding Handlers With Class Wizard: Whenever a handler is added, the class wizard places the prototype for the message handler in the header (.H) file. It gives a skeleton hand

APPWIZARD   The Appwizard is a tool used for creating a project. It follows a series of steps to create a project. Steps Involved in Creating A Project: Step 1: Fr