Yashied Posted March 3, 2009 Posted March 3, 2009 Prompt please, is it possible using AutoIt define a function with a large number of parameters of the same type do not list them in the title of this feature.For example:MyFunc (value1, value2 [, value n])And how to obtain these parameters in the loop.If it is not possible, then why there is a macro @NumParams. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
Wus Posted March 3, 2009 Posted March 3, 2009 As a pretty irrelevant tidbit of info I'd like to say that this concept is typically called a "variable length argument list". It is present in Java by default and is present in c/c++ by some sort of include if I recall correctly. Google it to find out more. I am pretty sure AutoIT does not support it, but to be honest that isn't a big deal, just throw your arguments into an array and pass that instead. It's really a pretty unnecessary construct IMHO, though it can make code more concise at times.
Yashied Posted March 3, 2009 Author Posted March 3, 2009 (edited) I wanted to write a function like BitOR (). But to enumerate all the parameters is absurd. func Problem($v1, $v2, $v3, $v4, $v5, $v6, $v7, $v8, $v9, $v10, $v12, $v13, $v14, $v15, $v16, ..., $v255) :wacko: if $v1 = 0 then if $v2 = 0 then if $v3 = 0 then ... endfuncHow to use the @NumParams?Thanks. Edited March 3, 2009 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
BrettF Posted March 3, 2009 Posted March 3, 2009 Like Wus said, an array would be easiest. Global $aArr[5] $aArr[0] = "Something" $aArr[1] = "Goes" $aArr[2] = "Here" $aArr[3] = "Okay" $aArr[4] = "Good" _ParesParams ($aArr) Func _ParesParams ($aParams) $total = UBound ($aParams) MsgBox (0, "", "THere are " & $total & " params") EndFunc Cheers, Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
AdmiralAlkex Posted March 3, 2009 Posted March 3, 2009 As Wus said, AuotIt doesn't have any "variable length argument list", if you want to shorten the code use an array instead (that would also have the added benefit of being able to have 16 million parameters instead of 250) .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
Valik Posted March 3, 2009 Posted March 3, 2009 As a pretty irrelevant tidbit of info I'd like to say that this concept is typically called a "variable length argument list". It is present in Java by default and is present in c/c++ by some sort of include if I recall correctly. Google it to find out more. I am pretty sure AutoIT does not support it, but to be honest that isn't a big deal, just throw your arguments into an array and pass that instead. It's really a pretty unnecessary construct IMHO, though it can make code more concise at times.Technically it's supported natively. The header you refer to just provides some convenience macros so the programmer doesn't have to offset memory addresses manually.
Richard Robertson Posted March 3, 2009 Posted March 3, 2009 But offsetting memory addresses is so much more fun. I just wish C++ had a type safe variable argument list.
Yashied Posted March 3, 2009 Author Posted March 3, 2009 As Wus said, AuotIt doesn't have any "variable length argument list", if you want to shorten the code use an array instead (that would also have the added benefit of being able to have 16 million parameters instead of 250)The array is not the solution. In this case, can I pass a pointer and then get more than 16 million. I would like to obtain a compact and a nice function. Who can answer anything about the appointment @NumParams? My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
Valik Posted March 3, 2009 Posted March 3, 2009 (edited) But offsetting memory addresses is so much more fun. I just wish C++ had a type safe variable argument list.That is an oxymoron. You can't be type-safe if you don't know what you are expecting. If you do know what you are expecting then it doesn't need to be variable. If you need to accept a variable number of arguments of the same type, a vector or other container would be best. However, you could always roll your own using RTTI to verify the objects. The array is not the solution. In this case, can I pass a pointer and then get more than 16 million. I would like to obtain a compact and a nice function. Who can answer anything about the appointment @NumParams?It contains the number of parameters passed when optional parameters are used. What you are trying to do is not possible to do without using an array or explicitly declaring a function that takes 255 (mostly) optional parameters. With proper naming Eval() can be used to write short code but performance is going to suffer. Something like this would be a start: Func Test($v1 = 0, $v2 = 0, $v3 = 0, ..., $v255 = 0) For $i = 1 To @NumParams ConsoleWrite(Eval("v" & $i) & @CRLF) Next EndFunc Edited March 3, 2009 by Valik
Yashied Posted March 3, 2009 Author Posted March 3, 2009 (edited) Thank you for a short and simple answer, Valik. Edited March 3, 2009 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
Wus Posted March 3, 2009 Posted March 3, 2009 Technically it's supported natively. The header you refer to just provides some convenience macros so the programmer doesn't have to offset memory addresses manually.Hmm, thanks for the info, I didn't know that. To be honest I've never really had the need to use variable length argument lists in c++. Now that I think on it a bit, the only place I have ever used variable length argument lists is for things like max functions, since it seems like you always need 2, 3, and 4 argument versions and variable length argument lists are the most terse way of doing it as far as I know.
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