Sign in to follow this  
Followers 0
MadaraUchiha

Enumeration Help

16 posts in this topic

Hello,

I want to ask you how to handle the enum keyword in AutoIt, since I am not very familiar with enumerations in AutoIt.

So, I already checked the Help files description, for enums:  http://www.autoitscript.com/autoit3/files/beta/autoit3-docs/keywords/Enum.htm

But, I am currently playing arround with DllCall's and stuff, I have a enumeration like this:

Return code/valueDescription

FILE_TYPE_CHAR 0x0002

The specified file is a character file, typically an LPT device or a console.

FILE_TYPE_DISK 0x0001

The specified file is a disk file.

FILE_TYPE_PIPE 0x0003

The specified file is a socket, a named pipe, or an anonymous pipe.

FILE_TYPE_REMOTE 0x8000

Unused.

FILE_TYPE_UNKNOWN 0x0000

Either the type of the specified file is unknown, or the function failed.

 
In C# I would enumerate it like this:
 

enum FileType : uint

    {
    FileTypeChar = 0x0002,
    FileTypeDisk = 0x0001,
    FileTypePipe = 0x0003,
    FileTypeRemote = 0x8000,
    FileTypeUnknown = 0x0000,
    }

 

But I am not sure how to do it with AutoIt.

How can I clear make a enumeration with all variables holding the differnent values?

Can someone point me to the right direction? :)


Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This would be in AutoIt:

Global Enum $FileTypeUnknown, $FileTypeDisk, $FileTypeChar, $FileTypePipe, FileTypeRemote = 0x8000
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

MadaraUchiha,

What you have in that C# code looks like a datatype declaration and subsequent variable assignment - remember that in AutoIt you do not need to declare the datatype as we only have one. ;)

Enum essentially declares a list of variables with a fixed interval between them. So in your case you could do something like this:

; These will be set automatically to 0, 1, 2, 3
Local Enum $FILE_TYPE_UNKNOWN, $FILE_TYPE_DISK, $FILE_TYPE_CHAR, $FILE_TYPE_PIPE
; But you will have to declare this one separately
Local $FILE_TYPE_REMOTE = 0x8000
I question whether this is much of a saving over a full declaration:

Local $FILE_TYPE_UNKNOWN = 0, $FILE_TYPE_DISK = 1, $FILE_TYPE_CHAR = 2, $FILE_TYPE_PIPE = 3, $FILE_TYPE_REMOTE = 0x8000
Your choice. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

I was a bit faster ;), but Melba's given a more complete explanation.

If your enumeration starts with 0 and increments in steps of 1 you can use the defaults and shorten the code a bit (as you can see in my example).


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

First, thanks you two for your replies.

I already realized, I also can do it like this, can't I?

Global Enum $FileTypeChar = 0x0002, $FileTypeDisk = 0x0001, $FileTypePipe = 0x0003, $FileTypeRemote = 0x8000, $FileTypeUnknown = 0x0000

MsgBox(0,'','FileTypeChar : ' & $FileTypeChar)
MsgBox(0,'','FileTypeDisk : ' & $FileTypeDisk)
MsgBox(0,'','FileTypePipe : ' & $FileTypePipe)
MsgBox(0,'','FileTypeRemote : ' & $FileTypeRemote)
MsgBox(0,'','FileTypeUnknown : ' & $FileTypeUnknown)

But one thing is confusing me: Make these values constants.

I've I place the const keyword before the variable or before the enum keyword I get a syntax error? ;o

Global const Enum $FileTypeChar = 0x0002, $FileTypeDisk = 0x0001, $FileTypePipe = 0x0003, $FileTypeRemote = 0x8000, $FileTypeUnknown = 0x0000

MsgBox(0,'','FileTypeChar : ' & $FileTypeChar)
MsgBox(0,'','FileTypeDisk : ' & $FileTypeDisk)
MsgBox(0,'','FileTypePipe : ' & $FileTypePipe)
MsgBox(0,'','FileTypeRemote : ' & $FileTypeRemote)
MsgBox(0,'','FileTypeUnknown : ' & $FileTypeUnknown)

:ermm:


Share this post


Link to post
Share on other sites

Can't test it at the moment, but I think keyword Enum makes them a Constant by default.

Try to assign a new value to one of the variables.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

water,

keyword Enum makes them a Constant by default

Correct. :thumbsup:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

That was easy - it wouldn't be sensible the other way round ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Hm, is it possible to name my enumeration somehow? Because the return type of my DllCall to kernel32.DLL GetFileType has one of those as return type...

And I need to set them as return type somehow;o


Share this post


Link to post
Share on other sites

As you can see from the syntax description in the help file you can't assign a name to the enumeration.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

But how would I set the return type to my DllCall then? ;o


Share this post


Link to post
Share on other sites

Declare a variable. Based on your  C# code it would be named $Filetype.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Yes, but I already declared it in my enum? ;o

And since the return tyoe can be different in different cases, I need to make it decide whats the correct one...

Global Enum $FileTypeChar = 0x0002, $FileTypeDisk = 0x0001, $FileTypePipe = 0x0003, $FileTypeRemote = 0x8000, $FileTypeUnknown = 0x0000


Local $result = DllCall("kernel32.dll", "???", "GetFileType", Parameter stuff??)

But How? I am not so experienced with this stuff yet :/


Share this post


Link to post
Share on other sites

If you check the help file for DllCall you will see that you have to define the type of the returned result. The help file lists tghe valid types (Int, str etc.).


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Sure, but in this case, the return type can vary?


Share this post


Link to post
Share on other sites

MU,

The Windows function "GetFileType" only returns one type of value.  See this doc.

Also, your reply in post #5 leads me to believe that you do not understand M23's reply in post #3.

Enum does nothing more than assign incrementing values to constants.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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  
Followers 0