I'm stuck with a problem and can't work it out.
I'm needing a visual basic . net program written.
What I've worked out is...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim linecount As Integer
Dim asteriskcount As Integer
Dim asterisk As String
Dim spacecount As Integer

For spacecount = linecount To 20 - 1

Next
asteriskcount = 20 - spacecount To linecount - 1

Next
ListBox1.Items.Add(spacecount)

But I'm not sure where to go from here...
Please help

Write a program to enter a number between 1 to 20 and it displays a triangle of starts (asterisks) similar to the sample. Note the number of blank spaces decrease each line.

Use a fixed-width font “Courier” so that the spaces and asterisks will have the same width. If player does not enter a number, it will require a numeric value. But if the number is not in the range from 1 to 20, it will also require entering another number.

*
**
***
****
*****
******
*******

Sorry my asterisks dont line up but you get an idea

The spaces didn't come out on thge triangle when I drew it.
Its meant to have 19 spaces then an asterisk, next line is 18 spaces then 2asterisks and next line is 17 spaces and 3 asterisks

Hi

> Use two for loops
> One for Number of Lines (User Input)
> Second For loop for Number of stars
> Number of spaces can be assigned by Space() function

Your corrected Code

Dim linecount As Integer
        Dim asteriskcount As Integer
        Dim asterisk As String
        Dim spaces As String

        spaces = Space(20)
        For linecount = 1 To 20
            asterisk = ""
            For asteriskcount = 1 To linecount
                asterisk = asterisk & "*" & spaces
            Next
            ListBox1.Items.Add(asterisk)
        Next

Thanks for your help.
This is what I got

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim linecount, number, asteriskcount, spacecount As Integer
Dim asterisk, space As String

ListBox1.Items.Clear()
If IsNumeric(TextBox1.Text) Then
number = Val(TextBox1.Text)

If number >= 1 And number <= 20 Then
number = TextBox1.Text
For linecount = 1 To number
space = " "
asterisk = ""
For spacecount = linecount To number - 1

space = space & " "
Next
For asteriskcount = number - spacecount To linecount - 1
asterisk = asterisk & "*"
Next
ListBox1.Items.Add(space & asterisk)
Next
Else
MsgBox("Enter a number between 1 and 20", MsgBoxStyle.Critical, "Error")
End If
Else
MsgBox("Enter a value please", MsgBoxStyle.Critical, "Error")
End If


End Sub


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close() 'Exits
End Sub
End Class

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.