Syntax
While Condition
Series of instructions
Wend
Remarks
Repeats a series of instructions between While and Wend while the specified condition is true. The While¼Wend control structure is often used in WordBasic to repeat a series of instructions each time a given piece of text or formatting is found in a Word document. For an example of this use of While¼Wend, see EditFind.
Example
This Windows example uses the Files$() function within a While¼Wend loop to insert a list of files in the current folder whose filenames end with the .DOC filename extension. The instruction a$ = Files$("*.DOC") returns the first filename with a .DOC extension and a$ = Files$() returns the next filename with a .DOC extension each time the instructions within the loop run. As soon as Files$() returns an empty string (""), indicating there are no other .DOC files in the current folder, the condition a$ <> "" is false and Word exits the While¼Wend loop.
FileNewDefault currdir$ = Files$(".") a$ = Files$("*.DOC") While a$ <> "" count = count + 1 a$ = FileNameInfo$(a$, 3) InsertPara : Insert a$ a$ = Files$() Wend StartOfDocument : Bold 1 Insert currdir$ + " contains" + Str$(count) + " files."
On the Macintosh, you can use a similar example to create a list of Word documents in the current folder by modifying the instruction that sets the currdir$ variable and by specifying a signature instead of "*.DOC" as the file specification. Replace the first two Files$() instructions in the previous example with the following instructions:
currdir$ = Files$(":") a$ = Files$(MacID$("W6BN"))
See Also
For¼Next, Goto, If¼Then¼Else, Select Case