| | |
Help with For loop syntax
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2008
Posts: 23
Reputation:
Solved Threads: 0
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?
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?
Below is the code for what you are trying to do:
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.
vb Syntax (Toggle Plain Text)
Dim numNumbers As Integer Dim total As Double numNumbers = InputBox("Please enter the number of numbers you would like to add", "Number of Numbers") Dim counter As Integer For counter = 1 To numNumbers total = total + InputBox("Please enter number " & counter, "Number " & counter) Next 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.
![]() |
Similar Threads
- factorial using a for loop (C++)
- For loop syntax in csh, ksh, bash (Shell Scripting)
- Simple while loop in c++ (C++)
- Loop Issues (C)
- how to use loop in this question (C++)
- need help w/for loop (C++)
- Switch Loop (Legacy and Other Languages)
Other Threads in the VB.NET Forum
- Previous Thread: Waiting for a period of time and then killing a file
- Next Thread: Identify a specific instance of MS Word
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2008 access add advanced application array assignment basic binary box button buttons center click code combo connectionstring convert cpu data database databasesearch datagrid datagridview design designer dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists firewall folder image images isnumericfuntioncall listview login map math memory mobile module msaccess mssqlbackend mysql navigate net number opacity pan peertopeervideostreaming picturebox picturebox2 port print printpreview record regex reports" reuse right-to-left save savedialog search serial socket sorting sqldatbase sqlserver storedprocedure string temp textbox timer txttoxmlconverter upload useraccounts usercontol usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vbnet vista visual visualbasic visualbasic.net visualstudio.net web wpf xml





