Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
  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 Smile | :)
Posted 9-Dec-12 21:29pm
Comments
Zaf Khan at 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>
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
 
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
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You need to start with an initial i value - in this case i=6.
  Permalink  
Comments
lance12345 at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 741
1 OriginalGriff 255
2 Volynsky Alex 205
3 Kishore Pogaru 130
4 Magic Wonder 129
0 OriginalGriff 5,705
1 Sergey Alexandrovich Kryukov 4,763
2 CPallini 4,570
3 George Jonsson 3,142
4 Gihan Liyanage 2,450


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100