For…Next Command
Repeats a block of instructions a certain number of times, from to .
For < counter > = < start > To < end >
< block of instructions >
Next
Examples:
‘Erase the displays
For i=1 to 5
Screen.Item(“Display”&i).Value = 0
next
Exercises:
1. Create three demo tags.
2. Insert a chart on screen.
3. By clicking on an [Add] button, create a pen for each tag.
4. By clicking on a [Remove] button, remove all the pens.
For Each … Next Command
A For Each…Next loop is similar to a For…Next loop. Instead of repeating the instructions of a block a specific number of times, a For Each…Next loop repeats a group of commands for each item in a collection. This command is useful when we do not know the quantity of elements.
For each < object > in < Collection >
< block of instructions >
Next
Examples:
‘Display the name of all the tags
For each tag in Application.GetObject(“Data”)
MsgBox tag.Name
next
Exercises:
5. Create three demonstration tags.
6. Insert a chart on screen.
7. By clicking on an [Add] button, create a pen for each tag.
While…Wend Command
This command executes a block of instructions while a certain condition is true:
While < condition >
< block of instructions >
Wend
Examples:
‘Add 1 while it is less than 10
While Tag.Value < 10
Tag.Value = Tag.Value + 1
Wend
Exercises:
8. Create a horizontal rectangle on screen that woks a progress bar.
9. Make the rectangle’s HorizontalPercentFill property range from 0 to 100 within a while command. Tip: To refresh the screen, use Frame’s Refresh command.