Using the minus sign as a variable [illegal character] Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ahk_lover
Posts: 7
Joined: 07 Jan 2018, 01:16
Contact:

Using the minus sign as a variable [illegal character]

22 Jan 2018, 00:56

To my understanding, the variable names are not allowed to have a minus sign in it if its used as an expression. I have a slight problem, this is the code:

Code: Select all

s::
InputBox, grade, Enter the Grade Earned, 
If (%grade% = A-)
MsgBox, THIS WAS AN A-
else
MsgBox, Not an A-
So if I enter in a grade such as A-, it will throw an error and crash the script. How do I use minus signs so it would say "Not an A"?

In this script, it uses %%s for the variable to see its value. Please correct me if I am wrong.
gregster
Posts: 9029
Joined: 30 Sep 2013, 06:48

Re: Using the minus sign as a variable [illegal character]  Topic is solved

22 Jan 2018, 01:10

In expression mode you don't need %s to use variables, on the other hand A- is a hard-coded literal string in this case, not a variable. Therefore, you have to use quote signs:

Code: Select all

If (grade = "A-")
Compare https://autohotkey.com/docs/commands/IfExpression.htm and Variables.htm#Expressions:
Variable names in an expression are not enclosed in percent signs (except for pseudo-arrays and other double references). Consequently, literal strings must be enclosed in double quotes to distinguish them from variables.
Last edited by gregster on 22 Jan 2018, 01:21, edited 1 time in total.
Rohwedder
Posts: 7647
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Using the minus sign as a variable [illegal character]

22 Jan 2018, 01:21

Hallo,
or traditional:

Code: Select all

If grade = A-

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ccqcl, Descolada, Google [Bot], Rohwedder and 179 guests