Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

How to add/subtract an amount to a variable? [solved]


  • Please log in to reply
4 replies to this topic
Casper
  • Members
  • 57 posts
  • Last active: Oct 30 2015 10:17 AM
  • Joined: 01 Jun 2006
How do I add/subtract a amount to a variable?

F.x if I have Var1 and I want to either subtract with it Var2 or simply a fixed amount like 20, how would i write this?

Sorry if it's a very newb question, but I can't seem to find the answer in other posts or the help finder

edit: spelling fix
Casper

VarUser
  • Guests
  • Last active:
  • Joined: --
Var1 -= 20

Var1 -= Var2



Var1 := Var1 - 20

Var1 := Var1 - Var2


stanman
  • Members
  • 177 posts
  • Last active: Oct 10 2015 12:52 AM
  • Joined: 29 Apr 2004
The answer is in here: <!-- m -->http://www.autohotke...s.htm#Operators<!-- m -->

Var1 += 20 ; adds 20 to Var1
Var1 -= 20 ; subtracts 20 from Var1

You can do the same with another variable:
Var1 -= Var2 ; subtracts Var2 from Var1

But that can be a little confusing, so I would do something like this:
Var3 := (Var1 - Var2)

It's just a matter of preference.

Casper
  • Members
  • 57 posts
  • Last active: Oct 30 2015 10:17 AM
  • Joined: 01 Jun 2006
Thank you very much!

I'll go try it out after the break : )
Casper

Abrin
  • Members
  • 50 posts
  • Last active: Aug 16 2016 03:24 AM
  • Joined: 19 Jan 2014

Thanks so much stanman! When you are a non-programmer -- it is like the documentation is written in a foreign language sometimes. I get so confused! I've been trying to figure out what I've been doing wrong in my code all morning and thanks to you I finally get it! :D