Jump to content

What's the full extent of the usefulness of $Variable()


Morthawt
 Share

Recommended Posts

Yes. The only real thing I could come up with is instead of always using ThisNewFunctionThatHasAReallyDescriptiveName(whatever) you could

$go = ThisNewFunctionThatHasAReallyDescriptiveName

$go(whatever)

I am just trying to get a full understanding of these few new features so that I know where I am going with them and why. So is this purely a time saving thing or is there some important nuance I am missing of another reason this is good?

Edited by Morthawt
Link to comment
Share on other sites

There has been lengthy discussions about the pros and cons of this ability when they were introduced into beta.

I don't remember a link in dev chat, but worth having a peek, see if you can find it.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I don't believe there has ever been any "cons". Unless there was somebody really retarded involved in discussion.
Besides $Variable() existed since almost forever in the language. It was normally used for object variables to access default property/method:

$Variable = ObjCreate("Shell.Explorer")
ConsoleWrite($Variable() & @CRLF)

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

I don't believe there has ever been any "cons". Unless there was somebody really retarded involved in discussion.

 

Just an assumption darlin, someone always pipes up with a negative.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Just an assumption darlin, someone always pipes up with a negative.

;)

"Just be fred, all we gotta do, just be fred."  -Vocaliod

"That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha

@tabhooked

Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation

Link to comment
Share on other sites

and it rules out Call() (unless one is willing to make horrible computed function calls).

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)

Link to comment
Share on other sites

Morthawt.,

 A good example is _ArrayDisplay() where before the user function was being called by Call(), but I made a suggestion (in the MVP Forum) to change to a "first class object". Voila, you now see a real world example.

JohnOne,

I don't even remember a discussion taking place about this.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Well it was first introduced here >> '?do=embed' frameborder='0' data-embedContent>> and discussed a little bit >here. But it's a good addition to the language and no one should doubt that!

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Morthawt.,

 A good example is _ArrayDisplay() where before the user function was being called by Call(), but I made a suggestion (in the MVP Forum) to change to a "first class object". Voila, you now see a real world example.

JohnOne,

I don't even remember a discussion taking place about this.

 

In the example code for _ArrayDisplay() I see no mention of using Call() I don't think I understand what you are getting at. I still do not understand the benefit of this first class object business with regards to this new function thing. What is the tangible benefit to using it? I am just trying to understand it so that I know when and why to use it.

Edited by Morthawt
Link to comment
Share on other sites

  • Moderators

Morthawt,

Here is a concrete example, albeit simple, of how the new fucntionality works. :)

Up until now, passing a function to another function had to be done like this:

; Determine Autoit folder
Global $sRootFolder = StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", Default, -1))
ConsoleWrite($sRootFolder & @CRLF)

; Define a function
Func _FunctionToCall($sFile)
    ConsoleWrite($sFile & @LF)
EndFunc   ;==>_FunctionToCall

; Pass the function NAME to another function
_ListFolder($sRootFolder, "_FunctionToCall")

Func _ListFolder($sPath, $sFunctionToCall)

    If StringRight($sPath, 1) <> '\' Then $sPath &= '\'
    Local $hFind = FileFindFirstFile($sPath & "*.*")
    If $hFind < 0 Then Return SetError(1)
    Local $sFile
    While 1
        $sFile = FileFindNextFile($hFind)
        If @error Then ExitLoop

        ; We need to use Call to run the function as all we have is the NAME
        Call($sFunctionToCall, $sFile) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    WEnd

    FileClose($hFind)
EndFunc   ;==>_ListFolder
For various reasons this was less than ideal - particularly if you used Obfuscator. ;)

We can now do it like this:

; Determine Autoit folder
Global $sRootFolder = StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", Default, -1))
ConsoleWrite($sRootFolder & @CRLF)

; Define a function
Func _FunctionToCall($sFile)
    ConsoleWrite($sFile & @LF)
EndFunc   ;==>_FunctionToCall

; Pass the function itself to another function
_ListFolder($sRootFolder, _FunctionToCall)

; The function is assigned to a variable in this function definition line 
Func _ListFolder($sPath, $hFunctionToCall)
    
    If StringRight($sPath, 1) <> '\' Then $sPath &= '\'
    Local $hFind = FileFindFirstFile($sPath & "*.*")
    If $hFind < 0 Then Return SetError(1)
    Local $sFile
    While 1
        $sFile = FileFindNextFile($hFind)
        If @error Then ExitLoop
        
        ; We can now run the function directly
        $hFunctionToCall($sFile) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        
    WEnd
    FileClose($hFind)
    
EndFunc   ;==>_ListFolder
Does that help? :huh:

M23

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

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

@melba,

Your example shows how the new way to use a function can work but it doesn't show any advantages. To use 

$hFunctionToCall($sFile) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

you would have to know what parameters should be passed to the function, ie know what the function is, and so you would be doing the same as writing

_Functiontocall($File)

so when would you want to use the new feature? There would need to be a requirement to call a function without being able to predict what that function would be at design time. Since that is easily covered using conditional statements the use of the new feature is not at all obvious to me yet.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Yes I think so, unless I am mistaken you cannot use Call() in scripts you obfuscate because calls are needed during de-obfuscation right? So this offers a way to not break the script by enhancing it's ability to function in other environments. Are there any other environments where this would be crucial?

So far I have:

  • Can be used to shorten the code needed to shorten a long and repetative usage of a potentially long named function, to variableize it rather than make a shorter named function that passes the parameters to the long names function.
  • Can be used inside a function in a way that the original function, when called, can have a function as part of it's parameters so the function will perform different actions based on the "next" function that was added as a parameter to the original function as in your example. EDIT: Although as the poster above has said, that will only work if the same number and context of parameters are the same, else you might be passing a file path as a message box type etc.
Edited by Morthawt
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...