Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The usage of For Each...Next statement in VBS

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces "For Each... Next sentence usage "related knowledge, in the actual case operation process, many people will encounter such a dilemma, then let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

Repeat a set of statements for each element in an array or collection.

For Each element In group

[statements]

[Exit For]

[statements]

Next [element]

parameter element

A variable used to enumerate all elements in a collection or array. For a collection, an element can be a Variant variable, a generic Object variable, or an arbitrarily specified Automation object variable. For arrays, element can only be a Variant variable.

group

The name of the collection or array of objects.

statements

One or more statements executed for each item in the group.

description

If there is at least one element in the group, the For Each block is executed. Once inside the loop, all statements in the loop are executed first on the first element in the group. As long as there are other elements in the group, the statements in the loop are executed for each element. Exit the loop when there are no other elements in the group, and continue execution from the statement after the Next statement.

Exit For can only be used for For Each... Next or For... The Next control structure provides another way to exit the loop. You can place any number of Exit For statements anywhere in the loop. Exit For is often used with conditional statements (e.g., If... Then) and immediately transfers control to the statement following Next.

For Each... Next loops are placed within one another to form nested For Each... Next cycle. But the element of each loop must be unique.

Note that if you omit the element in the Next statement, the program continues to execute as if it had been included. If the Next statement occurs before its corresponding For statement, an error is generated.

The following example illustrates how to use For Each... Next statement:

Function ShowFolderList(folderspec) Dim fso, f, f1, fc, s Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.GetFolder(folderspec) Set fc = f.Files For Each f1 in fc s = s & f1.name s = s & "

" Next ShowFolderList = sEnd Function" For Each... The content of "Next sentence usage" is introduced here. Thank you for reading it. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report