[Function] ShowVarsToConsole()

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

[Function] ShowVarsToConsole()

22 Oct 2017, 21:40

Not too useful but it is handy to know what lies in an array or object, so why not show it?
ShowVarsToConsole
The auto execute section is something I set up for all my scripts... ignore some of the options.

Code: Select all

/*
	=========================================================================
	Title:							ListVars To Console
	=========================================================================
	Descrition:						Create a console to show your own
									variables. To show an array or object
									simply put Showvars(ArrayOrObj*)
									The asterisk will show all the variables
									in the array/object.
	-------------------------------------------------------------------------
	AutoHotkey Version:				1.1.26.01
	Language:						English
	Used Platform(s):				Win 10
	Author:							Delta
	Contact information:			[email protected]

	|=======================================================================|
	|	Hotkeys:															|
	|		None															|
	|=======================================================================|
	=========================================================================
*/

#NoEnv
#SingleInstance Force
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#ErrorStdOut
Process, Priority,, H
SetBatchLines, -1
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetWinDelay, -1
SetControlDelay, -1
SetDefaultMouseSpeed, 0
SendMode, Input
CoordMode, Mouse, Screen
SetWorkingDir, %A_ScriptDir%

Colors := ["Red", "Yellow", "Blue"]
Vars := {User: A_UserName, ScriptDir: A_ScriptDir, ScriptName: A_ScriptName}

; Do remember that each Console window must be closed before moving on in the scipt
ShowVarsToConsole(Colors*)
ShowVarsToConsole(Vars*)
ExitApp

; I couldn't have done this without the FileObj doc's second example!!
; https://autohotkey.com/docs/commands/FileOpen.htm#Examples
ShowVarsToConsole(Vars*) {
	DllCall("AllocConsole")
	stdin	:= FileOpen("*", "r `n")
	stdout	:= FileOpen("*", "w `n")

	; For older versions:
	;	stdin	:= FileOpen(DllCall("GetStdHandle", "int", -10, "ptr"), "h `n")
	;	stdout	:= FileOpen(DllCall("GetStdHandle", "int", -11, "ptr"), "h `n")

	stdout.Write("=============================`n")
	For Index, Out in Vars {
		stdout.Write(A_Space Index " : " Out "`n")
		stdout.Read(0)
	}
	stdout.Write("=============================`n")
	stdout.Write("Press Enter To Close...`n")
	stdout.Read(0)
	query := RTrim(stdin.ReadLine(), "`n")
	stdout.Read(0)
	stdin.Close()
	stdout.Close()
}
Hope this helps those who want to debug their script's variables!

It works with variables the same way:

Code: Select all

#Include Console_Func.ahk ; This is if you have the function inside a file all by itself

ShowVarsToConsole(A_ScriptName, A_ScriptDir, A_UserName, A_GuiControl, A_Index) ; Works with any variable that has a value, it displays in appearence according to the parameters in the function.

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 139 guests