Jump to content
Sign in to follow this  
trap16

C like macro

Recommended Posts

trap16

Hello,

I looked in help file but did not find any way to use an equivalent to C Macro #define keyword

This is an (useless) example i would like to insert in autoit script :

#define myMacro(x,y) ((x < 10 and y < 10))

If myMacro($a,$c) Then

; do process

Endif

Best regards.

Edited by trap16

Share this post


Link to post
Share on other sites
jchd

No such construct exists in AutoIt, only actual functions.


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
Fulano

You could implement something like that by making a script that defines your macros and run it on your source code to convert your shortcuts into code.

Probably wouldn't make sense though, as that sort of overhead only really makes sense with a compiled language.


#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Share this post


Link to post
Share on other sites
AdmiralAlkex

I looked in help file but did not find any way to use an equivalent to C Macro #define keyword

You would use a function.

Here's an example:

Local $iA = 7, $iC = 5

If _myFunction($iA, $iC) Then
    MsgBox(0, "Shut up while i'm talking", "The numbers seem to be smaller than 10")
EndIf

Func _myFunction($iX, $iY)
    If $iX < 10 And $iY < 10 Then Return True
EndFunc

Share this post


Link to post
Share on other sites
Richard Robertson

You would use a function.

Here's an example:

Local $iA = 7, $iC = 5

If _myFunction($iA, $iC) Then
    MsgBox(0, "Shut up while i'm talking", "The numbers seem to be smaller than 10")
EndIf

Func _myFunction($iX, $iY)
    If $iX < 10 And $iY < 10 Then Return True
EndFunc

That made me sad Alkex. You have no return value if either number is larger than 10.

Share this post


Link to post
Share on other sites
AdmiralAlkex

That made me sad Alkex. You have no return value if either number is larger than 10.

There's no need for that since functions by default return 0, and 0 is usually returned when things go wrong in AutoIt.

Edit: And it was meant as an example based on trap's code, not a fullblown UDF meant for official inclusion in AutoIt (strange grammar?).

Edited by AdmiralAlkex

Share this post


Link to post
Share on other sites
jchd

Alkex, make Richard's day sunny again with even simpler code, as both of you know:

Func _myFunction($iX, $iY)
 Return(($iX < 10) And ($iY < 10))
EndFunc

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
AdmiralAlkex

I think Richard wanted the opposite.

Func _IsNumberOver10($iX, $iY)
    If (Not IsNumber($iX)) Then Return SetError(2, 0, False)
    If (Not IsNumber($iY)) Then Return SetError(3, 0, False)

    If $iX < 10 And $iY < 10 Then Return True
    Return SetError(1, 0, False)
EndFunc

Share this post


Link to post
Share on other sites
trap16

Thanks for the information.

Best regards.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.