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

Appwizard, APPWIZARD   The Appwizard is a tool used for creating a p...

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

Runtime proggramming, i have a database i want mange it network and i want ...

i have a database i want mange it network and i want write it with vb.net so how i can do this

Constant naming conventions, Earlier versions of VBScript had no mechanism ...

Earlier versions of VBScript had no mechanism for making user-defined constants. Constants, if utilized, were implemented as variables & distinguished from other variables by using

Create a calculator application, Create a VB calculator application that ap...

Create a VB calculator application that appears as in the screen shots below. The user enters numbers in the textboxes labelled Number 1 and Number 2. When a calculati

Context-sensitive help, CONTEXT-SENSITIVE HELP   The Context-sensitive...

CONTEXT-SENSITIVE HELP   The Context-sensitive help gives online help for the circumstances which is associated with that state. The Context-sensitive help can be implemented

Create an application that calculates customer monthly bill, In this assign...

In this assignment, you will create an application that calculates and displays a customer's monthly cable bill. Your interface should look like this: Requirements:

Document view architecture, DOCUMENT VIEW ARCHITECTURE The Document/Vie...

DOCUMENT VIEW ARCHITECTURE The Document/View architecture is used to build an application based on the Microsoft Foundation Classes library. The Document/View architecture is s

Very Very Boards, This is from the book Programming in Visual Basic 2010 by...

This is from the book Programming in Visual Basic 2010 by Julia Case Bradley and Anita C. Millspaugh. The assignment is located in Chapter 3 on page 154. Before I type it in, I wou

Question, #question.algorithemtofindwhetheragivennumberisprime/not.

#question.algorithemtofindwhetheragivennumberisprime/not.

Multiple document interface (mdi) windows , MULTIPLE DOCUMENT INTERFACE (MD...

MULTIPLE DOCUMENT INTERFACE (MDI) WINDOWS   The SDI (Single document interface) supports one open window or document at a particular time. Microsoft's notepad and paint are il

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