please give me a solusion ( For...Next)
dim a,b,c,d as long
for a = 0 to 180000
for b = 0 to 20000
for c = 0 to 1000
for d = 0 to 100
if (a*400+b*600+c*100+d*2100=1519825400) and (a+b+c+d=165427) then
debug.print a,b,c,d
end if
next
next
next
next
Do you have other way?
[360 byte] By [
hieuaids] at [2007-11-11 8:37:23]

# 1 Re: please give me a solusion ( For...Next)
The problem you are having is with the maths - the max value that 'a*400+b*600+c*100+d*2100' can have is 84,310,000 - which is considerably less than 1519825400 ! - therefore you will never get a match.
From a programming perspective, there are a few minor mods that you can make ...
Change 'dim a,b,c,d as long' to 'Dim a as long, b as long, c as long, d as long' as the way you have it has a,b & c as variants, and d as long.
since you are looking for '(a+b+c+d)=165427' then there is no point in 'for a = 0 to 180000' - make it '0 to 165427' (thus reducing iterations by approx 6%)
Since in '(a*400+b*600+c*100+d*2100=1519825400)' both sides of equation are divisible by 100, then change to '(a*4+b*6+c*1+d*21=15198254)', although this is only for neatness ;-)
But above all else - change the 1519825400
gupex at 2007-11-11 17:25:18 >

# 2 Re: please give me a solusion ( For...Next)
thank you GUPS
I can replace it by 151940400. but i want to know this prolem the Computer can solve it? Because it is a big number. i've try it and i have a wrong (over memory)
do you have a full code to solve it?
# 3 Re: please give me a solusion ( For...Next)
Not surprising really - the total number of iterations through your loop is potentially 360,000,000,000,000 (180000*20000*1000*100). I do not know if this is possible, but even if it is, I sure wouldn't want to wait around for it to finish! (Now, if my maths are correct, assuming 1,000,000 iterations of your loop per second, it would take of the order of 4000 days.)
gupex at 2007-11-11 17:27:16 >

# 4 Re: please give me a solusion ( For...Next)
thank you Gupex
I understood from your write. So to solve this math, do you have a best and fast way?
I've learning VB myself by books (not school).
I hope to you.
# 5 Re: please give me a solusion ( For...Next)
Perhaps it's time to tell us exactly what is the problem you are trying to solve?
gupex at 2007-11-11 17:29:17 >

# 6 Re: please give me a solusion ( For...Next)
Another potential bug place...
dim a,b,c,d as long
This declares d as long, but a, b and c are variants.
If you want them to all be longs, then you need to declare them like this:
dim a as long,b as long,c as long,d as long
# 7 Re: please give me a solusion ( For...Next)
I hope to you, too, Greg! :p
Laurel at 2007-11-11 17:31:19 >

# 8 Re: please give me a solusion ( For...Next)
Laurel - Thanks, I appreciate it !
Edburdo - 'dim' covered in my first post ;-)
gupex at 2007-11-11 17:32:22 >

# 9 Re: please give me a solusion ( For...Next)
Perhaps it's time to tell us exactly what is the problem you are trying to solve?
a+b+c+d=169742
a*800+b*1200+c*1800+d*3400=151891800
?a?b?c?d
how do I solve it? exacly and fast.