MadaraUchiha Posted November 24, 2013 Posted November 24, 2013 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?
water Posted November 24, 2013 Posted November 24, 2013 (edited) This would be in AutoIt: Global Enum $FileTypeUnknown, $FileTypeDisk, $FileTypeChar, $FileTypePipe, FileTypeRemote = 0x8000 Edited November 24, 2013 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
Moderators Melba23 Posted November 24, 2013 Moderators Posted November 24, 2013 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 = 0x8000I 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 = 0x8000Your choice. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
water Posted November 24, 2013 Posted November 24, 2013 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 2024-07-28 - Version 1.6.3.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 (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
MadaraUchiha Posted November 24, 2013 Author Posted November 24, 2013 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)
water Posted November 24, 2013 Posted November 24, 2013 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 2024-07-28 - Version 1.6.3.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 (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
Moderators Melba23 Posted November 24, 2013 Moderators Posted November 24, 2013 water,keyword Enum makes them a Constant by defaultCorrect. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
water Posted November 24, 2013 Posted November 24, 2013 That was easy - it wouldn't be sensible the other way round My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
MadaraUchiha Posted November 24, 2013 Author Posted November 24, 2013 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
water Posted November 24, 2013 Posted November 24, 2013 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 2024-07-28 - Version 1.6.3.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 (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
MadaraUchiha Posted November 24, 2013 Author Posted November 24, 2013 But how would I set the return type to my DllCall then? ;o
water Posted November 24, 2013 Posted November 24, 2013 Declare a variable. Based on your C# code it would be named $Filetype. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
MadaraUchiha Posted November 24, 2013 Author Posted November 24, 2013 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 :/
water Posted November 24, 2013 Posted November 24, 2013 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 2024-07-28 - Version 1.6.3.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 (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
MadaraUchiha Posted November 24, 2013 Author Posted November 24, 2013 Sure, but in this case, the return type can vary?
kylomas Posted November 24, 2013 Posted November 24, 2013 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now