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

Input box - dialogue box in visual basic , Input Box: To demonstrate t...

Input Box: To demonstrate the use of the Input Box as shown in figure. Now consider the illustration shown below: 1. Initiate a new project 2. Select the standard exe

Project on VB6.0, I need a VB6 software for making a soccerboard for 10 tea...

I need a VB6 software for making a soccerboard for 10 teams & automatically generate their fixtures

The Generic Variable and Specific Variable, Explain difference, Generic Var...

Explain difference, Generic Variable: Create Object Ex:-Ole-Automation . No need refer the object library. What is Specific Variable: Binding Procedure Early & Late Binding ( Can

Precompiled header file, THE PRECOMPILED HEADER FILE As soon as you gen...

THE PRECOMPILED HEADER FILE As soon as you generate a blank project, ahead of doing any coding you compile the project to generate .pch (that is the pre compiled header) file a

Software with inappropriate behavior - basics of gui design, Software With ...

Software With Inappropriate Behavior: You would save a document; print it, and then you'll try to close it. The program will ask you if you want to save. This is because; the

Displaying the database - data control, Displaying The Database: The T...

Displaying The Database: The Text box, image box, check box, labels, picture box can be bounded to the data control for exhibiting the data base contents. The two properties a

Create a procedure - vbscript, Each piece of data is passed in your process...

Each piece of data is passed in your process using an argument. Arguments serve like placeholders for the data you wish to pass into your process. You can name your arguments along

Programming project using straight-line method, Depreciation to a Salvage V...

Depreciation to a Salvage Value of 0.   For tax purposes an item may be depreciated over a period of several years, n. With the straight-line method of depreciation, each year th

Features of user interface design, FEATURES OF USER INTERFACE DESIGN Th...

FEATURES OF USER INTERFACE DESIGN The features like how will the software's are used? Who will be the users? What will be the life of the software? During its lifetime how ofte

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