hi
can anyone plz give me the explanation of the below given program. it is written in vb 2010 using for next loop to create a pattern like
1
12
123
1234 and so on
Dim I As Integer
Dim a As String
ListBox1.Items.Clear()
a = ""
For I = 1 To Val(TextBox1.Text)
a = a & I
ListBox1.Items.Add(a)
Next I
thanks & regards
for next loop in vb 2010
Page 1 of 17 Replies - 1734 Views - Last Post: 10 October 2011 - 10:05 AM
Replies To: for next loop in vb 2010
#2
Re: for next loop in vb 2010
Posted 10 October 2011 - 09:27 AM
It's pretty straight forward... loop through numbers one to the input value in textbox1. Each number in that range is appended to a string adn added to a list box.
#3
Re: for next loop in vb 2010
Posted 10 October 2011 - 09:30 AM
1. & operator used to 'join'/concatenate the existing string 'a' and the counter variable that increments each time the loop goes around - generates the 123..
2. Add the new value of 'a' to the listbox which is shown on the GUI
3. Repeat until loop reaches number given in textbox.
Also please use [code] tags in future.
2. Add the new value of 'a' to the listbox which is shown on the GUI
3. Repeat until loop reaches number given in textbox.
Also please use [code] tags in future.
This post has been edited by Ryano121: 10 October 2011 - 09:32 AM
#4
Re: for next loop in vb 2010
Posted 10 October 2011 - 09:39 AM
DVEENA77, on 10 October 2011 - 09:18 AM, said:
hi
can anyone plz give me the explanation of the below given program. it is written in vb 2010 using for next loop to create a pattern like
1
12
123
1234 and so on
Dim I As Integer
Dim a As String
ListBox1.Items.Clear()
a = ""
For I = 1 To Val(TextBox1.Text)
a = a & I
ListBox1.Items.Add(a)
Next I
thanks & regards
can anyone plz give me the explanation of the below given program. it is written in vb 2010 using for next loop to create a pattern like
1
12
123
1234 and so on
Dim I As Integer
Dim a As String
ListBox1.Items.Clear()
a = ""
For I = 1 To Val(TextBox1.Text)
a = a & I
ListBox1.Items.Add(a)
Next I
thanks & regards
what is the purpose of a ="" string in this pgm. can any else be assigned to this instead of a = "".
#5
Re: for next loop in vb 2010
Posted 10 October 2011 - 09:41 AM
Well this just means that the string is empty before you start adding the numbers. If you put a = "foo", you would end up getting -
foo1
foo12
foo123
etc
foo1
foo12
foo123
etc
#6
Re: for next loop in vb 2010
Posted 10 October 2011 - 09:44 AM
It was initialized there, and because we need it to be empty, that is why it was given empty string. The initialization was done because the variable need to be used in the loop. and before using any value of a variable, variable must be initialized(given a value to hold)
#7
Re: for next loop in vb 2010
Posted 10 October 2011 - 10:01 AM
DVEENA77, on 10 October 2011 - 09:39 AM, said:
DVEENA77, on 10 October 2011 - 09:18 AM, said:
hi
can anyone plz give me the explanation of the below given program. it is written in vb 2010 using for next loop to create a pattern like
1
12
123
1234 and so on
Dim I As Integer
Dim a As String
ListBox1.Items.Clear()
a = ""
For I = 1 To Val(TextBox1.Text)
a = a & I
ListBox1.Items.Add(a)
Next I
thanks & regards
can anyone plz give me the explanation of the below given program. it is written in vb 2010 using for next loop to create a pattern like
1
12
123
1234 and so on
Dim I As Integer
Dim a As String
ListBox1.Items.Clear()
a = ""
For I = 1 To Val(TextBox1.Text)
a = a & I
ListBox1.Items.Add(a)
Next I
thanks & regards
what is the purpose of a ="" string in this pgm. can any else be assigned to this instead of a = "".
Can we do this program without using strings? if so how?
#8
Re: for next loop in vb 2010
Posted 10 October 2011 - 10:05 AM
Well you would need to store your previous information elsewhere.. so in theory you could remove the string and use another for loop.. but that would get slow and tedious..
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote






|