simple class assignment
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
bpacheco1227
Junior Poster in Training
58 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
You should increase number-variable in For Next loop like this:
For intCounter = 1 To 10
TextBox2.Text = number & wrap
number += 1
Next intCounter
Teme64
Veteran Poster
1,031 posts since Aug 2008
Reputation Points: 218
Solved Threads: 203
number variable not increase.
Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
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
bpacheco1227
Junior Poster in Training
58 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
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.
bpacheco1227
Junior Poster in Training
58 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
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
Teme64
Veteran Poster
1,031 posts since Aug 2008
Reputation Points: 218
Solved Threads: 203
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.
bpacheco1227
Junior Poster in Training
58 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
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.
bpacheco1227
Junior Poster in Training
58 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0