Calculator Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Calculator

28 Jul 2017, 12:21

Can someone help me make my calculator work?

I am stuck at this problem:

x/z = 320
y/z = 426.6666666666667

The numbers I wrote I got by calculating other stuff but my problem is that x and y can only be hundreds and there is a limit: 3000.
In other words, I need to limit the choices for x and y to 30 numbers (100, 200, 300, ..., 3000).
Z must have a rule as well but no limit. How to make a rule to choose only from numbers with 1 number after comma? eg. 0.9, 1, 1.1, 1.2, 1.3, etc.?

The point of my calculator is to check if there are possible combinations of numbers with given rules and limitations.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Calculator

28 Jul 2017, 13:58

Check out SetFormat or Format() .
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Re: Calculator

29 Jul 2017, 01:37

I don't understand how ;-;
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Calculator

29 Jul 2017, 03:21

Can you give some examples for x,y,z?
Btw 'with 1 number after comma (dot)', I believe you mean numbers with 1 decimal place.

This code might do something similar to what you want:

Code: Select all

q::
vLimX := vLimY := 3000
Loop
{
	vZ := 0.8+A_Index*0.1
	Loop
	{
		vY := A_Index*100
		if (vY > vLimY)
			break
		Loop
		{
			vX := A_Index*100
			if (vX > vLimX)
				break
			vOutput1 := vX "/" vZ "=" (vX/vZ)
			vOutput2 := vY "/" vZ "=" (vY/vZ)
			if (vX/vZ > 300) && (vX/vZ < 350)
			&& (vY/vZ > 400) && (vY/vZ < 450)
				MsgBox, % vOutput1 "`r`n" vOutput2
		}
	}
}
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Re: Calculator

29 Jul 2017, 03:55

Ok, this is the whole process with working numbers:

List of numbers that ahk can choose from when checking x and y.
100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500,1600,1700,1800,1900,2000,2100,2200,2300,2400,2500,2600,2700,2800,2900,3000

List of numbers that ahk can choose from when calculating z.
0.1,0.2,0.3,... (Numbers with 1 decimal place, range from 0 to 5)

Solved example:

Code: Select all

Let's say we input values:
600
800

600 := x*z
800 := y*z

Ahk calculates possible combinations and posts results:
x=600
y=800
z=1.0

x=300
y=400
z=2.0

x=1200
y=1600
z=0.5

etc
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Calculator

29 Jul 2017, 08:03

Well, I've got some nice code for this. A school/university assignment? A real-world problem? Cheers.

Code: Select all

q::
vLimX := vLimY := 3000
vLimZ := 5
Loop
{
	vZ := Format("{:0.2f}", A_Index*0.01)
	if (vZ > vLimZ)
		break
	Loop
	{
		vY := A_Index*100
		if (vY > vLimY)
			break
		Loop
		{
			vX := A_Index*100
			if (vX > vLimX)
				break
			vOutput1 := vX "/" vZ "=" (vX/vZ)
			vOutput2 := vY "/" vZ "=" (vY/vZ)
			if (vX/vZ = 320)
			&& (vY/vZ > 420) && (vY/vZ < 430)
				MsgBox, % vX " " vY " " vZ "`r`n" vOutput1 "`r`n" vOutput2
		}
	}
}
MsgBox, % "done"
return

;==================================================

w::
vLimX := vLimY := 3000
vLimZ := 5
vOutput := ""
Loop
{
	vZ := Format("{:0.2f}", A_Index*0.01)
	if (vZ > vLimZ)
		break
	Loop
	{
		vY := A_Index*100
		if (vY > vLimY)
			break
		Loop
		{
			vX := A_Index*100
			if (vX > vLimX)
				break
			if (vX*vZ = 600)
			&& (vY*vZ = 800)
				vOutput .= vX " " vY " " vZ "`r`n"
		}
	}
}
Clipboard := vOutput
MsgBox, % vOutput
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Re: Calculator

29 Jul 2017, 10:11

jeeswg wrote:Well, I've got some nice code for this. A school/university assignment? A real-world problem? Cheers.
Spoiler
Oh man, it works perfectly! I already grasp a little how it works and I can find values if I type it manually. Thank you!

BUT

For calculator to work I must be able to place different variables each time I run the script.
I tried moving them to replace numbers like this:
if (vX*vZ = %var1%)
&& (vY*vZ > %var2%-1) && (vY*vZ < %var2%+1)

I get error code " 600.00000 is not a valid number" and ahk closes. Why does it crash and is this expression (%var2%+1) correct?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Calculator  Topic is solved

29 Jul 2017, 10:31

Just remove the % signs, that should work:

Code: Select all

if (vX*vZ = var1)
&& (vY*vZ > var2-1) && (vY*vZ < var2+1)
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Re: Calculator

29 Jul 2017, 14:25

jeeswg wrote:Just remove the % signs, that should work:

Code: Select all

if (vX*vZ = var1)
&& (vY*vZ > var2-1) && (vY*vZ < var2+1)

You're a genius! Thank you! :dance:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], mikeyww and 237 guests