For next loop - vbscript, Visual Basic Programming

Assignment Help:

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 repetition of the loop.

For instance, the following procedure causes a procedure called MyProc to execute 50 times. The For statement indicate the counter variable x and its begin and end values. The Next statement enhanced the counter variable by one.

Sub DoMyProc50Times() Dim x

For x = 1 To 50

MyProc

Next

End Sub

By using the Step keyword, you can increase or decrease the counter variable through the value you indicate. In the following instance, the counter variable j is enhanced by 2 each time the loop repeats. While the loop is finished, total is the sum of 2, 4, 6, 8, & 10.

Sub TwosTotal() Dim j, total

For j = 2 To 10 Step 2 total = total + j

Next

MsgBox "The total is " & total

End Sub

To reduce the counter variable, you employ a negative Step value. You have to specify an end value that is less than the start value. In the given example, the counter variable myNum is reduced by 2 each time the loop repeats. While the loop is finished, total is the sum of 16, 14, 12, 10, 8, 6, 4, & 2.

Sub NewTotal()

Dim myNum, total

For myNum = 16 To 2 Step -2 total = total + myNum

Next

MsgBox "The total is " & total

End Sub

You can exit any For...Next statement before the counter reaches its end value by using the Exit For statement. Since usually you want to exit only in certain situations, such as while an error take place, you must use the Exit For statement in the True statement block of an If...Then...Else statement. If condition is False, the loop runs usually.  Or else perhaps you did not need to employ the loop in the first place.


Related Discussions:- For next loop - vbscript

External application window position, I have an external application I open...

I have an external application I open from visual studio (excel). I want to reposition where that opens (top, left).. How do I do that?

Wage calculator and ta calculations, ( Wage Calculator with Tax Calculation...

( Wage Calculator with Tax Calculations) Develop an application that calculates an employee’s earnings, as shown in Fig. 4.23. The user should provide the hourly wage and number of

Hotel management system, i need to do my final project for my last year bsc...

i need to do my final project for my last year bsc honours degree in Business Information systems. I need to develop a system which is operational for hotel management system. th

Vbscript operators, VBScript Operators VBScript contain a full range of...

VBScript Operators VBScript contain a full range of operators, including comparison operators, arithmetic operators, concatenation operators, and logical operators.

Steps to create a rectangle in the client region, STEPS TO CREATE A RECTANG...

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.

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

Creation of the menu in visual basic, Creation of the Menu in VB 1. Ini...

Creation of the Menu in VB 1. Initiate a new project by choosing a file and then new project. 2. Now select the Standard EXE as the Project type. 3. Build the Form1 activ

Retrieval methods - document in visual programming, Retrieval Methods: ...

Retrieval Methods: There are 3 ways to find a document. The primary method is a positional retrieval. This is achieved by keeping in mind where you left it. The next method is

Programming, steps of connecting database from vb6.0

steps of connecting database from vb6.0

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