Question Choosing the amount of times a loop, or sub should occur

Haxaro

Well-known member
Joined
Mar 13, 2009
Messages
105
Programming Experience
1-3
I have made an app that the user has to type a number, and i want the process for the app to do this how evermany times the user wishes it to do.

for example, the app is ment to create a line in a text document, so they write in textbox1 what they want written on the line, and then in textbox2, tey say how many lines they want to create.

So,

TextBox1.Text = "BLAA"
TextBox2.Text = "782"

It will create 782 lines of BLAA. not just one...

Thanks in advance.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,324
Location
Norway
Programming Experience
10+
Use a NumericUpDown control for numeric user input. The Value property is a Decimal you can simply convert to an Integer using the CInt conversion function.
For writing a number of lines to a text document use the StreamWriter.
Write the lines with a For loop.
 

newguy

Well-known member
Joined
Jun 30, 2008
Messages
611
Location
Denver Co, USA
Programming Experience
1-3
Try doing the loop like this:

Code:
Dim str As String 
For howManyTimes = 1 to Cint(textbox2.Text)
   str &= textbox1.Text
Next
Then add the str to the text file after the loop is done.
Consider using the KeyPress event to capture only numbers in your textbox.
 
Top Bottom