Jump to content

Important autoit limitation.


boludoz
 Share

Recommended Posts

So far I only found one limitation, if I call a function that has Default in its arguments and add a byref at the end it won't accept the byref because "error: all params followed by optional params must be optional", then I can't add a default value to the byref but I can't call it either, what am I supposed to create a global variable to pass a single variable through? the incompatibility of byref with the rest of the forms seems to me a "senseless" limitation, I also can't call a byref that was previously called; why don't you guys just delete the byref, it seems to me not a complete function, maybe it's better to go back to the primitive global.

Guys I know that they do this from the heart, but I only have that gravity so that they become aware of how important byref is for us; I love you, thanks for all greetings.

Edited by boludoz
Link to comment
Share on other sites

Global $sParam3 = "Test"
_Func1("param1", Default, $sParam3)

Func _Func1($sParam1, $sParam2 = Default, $sParam3 = "")
EndFunc

Func _Func2($sParam1, $sParam2 = Default, ByRef $sParam3)
EndFunc

Func _Func3($sParam1, ByRef $sParam3, $sParam2 = Default)
EndFunc

returns error:

Quote

"C:\Local\Test_Limitations.au3"(7,49) : error: all params followed by optional params must be optional.
Func _Func2($sParam1, $sParam2 = Default, ByRef $sParam3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
"C:\Local\Test_Limitations.au3"(7,58) : error: syntax error
Func _Func2($sParam1, $sParam2 = Default, ByRef $sParam3 =
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Local\Test_Limitations.au3 - 2 error(s), 0 warning(s)
!>11:19:27 AU3Check ended. Press F4 to jump to next error.rc:2

As ByRef for an optional parameter does not make sense, AutoIt expects the parameter to be mandatory.
Hence you need to first pass all mandatory, then the optional parameters. See _Func3.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

@boludoz  is raising a good point, albeit in an unduly offensive way.

In AutoIt and by construction, an optional parameter has a default value.
Current ByRef modifier implies non-optional, but it could be more flexible: if a parameter is passed, then ByRef it else ByRef the default value.

The help file (Func ...) says "However, a literal cannot be passed to a ByRef parameter." but this is untrue:

what(123)
what("abc")
what(Null)
what(Default)

Func what(ByRef $a)
    ConsoleWrite(VarGetType($a) & @TAB & ($a = Null ? "Null" : $a) & @LF)
EndFunc

Here we're passing literals, which work fine.

What the OP expects is that this code:

which(123)
which("abc")
which()

Func which(ByRef $a = 5)
    ConsoleWrite(VarGetType($a) & @TAB & ($a = Null ? "Null" : $a) & @LF)
EndFunc

would work and produce:

Int32   123
String  abc
Int32   5

which is a perfectly legitimate feature request (whose place is in Trac, not agressively posted in Help).

11 hours ago, boludoz said:

I also can't call a byref that was previously called

I don't get this part. Show some code.

Edited by jchd

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

43 minutes ago, jchd said:

Here we're passing literals, which work fine.

I don't know what version you are using but I can't run this code :

+>07:06:08 Starting AutoIt3Wrapper v.19.102.1901.0 SciTE v.4.1.2.0   Keyboard:00001009  OS:WIN_7/Service Pack 1  CPU:X64 OS:X64  Environment(Language:040C)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\User\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\User\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:C:\Applications\AutoIt\ZZTemp\Temp4.au3
"C:\Applications\AutoIt\ZZTemp\Temp4.au3"(6,20) : error: what() previously called with Const or expression on ByRef param(s).
Func what(ByRef $a)
~~~~~~~~~~~~~~~~~~~^
"C:\Applications\AutoIt\ZZTemp\Temp4.au3"(1,9) : REF: first call to what().
what(123)
~~~~~~~~^
C:\Applications\AutoIt\ZZTemp\Temp4.au3 - 1 error(s), 0 warning(s)
!>07:06:09 AU3Check ended. Press F4 to jump to next error.rc:2
+>07:06:09 AutoIt3Wrapper Finished.
>Exit code: 2    Time: 0.8277

 

Edited by Nine
Link to comment
Share on other sites

AFAIK, passing literals to "ByRef  $varnameinfunc" should not work, as $varnameinfunc is used neither as a local variable nor as a pointer, but as a direct reference (which is different from a pointer, think of it as an alias) to the original parsed variable, meaning that the original variable is itself directly acted upon in the function. Also, since a literal is not a variable, no changes to it can be stored for future reference. "ByRef $varnameinfunc=Default" should similarly fail for the same reason ("Default" is not a $variable either).

Link to comment
Share on other sites

1 hour ago, Nine said:

I don't know what version you are using but I can't run this code :

The "error" comes from Au3Check. Use #AutoIt3Wrapper_Run_AU3Check=n to actually run the code (which works).

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

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

×
×
  • Create New...