Jump to content
Sign in to follow this  
michaelslamet

List all variable names and content in script

Recommended Posts

michaelslamet

So I would like to list all variable names and their contents in script for debugging.

I found this:

'?do=embed' frameborder='0' data-embedContent>>

#include <Array.au3>
#include <File.au3>
Global Const $asAutoItOperators[21] = ['=','+=','-=','*=','/=','&=', _
                                '+','-','*','/','&','^', _
                                '==','<>','>','<','>=','<=', _
                                'and','or','not']

Global Const $asAutoItVarKeywords[5] = ['Local','Global','Dim', _
                                'Const','Enum']

Global Const $asAutoItFuncKeywords[2] = ['Func','EndFunc']

Global $sFile = @ScriptFullPath

$asVarArray = ParseVarsFromScript($sFile)

_ArrayDisplay($asVarArray)

Func ParseVarsFromScript(Const $sFileName,Const $iStartLine = 1,$iEndLine = 0)
    Local $iLineCounter

    Local $sFileContent
    Local $sCurrentLine

    Local $asScriptVars[1]

    Local $hFile = FileOpen($sFileName,0)
    If @error Then
        SetError(1)
        Return
    EndIf

    If Not $iEndLIne Then
        $iEndLIne = _FileCountLines($sFileName)
    EndIf

    Local $sFileEndName = StringRegExp($sFileName,"[^\\/]+$",1)
    If Not @error Then
        $sFileEndName = $sFileEndName[0]
    Else
        $sFileEndName = $sFileName
    EndIf
    ProgressOn("Processing",$sFileEndName)
    $nProgress = 0.0

    For $iLineCounter = $iStartLine To $iEndLine
        $sCurrentLine = FileReadLine($hFile,$iLineCounter)
        $iVarCounter = 0

        While 1
            $iVarCounter += 1
            $iVarStartPos = StringInStr($sCurrentLine,"$",0,$iVarCounter)

            If $iVarStartPos <= 0 Then
                ExitLoop
            EndIf
            If CheckQuoted($sCurrentLine,$iVarStartPos,False) == False Then
                $iVarLen = CheckQUoted($sCurrentLine,$iVarStartPos,True)
                $sVarName = StringMid($sCurrentLine,$iVarStartPos,$iVarLEn)

                ReDim $asScriptVars[$asScriptVars[0]+2]

                $asScriptVars[$asScriptVars[0]+1] = $sVarName
                $asScriptVars[0]+=1
            EndIf
        WEnd
        $nProgress = ($iLineCOunter / $iEndLine) * 100

        $sProgressSubText = "Line " & $iLineCOunter & " off " & $iEndLine & @LF
        $sProgressSubText &= "Variables Found: " & $asScriptVars[0]
        ProgressSet($nProgress,$sProgressSubText)
    Next
    FileClose($hFile)
    ProgressOff()
    Return $asScriptVars
EndFunc

Func CheckQuoted(Const $sCurrentLine,$iVarStartPos,Const $fDirection = False)
    Local $sCurrentChar
    Local $fQuoted = False
    Local $iStep
    Local $iSkippedCharCounter = 0
    Local $sVarEndRegEx

    If $fDirection == False Then
        $iStep = -1
        $iEnd = 1
        $iVarStartPos -= 1
    Else
        $iStep = 1
        $iEnd = StringLen($sCurrentLine)
        $iVarStartPos += 1
    EndIf

    For $iCharCounter = $iVarStartPos To $iEnd Step $iStep
        $sCurrentChar = StringMid($sCurrentLine,$iCharCounter,1)

        If Not StringLen($sCurrentChar) Or (Not $fQuoted And StringRegExp($sCurrentChar,"[()\[\],.\s]")) Then
            ExitLoop
        ElseIf $sCurrentChar == "'" Or $sCurrentChar = '"' Then
            $fQuoted = True
        EndIf

        If $fQuoted Then
            ContinueLoop
        EndIf

        For $iOperatorCounter = 0 To UBound($asAutoItOperators)-1
            $sCurrentOperator = $asAutoItOperators[$iOperatorCounter]
            $iCurrentOperatorLen = StringLen($sCurrentOperator)
            If $fDirection == False Then
                $sTempCompare = StringMid($sCurrentLine,$iCharCounter-$iCurrentOperatorLen+1,$iCurrentOperatorLen)
            Else
                $sTempCompare = StringMid($sCurrentLine,$iCharCounter,$iCurrentOperatorLen)
            EndIf
            If @error Or Not StringLen($sTempCompare) Then
                ContinueLoop
            ElseIf $sTempCompare == $sCurrentOperator Then
                $fQuoted = False
                ExitLoop(2)
            EndIf
        Next
    Next
    If $fDirection Then
        If $fQuoted Then
            Return 0
        Else
            Return $iCharCounter-$iVarStartPos+1
        EndIf
    Else
        Return $fQuoted
    EndIf
EndFunc

 

The problems with the code are:

1. The variables names it get are duplicate, not unique.

2. It only get the variables names, not the content of the variables.

I know I should can get the variable contents using Eval through a loop, but cant make it works :(

Share this post


Link to post
Share on other sites
Bowmore

Have you tried running Tidy.exe with the /gd option. This produces a very detailed report on variables, look towards the bottom of the report, that lists all the variables, where they are declared and where they are used.


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites
Chimp

Hi michaelslamet

in reference to your script, you could use something like this to see all variables not repeated and the value within them,

$asVarArray = _ArrayUnique(ParseVarsFromScript($sFile))
_ArrayDelete($asVarArray, 0)
_ArrayDelete($asVarArray, 0)
For $i = 0 To UBound($asVarArray) - 1
    $asVarArray[$i] = $asVarArray[$i] & " = " & String(Execute($asVarArray[$i]))
Next
_ArrayDisplay($asVarArray)

but as you can see all the variables that are declared as "Local" within functions are not recognized outside of the functions and are therefore listed as empty. in addition if it is an array, also appear as empty, while the variables in the same "scope" are listed with their value (in this case only $i and $sFile)
bye


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
michaelslamet

Thank you AZJIO, thank you PincoPanco.

AZJIO, your scripts are for displaying list of vars on another scripts.

PincoPanco, the modified script seems promising when run from SciTE, but display nothing when compiled.

I wish to add this feature to all of my scripts to help debugging when run, so it can display all of the vars used and their content,

I think it's not possible, moreover in the compiled mode?

Share this post


Link to post
Share on other sites
michaelslamet

Thank you, Bowmore :) Unfortunetely, using tidy.exe is not an option :(

Share this post


Link to post
Share on other sites
BrewManNH

There is no way for a script to display the contents of all of its variables at runtime without a LOT of consolewrites/filewrites/msgboxs etc. What you should look at is the AutoIt debugger written by Stumpii that will help in debugging your script, other than that I can't think of any way for you to get this information.

BTW, without using a LOT of consolewrites/filewrites/msgboxs etc. you can't get this information at all with a compiled script.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
jchd

You're barking at the wrong tree. Learn and strictly apply robust programming practices first, then 99.99% of your problems will vanish.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
michaelslamet

You're barking at the wrong tree. Learn and strictly apply robust programming practices first, then 99.99% of your problems will vanish.

 

I'm not trying to hide any errors. I just think this is a nice feature to have.

Currently from any of my scripts, I can press hot key, enter var name is the value displayed. This is a nice feature that I "stole" from one of post lately,

then I think it will be great if we can display all the var names and their value anytime we need when run the script.

Shoudn't everybody need a debugger, no matter how roboust programming practices applied? :)

By that I'm not saying I apply a roboust programming practices because most of my scripts are --while can run perfectly most of the time-- messy

in variable names, logic, etc.

Share this post


Link to post
Share on other sites
michaelslamet

There is no way for a script to display the contents of all of its variables at runtime without a LOT of consolewrites/filewrites/msgboxs etc. What you should look at is the AutoIt debugger written by Stumpii that will help in debugging your script, other than that I can't think of any way for you to get this information.

BTW, without using a LOT of consolewrites/filewrites/msgboxs etc. you can't get this information at all with a compiled script.

 

Ok noted :) So confirm this is not possible?

Share this post


Link to post
Share on other sites
mLipok

yes it is possible

 

look in scite

MENU: Tools/Debug ...

MENU: Tools/Trace: ...

MENU: Tools/Debug Trace: ...

for example

MENU: Tools/Trace: Add Func trace line

 
this is something like you need
but of course this is not exactly what you need, becasue this function are not created for trace/debug variables

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library
 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-10-31

Share this post


Link to post
Share on other sites
MHz

michaelslamet,
So I guess you did not see my relic >_DebugGlobalVars() from 2006. It seems to work in the beta but not 3.3.8.1. Perhaps I was ahead of my time. :idiot:

Dumping Global variables from a function is easy though doing Local variables is something else. The debug code running in the script may need to be in the function of choice to get the Locals variables for that function.

Here is something more current with StringRegExp to help make it more efficient.

#include <array.au3>
OnAutoItExitRegister('_DumpGlobalVars')

Global _
    $string = 'This is a string with a @TAB' & @TAB & 'and it ends with @CRLF' & @CRLF, _
    $array[11], _
    $binary = StringToBinary($string), _
    $bool = True, _
    $false = False, _
    $float = 12.01, _
    $hex = Hex(13), _
    $hwnd = WinGetHandle("[CLASS:Shell_TrayWnd]"), _
    $int = 14, _
    $keyword = Default, _
    $number = Number(15.01), _
    $ptr = Ptr(16), _
    $struct = DllStructCreate('char[' & 65536 & ']'), _
    $true = True

Exit

Func _DumpGlobalVars()
    Local $__content, $__string, $__variable, $__format = '%-10s%-15s%s'
    $__content =  StringRegExpReplace(FileRead(@ScriptFullPath), '(*ANYCRLF);.*', '')
    $__content =  StringRegExp($__content, '(?<=\$)\w+?\b', 3)
    If IsArray($__content) Then
        $__content = _ArrayUnique($__content)
        _ArraySort($__content)
        $__string = StringFormat($__format, 'TYPE', 'VARIABLE', 'VALUE') & @CRLF
        For $__variable In $__content
            If IsDeclared($__variable) = 1 Then
                $__string &= StringFormat($__format, VarGetType(Eval($__variable)), '$' & $__variable, Eval($__variable)) & @CRLF
            EndIf
        Next
        ConsoleWrite($__string & @CRLF)
    Else
        ConsoleWriteError('No variables found' & @CRLF)
    EndIf
EndFunc

It will dump all Globals to the console when the script has exited as the setting of OnAutoItExitRegister does this. :)

This is the output from the example:

TYPE      VARIABLE       VALUE
Array     $array         
Binary    $binary        0x54686973206973206120737472696E6720776974682061204054414209616E6420697420656E64732077697468204043524C460D0A
Bool      $bool          True
Bool      $false         False
Double    $float         12.01
String    $hex           0000000D
Ptr       $hwnd          0x0001007E
Int32     $int           14
Keyword   $keyword       Default
Double    $number        15.01
Ptr       $ptr           0x00000010
String    $string        This is a string with a @TAB   and it ends with @CRLF

DLLStruct $struct        
Bool      $true          True
  • Like 1

Share this post


Link to post
Share on other sites
mLipok
@MHz
thank you for this script, it is really very useful
 
ps.
have you thought about adding it to the "Example Scripts"
I think it's worth
 
EDIT: typo
EDIT2:
sorry I see
it is on example script
Edited by mlipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library
 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-10-31

Share this post


Link to post
Share on other sites
michaelslamet

@MHz,

This is impressing! :thumbsup:

Any change to display those vars name and their content when the script is compiled?

I tried it, it run well on SciTE but display only header (TYPE             VARIABLE              VALUE) when compiled

Thanks!

Share this post


Link to post
Share on other sites
MHz

Thanks for the compliment. B)

The FileRead will not work well at all on a binary file. It relies on you running the source as au3. So I can not satisfy your request. :ph34r:

Share this post


Link to post
Share on other sites
mLipok

 

yes it is possible

 

look in scite

MENU: Tools/Debug ...

MENU: Tools/Trace: ...

MENU: Tools/Debug Trace: ...

for example

MENU: Tools/Trace: Add Func trace line

 
this is something like you need
but of course this is not exactly what you need, becasue this function are not created for trace/debug variables

 

@michaelslamet

you need a tool what I mention


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library
 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-10-31

Share this post


Link to post
Share on other sites
MHz

Any change to display those vars name and their content when the script is compiled?

I tried it, it run well on SciTE but display only header (TYPE             VARIABLE              VALUE) when compiled

As a thought. You could FileInstall the source from the compiled script and read from that one instead.

So the function would be

#include <array.au3>
OnAutoItExitRegister('_DumpGlobalVars')

Global _
    $string = 'This is a string with a @TAB' & @TAB & 'and it ends with @CRLF' & @CRLF, _
    $array[11], _
    $binary = StringToBinary($string), _
    $bool = True, _
    $false = False, _
    $float = 12.01, _
    $hex = Hex(13), _
    $hwnd = WinGetHandle("[CLASS:Shell_TrayWnd]"), _
    $int = 14, _
    $keyword = Default, _
    $number = Number(15.01), _
    $ptr = Ptr(16), _
    $struct = DllStructCreate('char[' & 65536 & ']'), _
    $true = True

Exit

Func _DumpGlobalVars()
    Local $__content, $__path, $__string, $__variable, $__format = '%-10s%-15s%s'
    If @Compiled Then
        If FileExists(StringTrimRight(@ScriptFullPath, 4) & '.au3') Then
            $__path = StringTrimRight(@ScriptFullPath, 4) & '.au3'
        Else
            Return 0
        EndIf
    Else
        $__path = @ScriptFullPath
    EndIf
    $__content =  StringRegExpReplace(FileRead($__path), '(*ANYCRLF);.*', '')
    $__content =  StringRegExp($__content, '(?<=\$)\w+?\b', 3)
    If IsArray($__content) Then
        $__content = _ArrayUnique($__content)
        _ArraySort($__content)
        $__string = StringFormat($__format, 'TYPE', 'VARIABLE', 'VALUE') & @CRLF
        For $__variable In $__content
            If IsDeclared($__variable) = 1 Then
                $__string &= StringFormat($__format, VarGetType(Eval($__variable)), '$' & $__variable, Eval($__variable)) & @CRLF
            EndIf
        Next
        ConsoleWrite($__string & @CRLF)
    Else
        ConsoleWriteError('No variables found' & @CRLF)
    EndIf
EndFunc

So if I run that compiled where the source is in the same directory and with same base name, then running the command "compiledscript.exe > out.txt" will output the variables to the out.txt file.

Share this post


Link to post
Share on other sites
mLipok

This script is still developing here:

'?do=embed' frameborder='0' data-embedContent>>


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library
 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-10-31

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×