OK, I am just learning.
I want to be able to print this when
a command button is clicked:
*
**
***
****
*****
******
*******
********
*********
**********
But I have to use a ForNext Loop...
Can someone please help me?
Printable View
OK, I am just learning.
I want to be able to print this when
a command button is clicked:
*
**
***
****
*****
******
*******
********
*********
**********
But I have to use a ForNext Loop...
Can someone please help me?
Why do you need a For...Next loop? Unless you need that for
a specific reason, try this
Code:Option Explicit
Private Sub Command1_Click()
Dim i As Single, J As Single
For i = 1 To 10
For J = 1 To i
Text1.Text = Text1.Text & "*"
Next
If i <> 10 Then Text1.Text = Text1.Text & vbNewLine
Next
End Sub
It's been a while since I've done this coding. This must be for school? The coding below is the ForNext loop you want, however I'm not sure if it will print the information on seperate lines. I do know you must set your textbox multiline property to true. I'm thinking this coding will work though, if not let me know, because I know I have the coding somewhere. You caught me at work without my dope books.
Dim i as integer
Dim Message as String
For i = 1 to 10 step 1
Message = Message + "*"
Next
Text1.text = Message
That would make the for next make sense. But I think he means to output into a picturebox control, hence:
'start a 10 step for next loop
For x = 1 To 10
For y = 1 To x
'print x number of stars, the ; makes it print on the same line
picbox.Print "*";
Next y
'print a blank so that it moves to the first line
picbox.Print ""
Next x
Also there are better ways to do this, but this way is low key and easy to understand
DrewDog has the right idea. I know I was doing it wrong. It's been a while since I've done that one. Sorry.
thanks guys! I had forgotten about printing a blank!
I think this is the shortest way:
Code:For i = 1 to 10
Text1.Text = Text1.Text & String(i,"*") & VbCRLF
Next