Help with For loop syntax

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 23
Reputation: 3Dees is an unknown quantity at this point 
Solved Threads: 0
3Dees 3Dees is offline Offline
Newbie Poster

Help with For loop syntax

 
0
  #1
Sep 29th, 2008
Hi,
I am trying to write the syntax using a FOR loop to sum numbers base on user input from a console apps. The user enters the total amount numbers to add 2 for eg then the actual numbers to add 4 and then 4 for eg.

so the using will enter the amount of numbers to add wNumber
then the first number to add yNumber
then the next mumber zNumber

ynumber+xNumber

display the result=

any suggestions on how i can approach this please?
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 23
Reputation: 3Dees is an unknown quantity at this point 
Solved Threads: 0
3Dees 3Dees is offline Offline
Newbie Poster

Re: Help with For loop syntax

 
0
  #2
Sep 29th, 2008
I am using VB.NET
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 306
Reputation: timothybard is an unknown quantity at this point 
Solved Threads: 26
timothybard's Avatar
timothybard timothybard is offline Offline
Posting Whiz

Re: Help with For loop syntax

 
0
  #3
Sep 29th, 2008
Below is the code for what you are trying to do:

  1. Dim numNumbers As Integer
  2. Dim total As Double
  3. numNumbers = InputBox("Please enter the number of numbers you would like to add", "Number of Numbers")
  4.  
  5. Dim counter As Integer
  6. For counter = 1 To numNumbers
  7. total = total + InputBox("Please enter number " & counter, "Number " & counter)
  8. Next
  9.  
  10. MsgBox("The total is " & total, MsgBoxStyle.OkOnly, "Total")

This code uses InputBoxes for input and MsgBoxes for output. Also, this code has no error handling; therefore, if someone types something other than a number, then there is an error. The key to this is to not have the program store each number individually but only the total; once the number is added to the total, there is no need to remember the number.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 23
Reputation: 3Dees is an unknown quantity at this point 
Solved Threads: 0
3Dees 3Dees is offline Offline
Newbie Poster

Re: Help with For loop syntax

 
0
  #4
Sep 29th, 2008
Thanks Timo,
I will try and transfer this code to work in a console application.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC