9 Replies - 721 Views - Last Post: 24 February 2012 - 08:46 PM Rate Topic: -----

#1 bro4mayor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 23-February 12

looping an inputbox

Posted 24 February 2012 - 01:45 PM

I'm trying to loop the inputbox 5 times but I'm not sure how.

 Dim payroll1 As String

        payroll1 = InputBox("What is the payrolls for store1", "Inc", , , )
        Lblstore1.Text = payroll1



i can get it to loop till a specific amount but not 5 times exactly.
Is This A Good Question/Topic? 0
  • +

Replies To: looping an inputbox

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1397
  • View blog
  • Posts: 4,494
  • Joined: 25-September 09

Re: looping an inputbox

Posted 24 February 2012 - 01:52 PM

Check out this link for using loops. It should get you what you want.
Was This Post Helpful? 1
  • +
  • -

#3 smohd  Icon User is offline

  • Critical Section
  • member icon



Reputation: 1746
  • View blog
  • Posts: 4,409
  • Joined: 14-March 10

Re: looping an inputbox

Posted 24 February 2012 - 02:03 PM

And we have a tutorial on that in Vb.Net tutorials.
Was This Post Helpful? 1
  • +
  • -

#4 nK0de  Icon User is offline

  • Catch me As Exception
  • member icon

Reputation: 204
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: looping an inputbox

Posted 24 February 2012 - 02:04 PM

View Postbro4mayor, on 25 February 2012 - 02:15 AM, said:

i can get it to loop till a specific amount but not 5 times exactly.


what do you mean by specific amount?? of course you can set it to an exact number of times. Using a For...Next loop will be easy for you on this one.
Was This Post Helpful? 0
  • +
  • -

#5 DimitriV  Icon User is offline

  • Don't try to save yourself… the circle is complete
  • member icon

Reputation: 544
  • View blog
  • Posts: 2,632
  • Joined: 24-July 11

Re: looping an inputbox

Posted 24 February 2012 - 02:13 PM

You'd loop like this: declare an integer named x, instanced to 0, add one to it each time and loop until x = 5.

View PostnK0de, on 25 February 2012 - 07:04 AM, said:

View Postbro4mayor, on 25 February 2012 - 02:15 AM, said:

i can get it to loop till a specific amount but not 5 times exactly.


what do you mean by specific amount?? of course you can set it to an exact number of times. Using a For...Next loop will be easy for you on this one.

Or a Do...Loop Until x = 5 loop.
Was This Post Helpful? 0
  • +
  • -

#6 bro4mayor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 23-February 12

Re: looping an inputbox

Posted 24 February 2012 - 02:50 PM

View PostnK0de, on 24 February 2012 - 02:04 PM, said:

View Postbro4mayor, on 25 February 2012 - 02:15 AM, said:

i can get it to loop till a specific amount but not 5 times exactly.


what do you mean by specific amount?? of course you can set it to an exact number of times. Using a For...Next loop will be easy for you on this one.


I meant I wanted it to loop 5 times because i wanted the user to give me 5 amounts to be adding together.
Was This Post Helpful? 0
  • +
  • -

#7 smohd  Icon User is offline

  • Critical Section
  • member icon



Reputation: 1746
  • View blog
  • Posts: 4,409
  • Joined: 14-March 10

Re: looping an inputbox

Posted 24 February 2012 - 03:15 PM

Did you read the tutorials which we gave to you? Read them and try something, then come back with what you have tried and we will be happy to help if you have any problem with it
Was This Post Helpful? 0
  • +
  • -

#8 bro4mayor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 23-February 12

Re: looping an inputbox

Posted 24 February 2012 - 07:55 PM

View Postsmohd, on 24 February 2012 - 03:15 PM, said:

Did you read the tutorials which we gave to you? Read them and try something, then come back with what you have tried and we will be happy to help if you have any problem with it


I read them and looked at the video for the loops and came up with this.

 For payroll1 = 1 To 5 Step 1

            Console.WriteLine("payroll1 - " & payroll1)


            payroll1 = InputBox("What is the payrolls for store1", "Kenton Inc", , , )
            Lblstore1.Text = payroll1
        Next


It will loop 5 times but i think it has more to do with amount than times. I'm looking to make it loop 5 times exactly regardless of the amount while still keeping all 5 amounts.
Was This Post Helpful? 0
  • +
  • -

#9 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1397
  • View blog
  • Posts: 4,494
  • Joined: 25-September 09

Re: looping an inputbox

Posted 24 February 2012 - 08:06 PM

Well, you're on the right track. By the way, not that it really matters but the Step 1 is not required as it defaults to 1 iteration per loop. Step is better served when you want to move more than the default. Anyway... the problem you're having is that you are over-writing the .Text property each iteration.

To accumulate the total of payroll1 you need to store it back into the variable.

This is accomplished by using Lblstore1.Text = Lblstore1.Text + payroll1. In other words take what is in the Lblstore.Text and add payroll1 to it and then store it back into Lblstore1.Text.

A shorter method is
Lblstore1.Text += payroll1

Here's a good tutorial that might explain better on the topic of strings

Make sure you read the first comment where it talks about string being immutable, it's precisely what you're experiencing.

This post has been edited by CharlieMay: 24 February 2012 - 08:13 PM

Was This Post Helpful? 0
  • +
  • -

#10 bro4mayor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 23-February 12

Re: looping an inputbox

Posted 24 February 2012 - 08:46 PM

View PostCharlieMay, on 24 February 2012 - 08:06 PM, said:

Well, you're on the right track. By the way, not that it really matters but the Step 1 is not required as it defaults to 1 iteration per loop. Step is better served when you want to move more than the default. Anyway... the problem you're having is that you are over-writing the .Text property each iteration.

To accumulate the total of payroll1 you need to store it back into the variable.

This is accomplished by using Lblstore1.Text = Lblstore1.Text + payroll1. In other words take what is in the Lblstore.Text and add payroll1 to it and then store it back into Lblstore1.Text.

A shorter method is
Lblstore1.Text += payroll1

Here's a good tutorial that might explain better on the topic of strings

Make sure you read the first comment where it talks about string being immutable, it's precisely what you're experiencing.


thanks man. I'm trying to change the code now to make it come up 5 times pricely went back and rewatched the for....next statement video
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1