Hi Guys,
I am struggling on an assignment where I have to enter an odd number to produce a triangle of stars. e.g.
If I enter 5 - then it should look something like this
*****
***
*
My code is as follows:
Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click
Dim Number As Integer
Dim Index As Integer
Dim StarString(15) As String 'declare array as String
Number = CInt(txtNumber.Text)
StarString(0) = "" 'store stars in array (string)
StarString(1) = "*" 'odd numbers of stars from 1 to 15 -
StarString(2) = "" 'with negative even numbers
StarString(3) = "***"
StarString(4) = ""
StarString(5) = "*****"
StarString(6) = ""
StarString(7) = "*******"
StarString(8) = ""
StarString(9) = "*********"
StarString(10) = ""
StarString(11) = "***********"
StarString(12) = ""
StarString(13) = "*************"
StarString(14) = ""
StarString(15) = "***************"
If Number > 15 Then
MsgBox("Please enter a number between 5 and 15") 'triangle can only be formed
Else 'with a minimum of 5 stars
If Number < 5 Then 'on top row
MsgBox("Please enter a number between 5 and 15")
Else
For Index = 1 To Number Step 1
txtOutput.Text = (StarString(Index) & vbNewLine)
Next
Index = Index - 2
End If
End If
I can successfully generate the first line, but after that there is nothing.
I know it is possible to do it by using (VBNewline - number - 2), but that isn't what my tutor is looking for.
I have tried to use a loop - but can't get it to work, and so have taken it out. I know I am close - but no cigar.
Can someone please help?:confused: