Expression question?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
eblanc
Posts: 71
Joined: 08 May 2019, 14:41

Expression question?

13 May 2019, 12:31

Hi, I'm newish to AHK. I have a question about "expressions" I still don't understand them properly, I kind of have stumbled into them and am starting to use them, but not really understand them as much as I would like to. I've read the manual and help on the AHK wiki, but still not comprehending the concept. I'm trying to fix the following code, but also have a few small questions.

So expressions is using this symbol ":=" what does that create exactly?

like a temporal clipboard named to whatever I want?
or is there rules for what can be named, the information it can be stored?,
and the amount of expressions I can create?




I have this code that is copying files and creating a directory.

I have used No := as my expression, but realized for what I want I need to use TWO expression in the same command line. So I've created a "Ni :=" expression hoping that it would work.

.
.

Probably very obviously to most other people in the forum. It. does. not.

What could I use to fix. this code and be able to use to expressions (that are trimming the clipboard) in the same line, or what am I doing wrong.

Thank you for reading. And taking the time to helping someone else understand.

Code: Select all

^+T::
No := SubStr(ClipBoard, 1, 4)
filecreatedir, c:\temp\%no%\%clipboard%
sleep, 600
filecopy, C:\Users\Enrique\Desktop\Templates\New Project Template Master.xlsx, c:\temp\%no%\%clipboard%\%clipboard%.xlsx
sleep, 600
Ni := SubStr(ClipBoard, 8, 5)
filecopy, C:\Users\Enrique\Desktop\Templates\dal_xxxxx_1.stream, c:\temp\%no%\%clipboard%\dal_%Ni%_1.stream
run, c:\temp\%clipboard%
return 
;Example of a clipboard I would use: WA01 - 51234 - Smith Realtors - 123 John - 123 John St
User avatar
eblanc
Posts: 71
Joined: 08 May 2019, 14:41

Re: Expression question?

13 May 2019, 16:50

Turns out I wasn't closing the directory. \%clipboard%\

So that's fixed. However, I would still like to know what people answer to the questions I've asked.
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Expression question?

14 May 2019, 22:09

:= assigns a value to a variable, the same as var=value, except that value is an expression, not unquoted text.

I think your "temporal clipboard" is just a variable (one which happens to contain a part of the text retrieved from the clipboard).
User avatar
Cuadrix
Posts: 236
Joined: 07 May 2017, 08:26

Re: Expression question?

14 May 2019, 23:23

With = you can assign a value to your variable, like this:

Code: Select all

var = hello
..or you can pass one variables value to another like this:

Code: Select all

var1 = hello
var2 = %var1% ; var2 now contains hello
With := you can do the same as above, but with quotes:

Code: Select all

var := "hello"
..and you can also pass on the contents of other variables like this:

Code: Select all

var1 := "hello"
var2 := var1 ;without percent %% signs, var 2 now contains hello
The difference between := and = is that := accepts expressions.
An expression is simply put an operation that returns a value.

A very simple example of an expression is a math operation.

Let's say that we have a simple math question like 1 + 2 = 3.
In this "question" 1 + 2 is an expression, and 3 is the return value.
So how do we get the return value to this expression using autohotkey?
We use the := operator to assign a variable the expression 1 + 2, and read the return value assigned to the variable by the expression, like this:

Code: Select all

var := 1 + 2
msgBox %var% ; this will show 3

;or

var1 := 1 + 2
var2 := var1 ; var2 now contains 3
msgBox %var2%

; note that we don't use quotes around expressions. Use quotes only when assigning strings/text.
These expressions/math operations are not possible to do with =
The only place you really should use = variables are with Autohotkeys command syntax.

:terms:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: fiendhunter and 233 guests