iNFERiON Posted February 25, 2007 Posted February 25, 2007 (edited) Hey everybody, I'm having a problem with a counter script I'm creating. It's a counter that counts down a given time. Now, it works OK, except for 1 small annoying thing. If a number gets below 10, it doesn't have a leading zero, which I would like. For example, a counter I would like for 10 minutes (and 0 hours): 00:00:00 What it gives me: 0:0:0 I've tried using an array search and paste a "0" as a string in front of it (after conversion) but to no avail... Any clues ? Here's my code so far. $time_hrs = Int(ControlGetText("","",$hrs)) $time_min = Int(ControlGetText("","",$min)) $time_sec = Int(ControlGetText("","",$sec)) Dim $int_time[10] $int_time[0] = "0" $int_time[1] = "1" $int_time[2] = "2" $int_time[3] = "3" $int_time[4] = "4" $int_time[5] = "5" $int_time[6] = "6" $int_time[7] = "7" $int_time[8] = "8" $int_time[9] = "9" (...) $show_hrs = String($time_hrs) $show_min = String($time_min) $show_sec = String($time_sec) $search_hrs = _ArraySearch($int_time,$time_hrs) If Not $search_hrs = -1 Then $show_hrs = String("0" & $search_hrs) EndIf $search_min = _ArraySearch($int_time,$time_min) If Not $search_min = -1 Then $show_min = String("0" & $search_min) EndIf $search_sec = _ArraySearch($int_time,$time_sec) If Not $search_sec = -1 Then $show_sec = String("0" & $search_sec) EndIf Edited February 25, 2007 by iNFERiON
iNFERiON Posted February 25, 2007 Author Posted February 25, 2007 Hmm, this seems to work. But I just have a feeling there has got to be an easier way. $search_hrs = _ArraySearch($int_time,$time_hrs) If $search_hrs = 0 Or $search_hrs = 1 Or $search_hrs = 2 Or $search_hrs = 3 Or $search_hrs = 4 Or $search_hrs = 5 Or $search_hrs = 6 Or $search_hrs = 7 Or $search_hrs = 8 Or $search_hrs = 9 Then $show_hrs = String("0" & $search_hrs) EndIf $search_min = _ArraySearch($int_time,$time_min) If $search_min = 0 Or $search_min = 1 Or $search_min = 2 Or $search_min = 3 Or $search_min = 4 Or $search_min = 5 Or $search_min = 6 Or $search_min = 7 Or $search_min = 8 Or $search_min = 9 Then $show_min = String("0" & $search_min) EndIf $search_sec = _ArraySearch($int_time,$time_sec) If $search_sec = 0 Or $search_sec = 1 Or $search_sec = 2 Or $search_sec = 3 Or $search_sec = 4 Or $search_sec = 5 Or $search_sec = 6 Or $search_sec = 7 Or $search_sec = 8 Or $search_sec = 9 Then $show_sec = String("0" & $search_sec) EndIf
The Kandie Man Posted February 25, 2007 Posted February 25, 2007 You use an if statement to check the value of that field. If the value is less than 10, you know to append a 0 in front of the string. Something like this: Local $min = 5 If $min < 10 Then $min = "0" & $min Endif "So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire
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