I'm having a problem with my for loops. The program is supposed to get a number from the user and when button is pressed add 1 and skip a line until the tenth number is reached. I fell like I almost have it but I'm missing something. Please help.

Public Class Form1

    Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
        Dim intCounter As Integer
        Dim number As Integer
        Dim result As Integer
        Dim wrap As String
        wrap = Chr(13) & Chr(10)
        number = numberBox.Text


        For intCounter = 1 To 10


            TextBox2.Text = number + 1 & wrap

        Next intCounter



    End Sub

    Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()

    End Sub
End Class

You should increase number-variable in For Next loop like this:

For intCounter = 1 To 10
  TextBox2.Text = number & wrap
  number += 1
Next intCounter

number variable not increase.

Thank You, for your response, still having problems though. I've changed the program as suggested and when a number is entered it just displays 'number+10' eg. user enters 5 it'll spit out 15. I need it to display as follows
user enter 5 program prints
6
7
8
9
10
11
12
13
14
15

I thought it might work with the 'wrap' variable that I've defined, but of course it didn't.
Any additional help would be greatly appreciated, understanding this will open up my next assignment. Thank you.

Public Class Form1



    Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click

        Dim intCounter As Integer
        Dim number As Integer
        Dim wrap As String
        wrap = Chr(13) & Chr(10)
        number = numberBox.Text

        For intCounter = 1 To 10

            TextBox2.Text = number & wrap
            number += 1

        Next intCounter

    End Sub

    Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click

        Me.Close()

    End Sub
End Class

try putting

number = CInt(numberBox.text)

otherwise, i'm unfamiliar with the Chr function..

thanks but that's didn't work, that Chr line I got from my VB book to do a carriage return. The carriage return works, but there's something wrong with the loop. Any help would be appreciated.

Ok. Here's rewritten procedure:

Dim intCounter As Integer
Dim number As Integer
Dim wrap As String

wrap = Chr(13) & Chr(10)
' Make sure you get integer, not string as Lee suggested
number = CInt(numberBox.Text)
' TextBox2 is a multiline textbox. Clear it first
TextBox2.Text = ""
For intCounter = 1 To 10
  ' Increment goes first
  number += 1
  ' Use AppendText to get all the sequence (6, 7, ...) visible
  ' and number.ToString to make sure integer goes as string
  TextBox2.AppendText(number.ToString & wrap)
Next intCounter

I wasn't able to get "number+10" eg. "15" from the previous post. Are you sure you copy/pasted code as it was? The only way to get it should be to have increment as number +=10

now I get an error msg pertaining to the
'TextBox2.AppendText(number.ToString & wrap)' line that states 'Argument not specified for parameter 'text' of 'Public Sub AppendText(text As String)'. And if I just use TextBox2.Text(number.ToString & wrap) it still just prints one number.

alright, check this out

i replicated your code and still don't understand what wrap is doing. But this gives the appropriate output bud..

Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
        Dim intCounter As Integer
        Dim number As Integer

        number = CInt(numberBox.Text)

        For intCounter = 1 To 10

            number += 1
            Label1.Text &= number & ControlChars.NewLine

        Next intCounter

    End Sub

hope this helps you enough that you can change it to meet your requirements

Lee

commented: a great help +2

wow, thanks Lee, it worked, you're great, I must have the worst VB professor, I didn't know about controlChars. At least I was close. Thanks again.

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.