Hi, I am hoping you guys could help me with this.

I am trying to loop number into something like this.

0
12
345
6789

here is my code:

Dim i As Integer
Dim j As Integer
j = CInt(TextBox1.Text)

For i = 0 To j
    label1.text = i
Next

I don't have any idea how will I do it like that

I tried searching for other and did not understand how to do it since they normally do it on console

Edited 4 Years Ago by Nick Evan: fixed code tags

Put the numbers into one string.
Use a substring to determine the offset and the length of what you're printing.
Loop 4 times.

Comments
thanks that helped me

Hi. thanks for the advise and I have already done it, but what if I am going to input the number of rows how will I be able to do it like a pyramid or a right angle.
for example:
I typed "4" into textbox

output should be in label:
0
12
345
6789

and when "3":
0
12
345

This does something very close to what you want, try to use this as a reference.

    Dim j As Integer = CInt(TextBox1.Text)
    Dim numOfPasses As Integer = j

    Dim numbers() As String = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}


    For i = 0 To j
        Dim lineString As String = ""
        numOfPasses = i + 1
        While numOfPasses <> 0
            lineString &= numbers(numOfPasses)
            numOfPasses -= 1
        End While
        ListBox1.Items.Add(lineString)
    Next
Comments
thanks, it helped a lot

If there is a mathematical formula that generates the sequence 0, 12, 345, 6789, ... then you can use it. Otherwise you can use

    Dim numberOfPasses As Integer = 3 'you would likely get the number from a control

    For Each s As String In {"0", "12", "345", "6789"}
        numberOfPasses -= 1
        if numberOfPasses < 0 Then Exit For
        label1.Text = s
    Next

Although I feel I should point out that there is no reason to do this in a loop. What is the point of "writing" each iterated value into the textbox when the next iteration will just overwrite the previous value? It would all happen so quickly that the previous values would never be seen. You'd be better off storing the numbers 0, 12, etc in an array, then indexing into that array with the user input "level" number (of course, checking beforehand to ensure that the user selected value falls within the array).

This question has already been answered. Start a new discussion instead.