Running statements if a condition is true, Visual Basic Programming

Assignment Help:

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


Related Discussions:- Running statements if a condition is true

Steps for creating a multiple document interface (mdi) form, Steps for Crea...

Steps for Creating A MDI Form: 1. Build a new form and set IsMdiContainer property to true. 2. Build a child form class to add to the form. 3. Now Right click the proj

Vb script, We will discuss scripting language; called VB Script. VBScript i...

We will discuss scripting language; called VB Script. VBScript is Microsoft's scripting language. It enables us to write programs which enhance the power of Web pages by letting us

Events - intrinsic contol, Events: The Controls are placed on a form a...

Events: The Controls are placed on a form and then to make them functional an "event procedure" is related with the control object. An event process is what happens in respons

For next loop - vbscript, You can employ For...Next statements to run a blo...

You can employ For...Next statements to run a block of statements a specific number of times. For loops, employ a counter variable whose value is increased or decreased with each r

MATHEMATICS PROJECT, HOW TO SOLVE ORDINARY DIFFERENTIAL EQUETION IN VISUAL ...

HOW TO SOLVE ORDINARY DIFFERENTIAL EQUETION IN VISUAL BASIC PROGRAMMING

Option explicit declaration - data types, Option Explicit Declaration: ...

Option Explicit Declaration: If the option explicit is used essentially then all the variables will have to be declared. Or else an error will be reported saying that the vari

Cell phone application, to dial a person''s 10 digit number and assign it t...

to dial a person''s 10 digit number and assign it to their name

Match Game, I would like someone to look at my code and tell me why it''s n...

I would like someone to look at my code and tell me why it''s not working

Program to order a product from inventory, Write a program that permits the...

Write a program that permits the user to order a product from inventory. The user selects the product and enters the quantity. If there is sufficient quantity on hand of the produc

Vbscript procedures, A Sub procedure is a series of VBScript statements, en...

A Sub procedure is a series of VBScript statements, enclosed through Sub & End Sub statements which perform actions however don't return a value. A Sub procedure can take arguments

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd