Loop - Do While ?

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
pinkpanther
Newbie
Posts: 9
Joined: Tue Aug 09, 2005 3:39 pm

Loop - Do While ?

Post by pinkpanther » Tue Aug 09, 2005 4:33 pm

Do you know the proper way to creat a loop in this VBScript, I am getting an error

VBSTART
set ShipDB = CreateObject("ADODB.Connection")
ShipDB.Open "maketickets"
SQLString = "select * from FLINLAND"
set rsPickList = ShipDB.Execute(SQLString)
rsPickList.MoveFirst
If Not rsPickList.EOF then
dowhile Not rs.Picklist.EOF
tech = rsPickList.Fields("Technician")
clearing = rsPickList.fields("clearing#")
code = rsPickList.fields("code")
phone = rsPickList.fields("tel#")
MsgBox tech
rePicklist.movenext
Loop
else
GetNextRecord = 0
end if
ShipDB.Close
VBEND
Message> tech
Pinkpanther

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Tue Aug 09, 2005 4:46 pm

From the VBScript Help File:

Do...Loop Statement
Repeats a block of statements while a condition is True or until a condition becomes True.

Do [{While | Until} condition]
[statements]
[Exit Do]
[statements]
Loop

Or, you can use this syntax:

Do
[statements]
[Exit Do]
[statements]
Loop [{While | Until} condition]

Arguments
condition

Numeric or string expression that is True or False. If condition is Null, condition is treated as False.

statements

One or more statements that are repeated while or until condition is True.

Remarks
The Exit Do can only be used within a Do...Loop control structure to provide an alternate way to exit a Do...Loop. Any number of Exit Do statements may be placed anywhere in the Do...Loop. Often used with the evaluation of some condition (for example, If...Then), Exit Do transfers control to the statement immediately following the Loop.

When used within nested Do...Loop statements, Exit Do transfers control to the loop that is nested one level above the loop where it occurs.

The following examples illustrate use of the Do...Loop statement:

Do Until DefResp = vbNo
MyNum = Int (6 * Rnd + 1) ' Generate a random integer between 1 and 6.
DefResp = MsgBox (MyNum & " Do you want another number?", vbYesNo)
Loop

Dim Check, Counter
Check = True: Counter = 0 ' Initialize variables.
Do ' Outer loop.
Do While Counter < 20 ' Inner loop.
Counter = Counter + 1 ' Increment Counter.
If Counter = 10 Then ' If condition is True...
Check = False ' set value of flag to False.
Exit Do ' Exit inner loop.
End If
Loop
Loop Until Check = False ' Exit outer loop immediately.
Requirements
Version 1

See Also
Exit Statement | For...Next Statement | While...Wend Statement


** Link to VBScript documentation download at http://www.mjtnet.com/resources.htm
MJT Net Support
[email protected]

pinkpanther
Newbie
Posts: 9
Joined: Tue Aug 09, 2005 3:39 pm

almost there

Post by pinkpanther » Tue Aug 09, 2005 5:04 pm

Are there tags to interchange between VB and the Macro Language?
I start the VBSTART

Get data records
Loop
VBEND

In between all of the I want to run the MACRO Scheduler code but then return to the loop for the next record. Do you have good samples of how to go back and forth from VB to MACRO language stuff?
Pinkpanther

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Tue Aug 09, 2005 5:09 pm

Yes, plenty of examples here.

Make a function in VBScript which gets the next record. Call that from MacroScript with VBEval:

VBSTART
.. various database code here
Function GetNext
..
End Function
VBEND

Label>looper
VBEval>GetNext,blabla
Goto>looper

So you do the loop in MacroScript, and call the VBScript function in each iteration. The VBscript function gets each row of data. Have it pass an obvious value on end of file so that the MacroScript loop knows to exit.
MJT Net Support
[email protected]

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts