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

The view - document view architecture, The View: The view is used for ...

The View: The view is used for visualising. For illustration, while performing word processing, the user works on a sequence of words which compose the text. If a user is perf

Message routing - visual basic, Message Routing: The system posts the ...

Message Routing: The system posts the messages to a first-in, first-out queue known as the message queue or it sends the messages directly to a window procedure. The Messages

Program to draw a rectangle shape , Create a project that draw a rectangle ...

Create a project that draw a rectangle shape which may be either (*) or (+) according to the selected radio button. The number of rows in the shape will be taken from the 1 st

Scope and lifetime of variables, The scope of a variable is finding out by ...

The scope of a variable is finding out by where you declare it. While you declare a variable in a procedure, only code in that procedure can access or alter the value of that varia

Executesql - database application, Executesql: The ExecuteSQL is used ...

Executesql: The ExecuteSQL is used for executing the query on the database. The CRecordset uses the RFX mechanism to replace data between field data members of the record set

Switch 2 images, I have a problem with Visual Basic: exchangeable 2 image...

I have a problem with Visual Basic: exchangeable 2 images of place I have 2 picturebox''s placed a button when I click on the button, the 2 pictures of this place change with e

File system controls, FILE SYSTEM CONTROLS There are 3 file system cont...

FILE SYSTEM CONTROLS There are 3 file system controls as shown in figure. The drive list box, directory list box & the file list box. The drive list box control is used to exhi

Validation controls, Describe different validation controls of VB.net?

Describe different validation controls of VB.net?

Attributes, departmental store attributes

departmental store attributes

Data control, DATA CONTROL The data control is used to connect to the d...

DATA CONTROL The data control is used to connect to the database. Three properties are very necessary to connect to the database. The primary property is the database name. You

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