7 Replies - 3962 Views - Last Post: 10 October 2011 - 10:05 AM Rate Topic: -----

#1 DVEENA77  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 21-June 11

for next loop in vb 2010

Posted 10 October 2011 - 09:18 AM

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

Is This A Good Question/Topic? 0
  • +

Replies To: for next loop in vb 2010

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9086
  • View blog
  • Posts: 34,134
  • Joined: 12-June 08

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.
Was This Post Helpful? 0
  • +
  • -

#3 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • View blog
  • Posts: 3,002
  • Joined: 30-January 11

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.

This post has been edited by Ryano121: 10 October 2011 - 09:32 AM

Was This Post Helpful? 1
  • +
  • -

#4 DVEENA77  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 21-June 11

Re: for next loop in vb 2010

Posted 10 October 2011 - 09:39 AM

View PostDVEENA77, 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



what is the purpose of a ="" string in this pgm. can any else be assigned to this instead of a = "".
Was This Post Helpful? 0
  • +
  • -

#5 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • View blog
  • Posts: 3,002
  • Joined: 30-January 11

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
Was This Post Helpful? 1
  • +
  • -

#6 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1819
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

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)
Was This Post Helpful? 1
  • +
  • -

#7 DVEENA77  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 21-June 11

Re: for next loop in vb 2010

Posted 10 October 2011 - 10:01 AM

View PostDVEENA77, on 10 October 2011 - 09:39 AM, said:

View PostDVEENA77, 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



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?
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9086
  • View blog
  • Posts: 34,134
  • Joined: 12-June 08

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..
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1