需要字符串在vb中用计数器递增

时间:2013-11-05 05:29:38

标签: vb.net while-loop counter increment

 Public Class Form1
Private Sub btnCreateRhombus_Click(sender As Object, e As EventArgs) Handles btnCreateRhombus.Click

    'Declarations
    Dim userInput As Integer
    Dim rowCount As Integer = 1
    Dim spaces As Integer = 0
    Dim stars As String = "****"

    'user imput
    userInput = Convert.ToString(TxtNum1.Text)

    'Calculations

    drawStarSub(userInput, stars, rowCount)

    drawSpaceSub(userInput, stars)

    'Output

End Sub

Sub drawStarSub(userInput As String, stars As String, rowCount As String)

    Dim count As Integer = 1

    While count <= userInput
        stars = stars & vbNewLine & stars

        count = count + 1
    End While

    'Output

    lblResult.Text = Convert.ToString(stars)

End Sub

Sub drawSpaceSub(userInput As Integer, stars As String)

End Sub
End Class

程序需要做的是绘制平行四边形 如果用户键入3,则有3行,4行有4行等...最多11行。 我需要为行增量和空间增量创建一个子。

我遇到麻烦的地方是使用“drawStarSub”中的计数器让“stars”字符串增加。提前感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

尝试用此

代替stars = stars & vbNewLine & stars
stars = stars & vbCrLf & stars

这对我有用。就个人而言,我会使用For循环而不是While循环,但这没什么大不了的。