list_vars()

Post your working scripts, libraries and tools
User avatar
davebrny
Posts: 83
Joined: 05 Dec 2016, 06:26

list_vars()

11 Mar 2017, 12:34

i made this to cut down on the amount of time it takes to get some variables printed to the screen.
in situations where you have more than 4 or 5 variables you want to check, it can be fairly time consuming having to arrange each of them in a msgBox on their own line, putting the name of the variable next to it so you know which one is which, and in some cases wrapping them in quotes so you can check for trailing characters etc etc ...aint nobody got time fo dat

this is much quicker:

Code: Select all

splitPath, a_ahkPath, file_name, file_dir, file_ext, name_no_ext, drive
list_vars(a_lineFile, a_lineNumber, a_thisLabel)

Code: Select all

winGetPos, x, y, width, height, a
list_vars(a_lineFile, a_lineNumber, a_thisLabel)
it can also be useful in a loop

Code: Select all

list = one,two , three,four
counter = 5

loop, parse, % list, `,
    {
    lstvrs = a_index a_loopField
    counter++
    list_vars(a_lineFile, "q" a_lineNumber, a_thisLabel)
    }
if you want to view some variables that arent present in the current script or label then you can add them to a variable to have them show up

Code: Select all

show_vars = a_ahkVersion a_OSVersion a_is64bitOS a_computerName a_userName a_scriptHwnd
list_vars(a_lineFile, a_lineNumber, a_thisLabel)
in that example the variable "show_vars" will also show up in the list. if the variable name "lstvrs" is used instead then the contents of the variable will be shown but the variable itself will be ignored

Code: Select all

lstvrs =
(
a_detectHiddenWindows a_detectHiddenText a_titleMatchMode
a_titleMatchModeSpeed a_batchLines a_sendMode a_coordMode
a_stringCaseSense a_winDelay
)

list_vars(a_lineFile, a_lineNumber, a_thisLabel)

scope

the built in "listvars" command will show every variable being used, which depending on how many other scripts and functions are included into the current script, could be a lot

using just the first 2 parameters in this function will show the variables being using in the current file only.
it will also only show the variables that have been used up to the point in time where the function is used... which means that you can use it at multiple places through out a script and track how variables are changing as the script progresses.

Code: Select all

list_vars(a_lineFile, a_lineNumber)
to narrow the list down further you can use the 3rd parameter to limit the scope the the current label/hotkey or function.

Code: Select all

list_vars(a_lineFile, a_lineNumber, a_thisLabel)
list_vars(a_lineFile, a_lineNumber, a_thisFunc)
• a_thisLabel can be used for both hotkeys and labels.
• a_thisFunc is used for functions but the function has to be set to global in most cases



options

lines that are longer than 55 characters are show shortened/truncated
if you want to see the full lines then put "f" into the second parameter along with a_lineNumber

Code: Select all

list_vars(a_lineFile, a_lineNumber "f", a_thisLabel)
add "a" to wrap the line in >arrows<
or "q" to wrap the line in "quotes"
add "c" to add the list to the clipboard. (the full variables are added to the clipboard whether the "f" is used or not)



limitations

i cant remember what they are now :D (i made this a year ago) but there were definitely were a few situations where this didnt work as expected. it works by reading the contents of the current file so maybe it was the variables in an #include file or function that werent showing up. anyway, this is just a disclaimer to say that it probably wont work in every situation


to do

a listView gui that could resize depending on the size would be much better than using a msgBox but i havnt got around to trying that out yet

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Google [Bot], gwarble, oldbrother, thebbandit and 40 guests