Jump to content

Enumeration Help


Recommended Posts

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? :)

Link to comment
Share on other sites

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

  • Moderators

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

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 comment
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 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

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:

Link to comment
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 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

  • Moderators

water,

keyword Enum makes them a Constant by default

Correct. :thumbsup:

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 comment
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 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

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

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

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

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 :/

Link to comment
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 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

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

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...