Notes on using For Loops in Visual Basic.
This code will show a For Loop doing a calculation and displaying the results in a picture box and in a text box.
This slide shows the output from the two four loops. Again one goes in a Picture Box and one goes in a Text Box.
Note that the picture box and the text box were not big enough to receive all of the data.
Note that to clear the picture box use the name of the box .Cls for clear screen. With the text box, simply set it to null.
Note that for this example, I am assuming that ct and answer have been defined with Dim statements.
When the inner loop is complete and ct1 is incremented by 1, control drops down to the For ct2 as opposed to returning to it from the next ct2. This means that ct2 is initialized at 1.
When control is through the next, ct2 is incremented.
When control drops down from the outer For loop, ct2 is initialized at 1.
You can create a line break in a text box by inserting a carriage control followed by a line feed. The carriage control is the ANSI 13 and the line feed is ANSI 10. These can be entered as Chr(13) and Chr(10).
Remember concatenation puts things together as a unit. In Visual Basic, concatenation is done with the &. Technically it can also be done with the +, but this is discouraged since it can be confused with addition.
The scroll bar is a property of the text box so it is set up when the text box is created.
The code is on the next slide.
In this example, I have organized the properties of the TextBox by using the Categorized tab. In previous examples, I have used the Alphabetic tab. The Categorized organization simply groups the properties by appearance, behavior etc. and can make things easier to find. In this instance, I look under behavior for ScrollBars. Note that they are set to option 2 which is a Vertical scroll bar.
Note that ScrollBar is not a property of a picture box.
To review, this is a single For loop where X varies from 1 t0 10. When X reaches 10 the For loop is over and since there is no other code in the procedure, cmdCalc is also done.
This shows another example of a nested FOR loop where X is controlled by the outer loop and Y is controlled by the inner loop. Again, concatenation is not used and the elements in the picFor.Print are separated by semi-colons.
Note that the picture says ProjFor2 - apparently I forgot to change the names!
Note that with a negative step, X and Y start with larger values that will be reduced.