How do I return the sum of all integers from two text boxes. If the end
user inputs 5 in the first textbox and then 10 in the second textbox my
answer needs to be 45.
5+ 6+7+8+9+10=45? I am using VB.NET 2003

Re: return the sums of all integers by Richard

Richard
Thu Jul 13 20:44:52 CDT 2006

Big_Blue wrote:

> How do I return the sum of all integers from two text boxes. If the end
> user inputs 5 in the first textbox and then 10 in the second textbox my
> answer needs to be 45.
> 5+ 6+7+8+9+10=45? I am using VB.NET 2003

Hi,

A function similar to below should work:
===============
Private Function SumIntegers(ByVal intStart As Integer, ByVal intEnd As
Integer) As Integer
Dim k As Integer
SumIntegers = 0
For k = intStart To intEnd
SumIntegers = SumIntegers + k
Next
End Function
==============
The function returns 0 if intStart is larger than intEnd. Pass the Text
properties of the textboxes to the function.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net



Re: return the sums of all integers by Jim

Jim
Thu Jul 13 21:19:23 CDT 2006

Answer = (TB2*(TB2+1) - TB1*(TB1-1))/2
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"Big_Blue" <stmcgrad05@aol.com> wrote in message news:1152839919.018188.279720@p79g2000cwp.googlegroups.com...
How do I return the sum of all integers from two text boxes. If the end
user inputs 5 in the first textbox and then 10 in the second textbox my
answer needs to be 45.
5+ 6+7+8+9+10=45? I am using VB.NET 2003


Re: return the sums of all integers by g-man

g-man
Thu Jul 13 21:33:26 CDT 2006

You will need to add error checking as necesary...

**************************************************************************************************
FirstNumber = inputbox("First Number")
SecondNumber = inputbox("Second Number")

For MyIncrement = FirstNumber to SecondNumber
MyCount = MyCount + MyIncrement
Next

Wscript.Echo "The Sum of all numbers between " & FirstNumber & " and "
& SecondNumber & " is: " & MyCount
**************************************************************************************************

Richard Mueller wrote:
> Big_Blue wrote:
>
> > How do I return the sum of all integers from two text boxes. If the end
> > user inputs 5 in the first textbox and then 10 in the second textbox my
> > answer needs to be 45.
> > 5+ 6+7+8+9+10=45? I am using VB.NET 2003
>
> Hi,
>
> A function similar to below should work:
> ===============
> Private Function SumIntegers(ByVal intStart As Integer, ByVal intEnd As
> Integer) As Integer
> Dim k As Integer
> SumIntegers = 0
> For k = intStart To intEnd
> SumIntegers = SumIntegers + k
> Next
> End Function
> ==============
> The function returns 0 if intStart is larger than intEnd. Pass the Text
> properties of the textboxes to the function.
>
> --
> Richard
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net


Re: return the sums of all integers by Richard

Richard
Thu Jul 13 23:41:05 CDT 2006

Yikes, I forgot all about that. Nice catch. In a function:

Function SumIntegers(ByVal intStart As Integer, ByVal intEnd As Integer) As
Integer
SumIntegers = (intEnd * (intEnd + 1) - intStart * (intStart - 1)) / 2
End Function

The only difference is that this function returns a negative value if
intStart is greater than intEnd, but that seems correct.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
"Jim Cone" <jim.coneXXX@rcn.comXXX> wrote in message
news:eXk60vupGHA.4032@TK2MSFTNGP03.phx.gbl...
> Answer = (TB2*(TB2+1) - TB1*(TB1-1))/2
> --
> Jim Cone
> San Francisco, USA
> http://www.realezsites.com/bus/primitivesoftware
>
>
> "Big_Blue" <stmcgrad05@aol.com> wrote in message
> news:1152839919.018188.279720@p79g2000cwp.googlegroups.com...
> How do I return the sum of all integers from two text boxes. If the end
> user inputs 5 in the first textbox and then 10 in the second textbox my
> answer needs to be 45.
> 5+ 6+7+8+9+10=45? I am using VB.NET 2003
>



Re: return the sums of all integers by Jim

Jim
Fri Jul 14 12:22:39 CDT 2006

Richard,

Re: "Yikes, I forgot all about that. Nice catch."

Well, I had it cached in my code library.<g>

Just saw your web site for the first time,
I like the layout and arrangement very much.
Wish more web sites were that well organized.

Regards,
Jim Cone
http://www.officeletter.com/blink/specialsort.html


"Richard Mueller"
<rlmueller-NOSPAM@ameritech.NOSPAM.net>
wrote in message
Yikes, I forgot all about that. Nice catch. In a function:
Function SumIntegers(ByVal intStart As Integer, ByVal intEnd As Integer) As
Integer
SumIntegers = (intEnd * (intEnd + 1) - intStart * (intStart - 1)) / 2
End Function

The only difference is that this function returns a negative value if
intStart is greater than intEnd, but that seems correct.
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net


"Jim Cone" <jim.coneXXX@rcn.comXXX> wrote in message
news:eXk60vupGHA.4032@TK2MSFTNGP03.phx.gbl...
> Answer = (TB2*(TB2+1) - TB1*(TB1-1))/2
> --
> Jim Cone
> San Francisco, USA
> http://www.realezsites.com/bus/primitivesoftware
>
>
> "Big_Blue" <stmcgrad05@aol.com> wrote in message
> news:1152839919.018188.279720@p79g2000cwp.googlegroups.com...
> How do I return the sum of all integers from two text boxes. If the end
> user inputs 5 in the first textbox and then 10 in the second textbox my
> answer needs to be 45.
> 5+ 6+7+8+9+10=45? I am using VB.NET 2003
>



Re: return the sums of all integers by Dr

Dr
Sat Jul 15 07:10:01 CDT 2006

JRS: In article <1152839919.018188.279720@p79g2000cwp.googlegroups.com>
, dated Thu, 13 Jul 2006 18:18:39 remote, seen in news:microsoft.public.
scripting.vbscript, Big_Blue <stmcgrad05@aol.com> posted :
>How do I return the sum of all integers from two text boxes. If the end
>user inputs 5 in the first textbox and then 10 in the second textbox my
>answer needs to be 45.
> 5+ 6+7+8+9+10=45? I am using VB.NET 2003

Let the integers be A and B. There are (B-A+1) numbers and their
average value is obviously (A+B)/2. Multiply those. 6 * 7.5 = 45.

If the average value is not obvious to you, write the series on one line
and the series reversed under it; Add the rows for each column, and
count the columns.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.