Jump to content

[Solved] "Is there equivalence variables == 'local' ByRef ?" No.


Recommended Posts

Posted (edited)

Short Answer: No.

- there are similar ways of doing things, each bringing their own level of verbosity to the table, all of which bring more verbosity and/or obscurity to things.

Easiest way to get here is to early on say $a = $b ... work with $b in the program, then copy it back before ending, $b = $a.

e.g. $gNumIterations = $array[20][21]

...

$array[20][21] = $gNumIterations

IniWrite

<hr>

Is there an equivalent to bash nameref / C pointers in autoit?

[Not talking about the pointers noted in the help file.]

char *cptr1, *cptr2=cptr1 sort of thing.

Suppose I have $array[2]=["key", 1]

Growing large enough, this all becomes a mouthful.

Suppose: $keyval = $array[2]

Is there a way (without function calls), wherein keyal is equivalenced to array[2]? Some languages would call it a macro, or cpp would substitute the verbiage in for you.

Or, essentially: $keyval = ByRef $array[2]

[int *keyval = &array[2]] ( = array[2]? It's been a while.)

[Groping for the right language to use here.]

Happy if there is another / better way to do it.

In this particular use case, I have loaded an .ini file into an array.

Constantly referencing $inival[20][21] is essentially meaningless to the code maintainer, whereas if:

$numRepititions = ByRef $inival[20][21]

were possible, the code maintainer seeing $numReptitions would be meaningful.

And IniWrite would do the intuitive.

 

Are equivalenced vars available in autoit?

Edited by bs27975
Close question.
Link to post
Share on other sites
  • Moderators

bs27975,

If you mean "Can 2 variables be linked so that changing one automatically changes the other" then to the best of my knowledge this functionality does not exist in AutoIt.

But if you are looking for a way to make obscure array values make sense, then I can offer 2 options:

1: Code with the Beta and use a Map variable to store your data - think "scripting dictionary".

2: Use Enum to give readable names to the array indices. Here is a snippet of code from one of my projects where I open a dialog:

; Create an emumerated list of the various controls
Local Enum $eStart, $eReset, $eRepeat, $eReload, $eAlbum, $eRecent, $eGenre, $eRepeat_Option_State, $eGenre_Option_State, $eFolder_Name, $eFolder_Alias, $eFolder_Data_File, $eMax

; Create an array to hold the various ControlIDs
Local $aParam_List[$eMax]

; And then later fill the list
$aParam_List[$eStart] = GUICtrlCreateRadio("Since Start", 10, 20, 80, 20)
$aParam_List[$eReset] = GUICtrlCreateRadio("Since Reset", -1, 20, 80, 20)
$aParam_List[$eRepeat] = GUICtrlCreateCheckbox(" No Repeats ", 20, 55)
$aParam_List[$eReload] = GUICtrlCreateCheckbox(" Track Reload", 120, 80)
$aParam_List[$eAlbum] = GUICtrlCreateCheckbox(" Album Mode", 120, 100)
$aParam_List[$eRecent] = GUICtrlCreateCheckbox(" Save Recent", 220, 80)
$aParam_List[$eGenre] = GUICtrlCreateCheckbox(" Genre List", 220, 100)

; Which you can then reference later like this
Case $aParam_List[$eRepeat]
    Switch GUICtrlRead($aParam_List[$eRepeat])
        Case 1
            GUICtrlSetState($aParam_List[$eStart], $GUI_ENABLE)
            GUICtrlSetState($aParam_List[$eReset], $GUI_ENABLE)
        Case Else
            GUICtrlSetState($aParam_List[$eStart], BitOR($GUI_DISABLE, $GUI_UNCHECKED))
            GUICtrlSetState($aParam_List[$eReset], BitOR($GUI_DISABLE, $GUI_UNCHECKED))
    EndSwitch

I hope that helps.

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 post
Share on other sites

It's possible if you store your variable(s) in a struct, and then retrieve a ptr to it (or any var inside it at the appropriate offset) with dllstructgetptr, see this thread. You can create as many "referencing" variables as you like with dllstructcreate when parsing the obtained ptr as second parameter. Then simply perform data I/O using dllstructget/setdata.

Link to post
Share on other sites
  • Moderators

RTFC,

Thanks for reminding me of the "IKEA" method.

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 post
Share on other sites

If the question is 

5 hours ago, Melba23 said:

Can 2 variables be linked so that changing one automatically changes the other

then, (besides various dll methods), there is this method, shown here:

$a=1

f($a, $a)

Func f(ByRef $b, ByRef $c)

$b+=1

ConsoleWrite($c)

EndFunc

The trick is sending the same variable to the function f() twice, then ByRef’ing it into to differently named locals.

Following the rules of Quantum Entanglement, modifying one will change the other.
Not sure if this method actually helps the OP; I’ve been looking for a way to use it without luck for sometime*

*First mentioned in the widely panned post “Guess The Output” :)

 


 

Code hard, but don’t hard code...

Link to post
Share on other sites
5 hours ago, Melba23 said:

... 2: Use Enum to give readable names to the array indices. Here is a snippet of code from one of my projects where I open a dialog:

Or, just:

$array[2]

$x=0

$y=1

$array[$x]

Link to post
Share on other sites
Posted (edited)

I agree that, as already shown above, giving meaningful human readable names to indexes is the simplest way on this case.
p.s. (just out of curiosity)
Although not exactly "on the subject" but somewhat related, here (https://www.autoitscript.com/forum/topic/201373-question-that-is-kinda-a-riddle/?do=findComment&comment=1445124) is another possible solution "workaround" on this topic..

 

Edited by Chimp

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

Link to post
Share on other sites
Posted (edited)
10 hours ago, bs27975 said:

Constantly referencing $inival[20][21] is essentially meaningless to the code maintainer, whereas if:

$numRepititions = ByRef $inival[20][21]

were possible, the code maintainer seeing $numReptitions would be meaningful.

Func numRepititions() ; this is called a helper function
    Return $inival[20][21]
EndFunc

Hope this does it.

Edited by argumentum
oops
Link to post
Share on other sites
  • 2 weeks later...
Posted (edited)
On 5/5/2021 at 10:55 PM, JockoDundee said:

@bs27975, would something like this work for you (assuming you use the interpreter)?

#include "DefineUDF.au3"

#define $gNumIterations $array[20][21]
#define $iAge 25

Local $array[25][25]
$array[20][21]="bingo"

MsgBox(1,"#define","you must be "& $iAge &" to play "& $gNumIterations)


1.25 kB · 6 downloads

Interesting. Self-modifying code. In essence, some of the functionality of cpp.  (Called macros, https://en.wikipedia.org/wiki/Macro_(computer_science), by some other languages. [Not Auto-it, different beastie there.])

Problem with 'numRepititions()' is that it adds an additional level of obscurity to what one gets into as a 'simple' .cmd replacement scripting language. 

Mayhap m4 (macro processor) https://en.wikipedia.org/wiki/M4_(computer_language) , perhaps combined with make https://en.wikipedia.org/wiki/Make_(software) brings something to this table.

At which point one is in to a full bore development environment - which is probably warranted. Long term, one must establish coding / project practices, including  some form of RCS - if one wants to maintain any semblance of sanity.

Mayhap I need to look deeper into some form of IDE (Eclipse?) - my code and comment bloat as I transit the autoit learning curve is increasing exponentially, and such may let me be comfortable with nuking old grabage sooner rather than later.

[I have no familiarity with Eclipse, just used it here as a generic popular IDE. Perhaps my bad, for AutoIt. Couple quick pokes seems to reveal that Eclipse isn't as popular or universal as I expected. Maybe I should have written ISN AutoIt Studio.]

Edited by bs27975
Link to post
Share on other sites
Posted (edited)
8 hours ago, bs27975 said:

Interesting. Self-modifying code. In essence, some of the functionality of cpp. 

I would not have done it if not for you, but now I’ve started to use it myself.

I’m not sure with what ramifications there are using the symbol # at the start of a line with words other than include and pragma etc.

It seems as though it’s just ignored, but then again there’s nothing stopping a version of the language from adding #define, which might screw me :)

In your case, just a regular ole’ pointer would do.  The ByRef thing comes tantalizingly close to doing what you want, but just needs a construct like (as you mentioned previously)

Local $aPtr = ByRef $aStr

Anyway, I need to add functional macro support to make it really useful, so...

Edited by JockoDundee
“as you mentioned previously”

Code hard, but don’t hard code...

Link to post
Share on other sites
On 5/5/2021 at 4:15 AM, bs27975 said:

Constantly referencing $inival[20][21] is essentially meaningless to the code maintainer, whereas if:
$numRepititions = ByRef $inival[20][21]

Func numRepititions($v = default) ; this is called a helper function
    If $v <> default Then $inival[20][21] = $v
    Return $inival[20][21]
EndFunc
or
Global $numRepititions = "Value"
or
Global Enum $numRepititions = 20
$inival[$numRepititions]
or
etc.

There's only so much you can do. Why an array to start with.

6 hours ago, bs27975 said:

Long term, one must establish coding / project practices, including  some form of RCS - if one wants to maintain any semblance of sanity.

Yes. The UDF style is widely accepted in the AutoIt community given the language and that is what I presented. But yes, however you start, you're kind of stuck with the style.

Link to post
Share on other sites
Posted (edited)
1 hour ago, argumentum said:

Why an array to start with.

Vartype arrays, like those in AutoIt, are often used like C structs*, to store heterogeneous collections of variables, due to the lack of a native implementation of structs (in the release version).
 

*yes you can ObjCreate or use DllStruct as well.

Edited by JockoDundee

Code hard, but don’t hard code...

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...