01 Mar 2010 @ 9:30 AM 

Exit For And Exit Do Statement

For…Next loop condition can be terminated by an Exit Forstatement. Consider the following statement block.

Dim x As Integer
For x = 1 To 10
Print x
If x = 5 Then
Print “The program exited at x=5″
End If
Next

The preceding code increments the value of x by 1 until it reaches the condition x = 5. The Exit For statement is executed and it terminates the For…Next loop. The Following statement block containing Do…While loop is terminated using Exit Do statement.

Dim x As Integer
Do While x < 10
Print x
x = x + 1
If x = 5 Then
Print “The program is exited at x=5″
Exit Do
End If
Loop

With…End With Statement

When properties are set for objects or methods are called, a lot of coding is included that acts on the same object. It is easier to read the code by implementing the With…End With statement. Multiple properties can be set and multiple methods can be called by using the With…End With statement. The code is executed more quickly and efficiently as the object is evaluated only once. The concept can be clearly understood with following example.

With Text1
.Font.Size = 14
.Font.Bold = True
.ForeColor = vbRed
.Height = 230
.Text = “Hello World”
End With

In the above coding, the object Text1, which is a text box is evaluated only once instead of every associated property or method. This makes the coding simpler and efficient.

Posted By: admin
Last Edit: 01 Mar 2010 @ 09:30 AM

EmailPermalinkComments (0)
Tags

 Last 50 Posts
 Back
 Back
Change Theme...
  • Users » 1
  • Posts/Pages » 33
  • Comments » 0
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight