WorknMan Posted April 12, 2011 Posted April 12, 2011 I'm wondering if it's possible to set up data types in AutoIt that are a little more complex than arrays, but not really as complex as full-blown objects either. I know there's an OOP UDF floating around, but I'm not exactly sure how it works. Basically, if I've got a $person array that's set up like this: $person[0] = 'Jane' ;first name $person[1] = 'Doe' ;last name $person[2] = 23 ;age $person[3] = 'F' ;gender ; and so on ... return $person I'd like to be able to set this up as something like: $person.firstname $person.lastname $person.age .... The reason I ask is because I've got a script using an array with 15+ elements, and it gets a bit difficult to try and remember what is $array[11] when I see it in code. Plus, if I ever need to change the order of the elements, that is a huge pain in the arse when it's being passed around from function to function.
Moderators Melba23 Posted April 12, 2011 Moderators Posted April 12, 2011 WorknMan,I recognse the problem! An Associative Array might be the thing you are looking for - my favourite implementation is this one by Nutster.Take a look and see if it is what you want - please come back and ask again if you have any questions on how to use it or it does not fit your requirements. 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
iamtheky Posted April 12, 2011 Posted April 12, 2011 If the elements are going to be static you could always set them to common names. #include <array.au3> Global $person[4] $first = 0 $last = 1 $age = 2 $sex = 3 $person[$first] = 'Jane' ;first name $person[$last] = 'Doe' ;last name $person[$age] = 23 ;age $person[$sex] = 'F' ;gender ; and so on ... _arraydisplay ($person) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
trancexx Posted April 12, 2011 Posted April 12, 2011 I'm wondering if it's possible to set up data types in AutoIt that are a little more complex than arrays, but not really as complex as full-blown objects either. I know there's an OOP UDF floating around, but I'm not exactly sure how it works. For example this how: expandcollapse popup#include "oLinkedList.au3" ; Error monitoring Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc") Func _ErrFunc() ConsoleWrite("COM Error, ScriptLine(" & $oError.scriptline & ") : Number 0x" & Hex($oError.number, 8) & " - " & $oError.windescription & @CRLF) EndFunc ;==>_ErrFunc _AutoItObject_Startup() Global $oMyList = LinkedList() $oMyList.add(_CreateItem("Jane", "Doe", 23, "F")) $oMyList.add(_CreateItem("Jack", "TheRipper", 38, "M")) $oMyList.add(_CreateItem("Jill", "Scott", 40)) $oMyList.add(_CreateItem("Joey", "Tribiani", 30, "M")) Global $sFemales, $sMales For $oMember In $oMyList If $oMember.gender = "F" Then $sFemales &= @TAB & $oMember.Name & " " & $oMember.LastName & " age " & $oMember.Age & @CRLF If $oMember.gender = "M" Then $sMales &= @TAB & $oMember.Name & " " & $oMember.LastName & " age " & $oMember.Age & @CRLF Next ConsoleWrite(">Females:" & @CRLF & $sFemales) ConsoleWrite(">Males:" & @CRLF & $sMales) Func _CreateItem($sName, $sLastName, $iAge, $sGender = "F") Local $oClass = _AutoItObject_Class() $oClass.AddProperty("Name", $ELSCOPE_PUBLIC, $sName) $oClass.AddProperty("LastName", $ELSCOPE_PUBLIC, $sLastName) $oClass.AddProperty("Age", $ELSCOPE_PUBLIC, $iAge) $oClass.AddProperty("Gender", $ELSCOPE_PUBLIC, $sGender) Return $oClass.Object EndFunc When you look closer you will see it's a real life saver. Btw, there can be number of variations on the subject. ♡♡♡ . eMyvnE
WorknMan Posted April 14, 2011 Author Posted April 14, 2011 (edited) Ok, I got a lot of info to sift through here, but I have a question for trancexx, or anyone who knows I see this line in your code: Global $oMyList = LinkedList() What is that LinkedList() function? Edited April 14, 2011 by WorknMan
ProgAndy Posted April 14, 2011 Posted April 14, 2011 LinkedList is a UDF wich is defined in oLinkedList.au3. It creates an object which represents a linked list. *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
RCMorey11 Posted April 14, 2011 Posted April 14, 2011 I like to use enumerations. So I would have something like: Global Enum $eFNAME, $eLNAME, $eAGE, $eSEX, $eNUM_TRAITS Global $Person[$eNUM_TRAITS] $Person[$eFNAME] = "John" $Person[$eLNAME] = "Doe" $Person[$eAGE] = 21 $Person[$eSEX] = "M"
WorknMan Posted April 14, 2011 Author Posted April 14, 2011 LinkedList is a UDF wich is defined in oLinkedList.au3. It creates an object which represents a linked list.Well, I kind of figured as such, but was wondering where to get the UDF I thought it might be a part of the AutoItObject UDF, but don't see any reference to it in the documentation or the code.
trancexx Posted April 14, 2011 Posted April 14, 2011 (edited) Well, I kind of figured as such, but was wondering where to get the UDF I thought it might be a part of the AutoItObject UDF, but don't see any reference to it in the documentation or the code.Sorry for not saying... you can find oLinkedList.au3 inside AutoItObject package in \Examples folder.AutoItObject package.Just place it together with AutoItObject.au3 into the script's folder. Edited April 14, 2011 by trancexx ♡♡♡ . eMyvnE
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