Quick help in VB Express 2005

BALIstik916

Senior member
Jan 28, 2007
755
0
71
hey guys i would appreciate the help i gotta turn this assignment in before midnight...

basically the program is two textboxes and a calculate button...the user enters 2 numbers into each textbox and if you hit the calculate button, the result is the sum of the squares in the range of the two numbers.

for example if you enter 2 and 5, the answer is
2^2 + 3^2 + 4^2 + 5^2...

it needs to check for which number is smaller and then do the calculation

Thanks all...
 

Noobsa44

Member
Jun 7, 2005
65
0
0
Without writing the program for you, here's the basics (I'm writing this off the top of my head, so the syntax maybe wrong):
Dim i1 as integer = Convert.ToInt32(Me.TxtBox1.Text)
Dim i2 as integer = Convert.ToInt32(Me.TxtBox2.Text)
Dim FirstNumber as integer
Dim SecondNumber as integer

if(i1>i2) then
FirstNumber = i2
SecondNumber = i1
else
FirstNumber = i1
SecondNumber = i2
end if
Dim total as integer
for i as integer = FirstNumber to SecondNumber
'Insert logic here.
next
 

BALIstik916

Senior member
Jan 28, 2007
755
0
71
No that doesn't seem to work because the FirstNumber = i2 is doing something because every output is equal to zero...
 

JACKDRUID

Senior member
Nov 28, 2007
729
0
0
Originally posted by: BALIstik916
No that doesn't seem to work because the FirstNumber = i2 is doing something because every output is equal to zero...

... error in logic? his code seem correct..

the logic part should be something like this..

sum += i*i


llol... wow... I guess the logic isn't too bad lol..
 

Aikouka

Lifer
Nov 27, 2001
30,383
912
126
Originally posted by: JACKDRUID
... error in logic? his code seem correct..

the logic part should be something like this..

sum += i*i


llol... wow... I guess the logic isn't too bad lol..

Actually the logic is more like sum += i ^ 2

:p

BAL, it doesn't help much if we tell you how to do it. The best thing would be for you to attempt it yourself first and post the code here. Try breaking this down into separate problems that form the big issue. For example, you first need to find the large number* and then you need to use the numbers to figure out the sum. Now, sometimes people have a hard time translating these problems into code, but my best advice for this is think basic (not the language). If you were to do this problem in your head, you would probably do each square operation at a time write down the number... then you'd do that again and add it to the sum before. Notice how we're talking about a lot of repetition?
 

JACKDRUID

Senior member
Nov 28, 2007
729
0
0
lol same thing but thats a better way to represent it lol :D

i was just jotting down the logic lol...nice one Aikouka