Jump to content
leuce

Update variable value automatically in terms of its definition

Recommended Posts

Hello everyone

Is there a way in AutoIt to make the value of a variable automatically update when any of the other variables that form part of its definition get updated?  Here's what I mean:

$a = 2
$b = $a + 1 ; now $b is 3
$a = 5 ; now I want $b to be 6 (because $b = $a + 1)
MsgBox (0, "", $b, 0) ; but no, $b is still only 3

Thanks!

Samuel

 

Edited by leuce

Share this post


Link to post
Share on other sites

Not by default.  But you could use Scripting.Dictionnary to hold your definitions.  And then have a function that uses Execute and Assign to apply all the definitions on a variable change.  Doable, require some work tho... 

Share this post


Link to post
Share on other sites

Hello there,

AdlibRegister would help for that. Check the Console to see the result.

HotKeySet('{ESC}', _Exit)

$a = 2
$b = $a + 1 ; now $b is 3
$a = 5 ; now I want $b to be 6 (because $b = $a + 1)

AdlibRegister('Update', 1000) ;1000 = 1 Second

While 1
WEnd

Func _Exit()
    Exit
EndFunc

Func Update()
    $b = $a + 1
    ConsoleWrite(@CRLF & $b & @CRLF) ;@CRLF - USED FOR A NEW ROW
EndFunc

Edit : Press ESC to Exit.

Edited by _Vlad
Press ESC to Exit.

Quote
Destiny is a name often given in retrospect to choices that had dramatic consequences.  J.K. Rowling

 

Share this post


Link to post
Share on other sites

@leuce

Much robust and simple: make that a function.


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

On a single definition, there is no issue.  But let's say he has few hundreds of those definitions that he wants to follow on.  Then it can become quite a challenge.

Share this post


Link to post
Share on other sites

OK but let's start with one.


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
6 hours ago, jchd said:

OK but let's start with one.

You have a hard time with someone telling you differently.  Kind of annoying you know ?

Share this post


Link to post
Share on other sites

In this particular case I guessed a simple and clear solution was preferable.  You have your right to think otherwise.


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
Global $b

$a = A(2)
$b = $a + 1 ; now $b is 3
$a = A(5) ; now I want $b to be 6 (because $b = $a + 1)
MsgBox (0, "", $b, 0) ; but no, $b is still only 3

Func A($value)
    $b = $value + 1
    Return $value
EndFunc

 

EDIT: This is fixed version

Global $b

$a = A(2) ; now $b is 3
$a = A(5) ; now I want $b to be 6 (because $b = $a + 1)
MsgBox (0, "", $b, 0) ; but no, $b is still only 3

Func A($value)
    $b = $value + 1
    Return $value
EndFunc

 

Edited by Zedna

Share this post


Link to post
Share on other sites

https://www.autoitscript.com/autoit3/docs/functions/Execute.htm

Is probably what you want but will depend on your requirements

$a = 2
$b = "$a + 1" ; now $b is 3
$a = 5 ; now I want $b to be 6 (because $b = $a + 1)
MsgBox (0, "", execute($b), 0) ; but no, $b is still only 3

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...