golfjrr Posted November 5, 2004 Posted November 5, 2004 I know this should be simple but alas.. I have a field of say minutes that is 5 but want to force it to be displayed in a string like 03:05:44 with the padded zeros. Now it is showing like 3:5:44. How do I do that in autoit? I basicall have separate fields for hours, minutes and seconds, and concat them together hh:mi:ss but of course don't get the leading zeros. The stringformat command has gotta be the most counterintuative/confusing way to format things I have ever seen in my 30+ years of programming..
Josbe Posted November 5, 2004 Posted November 5, 2004 (edited) An easy alternative:If your string it's joined by 3 variables, you could apply a If.Example:$var= 10 If $var < 10 Then $var= '0' & $var Msgbox(0, "", $var) Edited November 5, 2004 by josbe AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta
Developers Jos Posted November 5, 2004 Developers Posted November 5, 2004 (edited) StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs) Edited November 5, 2004 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
golfjrr Posted November 5, 2004 Author Posted November 5, 2004 StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)<{POST_SNAPBACK}>Thank you. I knew it should be simple. I'm not a c programmer and I guess that function/format is taken more from a c function thus it was greek to me. To a c programmer no doubt trival
Josbe Posted November 5, 2004 Posted November 5, 2004 StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)<{POST_SNAPBACK}>Very well, teacher... AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta
Administrators Jon Posted November 5, 2004 Administrators Posted November 5, 2004 Or you could add a zero to the start regardless of the number and then just do stringright $var = 1 $var = StringRight("0" & $var, 2) MsgBox(0, "", $var) Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/
Josbe Posted November 5, 2004 Posted November 5, 2004 Or you could add a zero to the start regardless of the number and then just do stringright $var = 1 $var = StringRight("0" & $var, 2) MsgBox(0, "", $var)<{POST_SNAPBACK}>Ingenious. AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta
ezzetabi Posted November 6, 2004 Posted November 6, 2004 Even an other idea... $digits = 3;the number of max digits while stringlen($var) < $digits $var = '0' & $var wend
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