Error: This variable has not been assigned a value: specifically, vscode Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
NotAColdSun
Posts: 57
Joined: 05 Aug 2022, 01:07

Error: This variable has not been assigned a value: specifically, vscode

Post by NotAColdSun » 25 Mar 2023, 16:03

Error: This variable has not been assigned a value.

Specifically: global vscode

If (A_ThisMenuItemPos = 1)
{
▶ Run(vscode ' ' RW1Script), WinWait(winTitle,, 3)
WinActivate()
}
My script worked well, but since yesterday I get this message when trying to run the following script:
running !a to show Menu Command, and clicking on fx. Arrays → should open Arrays.ahk in VScode:

Code: Select all

#Requires AutoHotkey v2.0
SendMode("Input")  ; Recommended for new scripts due to its superior speed and reliability.
#SingleInstance Force
SetWorkingDir(A_ScriptDir)  ; Ensures a consistent starting directory.
#Include "%A_ScriptDir%/lib/Hotstrings.ahk"

global vscode, winTitle, RW1Script, RW2Script, Arrays, 

vscode := EnvGet('LOCALAPPDATA') "\Programs\Microsoft VS Code\Code.exe"
winTitle := 'ahk_exe' vscode
RW1Script := A_ScriptDir "/RW1Script.ahk"
RW2Script := A_ScriptDir "/RW2Script.ahk"
Arrays   := A_ScriptDir '\lib\Arrays.ahk'

#HotIf !WinActive("ahk_class OpusApp")
~!a::
{
	MyMenu := Menu()
	MyMenu.Add("1.RWscript", MenuHandlerA)
	MyMenu.Add("2.RWscript", MenuHandlerA)
	MyMenu.Add("Arrays.ahk", MenuHandlerA)
        MyMenu.Show()
}

MenuHandlerA(A_ThisMenuItem, A_ThisMenuItemPos, MyMenu) 
{
If (A_ThisMenuItemPos = 1) {
	Run(vscode ' ' RW1Script), WinWait(winTitle,, 3)
	WinActivate
} else if (A_ThisMenuItemPos = 2) {
	Run(vscode ' ' RW2Script), WinWait(winTitle,, 3)
	WinActivate
} else if (A_ThisMenuItemPos = 3) {
		If !WinExist(winTitle)
		Run(vscode ' ' Arrays), WinWait(winTitle,, 3)
		WinActivate
} 
}
Why do I suddenly get this error message, which I wasn´t getting before? How to fix it?

it would also be nice to adjust the script so any errors will come up when trying to run the main script (clicking on the above script´s .ahk file) instead of getting an error message first when trying to use the !a hotkey to open a file.
Last edited by NotAColdSun on 25 Mar 2023, 17:54, edited 1 time in total.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Error: This variable has not been assigned a value: specifically, vscode

Post by swagfag » 25 Mar 2023, 16:15

thats why its a good idea to get in the habit of using version control. ud have known precisely and instantly what particular change caused the error
anyway, its pointless to troubleshoot the script ure showing, since the contents of #Include "%A_ScriptDir%/lib/Hotstrings.ahk" are unknown and the script doesnt even compile to begin with(on account of the presence of an extra, orphaned closing-brace).
so who knows, really, what ure actually trying to run on ur computer

NotAColdSun
Posts: 57
Joined: 05 Aug 2022, 01:07

Re: Error: This variable has not been assigned a value: specifically, vscode

Post by NotAColdSun » 25 Mar 2023, 18:06

I've deleted the extra orphan brace.
I'm trying to use a hotkey !a to show a Menu Command, and when clicking on a file name, I'll open the file in VScode.

Do you really think that contents in my #Include file could have anything to do with this error?

Never thought of the version control; I'll try to implement it (the one provided by VS code/GitHub, unless you have a better suggestion), also because I've sometimes experienced sudden errors on a previously working script.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Error: This variable has not been assigned a value: specifically, vscode  Topic is solved

Post by swagfag » 25 Mar 2023, 18:23

i dont think anything. like i said, its pointless for me to try and troubleshoot something i cant see the full extents of

if we run with what uve posted so far anyways, commenting out the include and the superfluous brace, there is nothing wrong with the script....

NotAColdSun
Posts: 57
Joined: 05 Aug 2022, 01:07

Re: Error: This variable has not been assigned a value: specifically, vscode

Post by NotAColdSun » 26 Mar 2023, 03:47

You helped me find part of the problem: I commented out the #Include line, and the script works fine again. As soon as I re-included the Hotstrings.ahk script, I get the same problem as originally described. When I don´t include the Hotstrings.ahk file, but run it separately, the script in question works, too.
So, the problem is in the #Include file, but I should be able to make it work, as I did in v1.
Any ways I can find this error? The Hotstrings.ahk has around 1000 lines, so no point in showing it here. The topmost 5 lines look like this, though:

Code: Select all

#Requires AutoHotkey v2.0
; #Warn Enable warnings to assist with detecting common errors.
SendMode("Input")
SetWorkingDir(A_ScriptDir)
#SingleInstance Force
UPDATE:
I´ve found the error:
In v1, I've been using the hotstring /dd to write a date in YYYY-MM-DD format, and used v1-to-v2 converter to convert the hotstring to v2, with a wrong result. After fixing the issue, it all works fine. No need for additional help at this moment.

Post Reply

Return to “Ask for Help (v2)”