Newbie with syntax problem

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Auntiejack56
Posts: 5
Joined: 28 Mar 2024, 00:24

Newbie with syntax problem

28 Mar 2024, 01:01

Hi, sorry for being such a newbie but scouring help, adjusting, displaying, rinsing and repeating is getting me nowhere on some of the absolute basics. I have finally worked out the syntax for where you put the curly brackets for block code, but displaying a variable still escapes me.

Code: Select all

^6::  ; Ctrl+Alt+N
{
    if WinExist("*fgsfhgsfhg - Notepad"){
        MyVar := "3"
        if (MyVar = "2")
            MsgBox "Hello World!" . MyVar
        else
            MsgBox "Hello World! <> 2" . MyVar
    }
        else
        Run "Notepad"
}
My code shows up the correct notepad window, and then the messagebox shows "Hello World! <> 2. MyVar". That is, the name of the variable, not the value.
If I change the statement "Myvar := 3" to "MyVar := 2", then the true part of the if statement executes, as expected. So the part I'm not understanding is how to display it.
What is wrong with my use of the variable?
Thanks heaps,
Jack
gregster
Posts: 9035
Joined: 30 Sep 2013, 06:48

Re: Newbie with syntax problem

28 Mar 2024, 01:11

the messagebox shows "Hello World! <> 2. MyVar"
Looks like you are running AHK v2 code with AHK v1 (the Launcher might have identified the used syntax incorrectly, or v2 is not installed (correctly)).
If you have v2 actually installed as well, add #Requires AutoHotkey v2.0 at the top of your script.
Auntiejack56
Posts: 5
Joined: 28 Mar 2024, 00:24

Re: Newbie with syntax problem

28 Mar 2024, 01:26

Thanks, I'll try that! I found out about Autohotkey after installing a fix for the mouse - my disabled partner was unable to stop from pressing the right mouse key, and someone had an Autohotkey v1 fix for it. Now, I'd like to do some programming in v2, and remove v1, but can't work out how to do so. Autohotkey v2 shows up in my apps, but not v1. Anyhow, one fix at a time i guess, thanks again!
gregster
Posts: 9035
Joined: 30 Sep 2013, 06:48

Re: Newbie with syntax problem

28 Mar 2024, 01:38

If correctly installed, it should be no problem to have v1 and v2 installed side by side so that you can use both kinds of scripts (no need to remove v1). That's what the Launcher is meant for... and the #Requires directive (also available in recent v1 versions).
Auntiejack56
Posts: 5
Joined: 28 Mar 2024, 00:24

Re: Newbie with syntax problem

28 Mar 2024, 02:29

Sorry to say, the inserted line didn't work. So I uninstalled V2 and Windows offered me the option of removing both v1 and v2.
Which I did, reinstalled v2, and now the message says:
>"C:\Program Files\AutoHotkey\AutoHotkey.exe" /ErrorStdOut "C:\Users\rayco\OneDrive\Documents\AutoHotkey\Test1.ahk"
'C:\Program' is not recognized as an internal or external command,
operable program or batch file."
I can see the problem (I think): v2 is installed at "C:\Program Files\AutoHotkey\V2\AutoHotkey.exe"
Is that fixable do you think?
Jack
Auntiejack56
Posts: 5
Joined: 28 Mar 2024, 00:24

Re: Newbie with syntax problem

28 Mar 2024, 03:22

Aha, restarted and now works ok, thanks!!

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: No registered users and 164 guests