piccaso Posted May 17, 2004 Share Posted May 17, 2004 So i wrote a little function to find 'free' temp Filenames func FileTempName ($dir,$ext) if $dir == "" Then $dir = @TempDir if FileExists($dir) == 0 Then $dir = @TempDir if StringRight($dir,1) <> '\' Then $dir = $dir & '\' if $ext == "" Then $ext="tmp" $timestamp = TimerStart() do $tempfile = filegetshortname($dir&Int(Random(10000000,99999999))&"."&$ext) if TimerStop($timestamp) > 2500 Then seterror(1) Return endif until FileExists($tempfile) == 0 Return $tempfile endfunc and i want $dir and $ext to be optional. is this possible? CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map Link to comment Share on other sites More sharing options...
pekster Posted May 17, 2004 Share Posted May 17, 2004 (edited) No, but you could pass an array to the function. Then do some array checking to see how many optional paramaters have been passed through the array. Something like Func OptionalParams($required, $required2, $optional) If UBound($optional) = 2 Then;2 vars passed through optional array ;do stuff ElseIf UBound($optional) = 0 Then;no vars passed through array ;do other stuff Else;general clause to catch bad input ;quit with some error message about bad paramaters EndIf EndFunc Edited to correct a typo in the code Edited May 17, 2004 by pekster [font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes. Link to comment Share on other sites More sharing options...
CyberSlug Posted May 17, 2004 Share Posted May 17, 2004 (edited) Optional paramters is a feature being discussed. Antother workaround is to use a single string parameter where variables are separated by a the pipe "|" symbol. I use pipe here since it is never allow in file names or paths. func FileTempName ($pipeSeparatedParams) Local $dir = "", $ext = "", $timestamp, $tempfile Local $params = StringSplit($pipeSeparatedParams, "|") If IsArray($params)Then If 1 = $params[0] Then $dir = $params[1] If 2 = $params[0] Then $ext = $params[2] EndIf ; rest of your code goes here P.S. You might consider using FileFindNextFile. Edited May 17, 2004 by CyberSlug Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
piccaso Posted May 17, 2004 Author Share Posted May 17, 2004 Still the goal remains unreachable... But i can call it by using FileTempName('','') anyway why shuld i consider using FileFindNextFile ? i dont get the point here thx for the nice support ( i think i will have to put this in my sig ) CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map Link to comment Share on other sites More sharing options...
trids Posted May 17, 2004 Share Posted May 17, 2004 Still the goal remains unreachable...Sluggie's pipe-delimited parameter list is a very sound workaround to simulate optional parameters Link to comment Share on other sites More sharing options...
piccaso Posted May 17, 2004 Author Share Posted May 17, 2004 you cant call the function without parameters -> Nothing inside the brackets, and this was my goal. Of corse The mentioned pipe workaround is a great idea CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map Link to comment Share on other sites More sharing options...
pekster Posted May 17, 2004 Share Posted May 17, 2004 Having the paramater be empty is not really that big of a problem. You could always do 'Function(0)' and have the function first test for a string (and exit if it doesn't get one, or whatever you need it to.) As long as you know that your function treats a non-string as no paramater it will work fine. Or use a blank string 'Function("")'. No need for the comma in your above example. [font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes. Link to comment Share on other sites More sharing options...
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