General discussion

Locked

Nested For Next Loops

By tony3198 ·
I need to write a simple program in VB that prints a Diamond Shape on the form, using For next reptition structures. The size should be about 9 rows/columns in courier bold.

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Nested For Next Loops

by TimTheToolMan In reply to Nested For Next Loops

Triple Ha!

Assignment one, question 3?

Cheers,
Tim.

Collapse -

Nested For Next Loops

by tony3198 In reply to Nested For Next Loops

Actually tim you are partly correct, its an assingment from Ch3 VB6 by Deitel & Deitel. But it is not for school, as I am trying to learn this on my own. I came up with some results that are diamond shaped but when I change the font to courierit will not appear exactly as it does in the book. The code I used is: Private Sub Command1_Click()
For R = 1 To 10
For c = 10 To R Step -1
Print " ";
Next c

For X = 1 To R
Print "$";
Next X
Print

Next R
For R = 1 To 10 For c = 2 To R
Print " ";
Next c

For X = 11 To R Step -1
Print "$";
Next X
Print
Next R

End Sub

Collapse -

Nested For Next Loops

by TimTheToolMan In reply to Nested For Next Loops

Hi,

In that case, well done.

Your Bold Courier is likely to be a proportional font and so the spacings aren't consistent.

Its not a fault of your code so dont be worried by it.

Cheers,
Tim.

Collapse -

Nested For Next Loops

by tony3198 In reply to Nested For Next Loops

After fooling with it for a while I finally got it. This works even w/courier Bold.

Private Sub Command1_Click()
For R = 1 To 10 Step 2
For c = 10 To R Step -2
Print " ";
Next c

For X = 1 To R
Print "$";
Next X
Print
Next R

For R = 1 To 7 Step 2
For c = -1 To R Step 2
Print " ";
Next c

For X = R To 7
Print "$";
Next X
Print
Next R

End Sub

Collapse -

Nested For Next Loops

by tony3198 In reply to Nested For Next Loops

This question was closed by the author

Back to Web Development Forum
5 total posts (Page 1 of 1)  

Software Forums