Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Dim i, j As Integer


      TextBox1.TextAlign = HorizontalAlignment.Center
      Do While i < 1


          i = i - 1

          j = 1
          Do While j < i - 1
              TextBox1.Text = TextBox1.Text & " *"
          Loop
          TextBox1.Text = TextBox1.Text & vbCrLf
      Loop

  End Sub




need out put: inverted pyramid
S*****
S****
SS***
SS**
SS*

help tnx :)
Posted
Comments
Zaf Khan 10-Dec-12 23:23pm    
With reference to Solution 1...
If i is intially set to a value of more than 0 (zero) then the program will not enter the main loop because the statement...
<pre>
Do while i < 1
</pre>
is ALWAYS going to be FALSE
so you will NEVER reach the statement
<pre>
i = i - 1
</pre>

It seems to me that the integer i should increase instead of decrease, and you would need to set a value for it at the start. (if you the output to look like what you said)
Uhm. No, it should decrease but the While condition was off, I think

VB
Dim i, j As Integer
 

        TextBox1.TextAlign = HorizontalAlignment.Center
        '' clear the TextBox1.Text before you fill it with the *'s
        TextBox1.Text = ""
        '' Set the amount of *'s you want the first line to contain
        i = 7
        Do While i > 1
           
             j = 1
            Do While j < i
                TextBox1.Text = TextBox1.Text & "*"
                j = j + 1
            Loop
            TextBox1.Text = TextBox1.Text & vbCrLf

            '' I would decrease i here, and not before the j-loop so that i indicates the amount of *'s in each line correctly
            i = i - 1
        Loop
 
    End Sub


I'd try it like that, hope this helped!

P.S. Don't forget the TextBox1.Multiline = True . I know I would lol
also, if something still goes wrong please tell us what error message you're getting/whatever.

Another Edit: if you want the first line to have 5 *'s, you will want to set i to 5, not 7 as I did
 
Share this answer
 
v3
You need to start with an initial i value - in this case i=6.
 
Share this answer
 
Comments
lance12345 10-Dec-12 3:39am    
... still doesn't work

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900