Coded4Decades Posted April 12, 2014 Posted April 12, 2014 I am converting some vbscript and vba programs to autoit and cannot find anything that is close to the vba Format(..) function. My current solution is to convert the code manually as follows vba====> filename = Format(Now, """file created in"" mmm ""at"" hh.mm.ss") autoit==> $filename = "file created in" & @mon & " at " & @hour & "." & @min & "." & @sec That works But, it would certainly simplify my conversion efforts if Autoit had something like Format which handles, dates, times am/pm, numbers, rounding, text percentages etc,
Danyfirex Posted April 12, 2014 Posted April 12, 2014 Maybe stringformat saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
Malkey Posted April 13, 2014 Posted April 13, 2014 .... But, it would certainly simplify my conversion efforts if Autoit had something like Format which handles, dates, times am/pm, numbers, rounding, text percentages etc, Also see StringFormat function and its examples in AutoIt help file. #include <Date.au3> Local $filename = StringFormat("file created in %02d at %02d.%02d.%02d", @MON, @HOUR, @MIN, @SEC) ConsoleWrite($filename & @LF) ;Or Local $filename2 = StringFormat("file created in %02d at %s", @MON, _NowTime(5)) ; _NowTime is one of the functions in "Date.au3" include file. ConsoleWrite($filename2 & @LF) ;Or Local $iNum = 12.3456 Local $Places = 3 ;Normally, a flag specification is not a variable concatenated inside a variable format, inside the "format control" ;parameter of the StringFormat function. ;That is, %." & $Places & "f" is equivalent to %.3f (see next line). Local $rounding = StringFormat("The number %g rounded to %d deciminal places %." & $Places & "f", $iNum, $Places, $iNum) ConsoleWrite($rounding & @LF) #cs Output:- file created in 04 at 08.23.07 file created in 04 at 08:23:07 The number 12.3456 rounded to 3 deciminal places 12.346 #ce
AdamUL Posted April 13, 2014 Posted April 13, 2014 Have a look at Melba23's >Date_Time_Convert UDF for converting dates and times. Adam
Solution Coded4Decades Posted April 15, 2014 Author Solution Posted April 15, 2014 #include <date.au3> global $xl ; make it global so I can add extra Excel functions easily in the future. $ans = _xltext(_now(),"mmm mm/dd/yyyy") MsgBox(262144, 'Debug line ~' & @ScriptLineNumber, 'Selection:' & @CRLF & ' $ans' & @CRLF & @CRLF & 'Return:' & @CRLF & $ans) ;### Debug MSGBOX func _xltext($value, $format) if $xl = "" then $xl= ObjCreate("Excel.Application") return $xl.worksheetfunction.text(_now(),"mmm mm/dd/yyyy") endfunc Thanks for the suggestions, but I'll probably not use either of them. stringformat looks useful and I may try it for other things, but it clearly does not handle date and times. date_time_convert udf has the type of data time functions I want, but it is a very complicated routine which kind of bothers me. I want the best of both worlds, so I decide to use Excel directly.
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