Stuart McLachlan
stuart at lexacorp.com.pg
Thu Feb 12 22:43:11 CST 2004
On 13 Feb 2004 at 13:57, Stuart McLachlan wrote: > On 12 Feb 2004 at 22:47, John W. Colby wrote: > > > Well... I was really hoping for a "check writer" kind of interpretation, > > Three minutes and fifty one seconds. > > OK, I dug up my cheque writer code and did a quick and dirty modification of it. Note that it won't like it if you try to feed it more than about 190 years worth of seconds (99,999,999 minutes worth actually <g>) Here it is (watch for wordwraps): Function teenword(amount As Long) As String Dim unitname(9) As String unitname(2) = "Twenty" unitname(3) = "Thirty" unitname(4) = "Forty" unitname(5) = "Fifty" unitname(6) = "Sixty" unitname(7) = "Seventy" unitname(8) = "Eighty" unitname(9) = "Ninety" teenword = unitname(amount) End Function Function unitword(amount As Long) As String Dim unitname(19) As String unitname(1) = "One" unitname(2) = "Two" unitname(3) = "Three" unitname(4) = "Four" unitname(5) = "Five" unitname(6) = "Six" unitname(7) = "Seven" unitname(8) = "Eight" unitname(9) = "Nine" unitname(10) = "Ten" unitname(11) = "Eleven" unitname(12) = "Twelve" unitname(13) = "Thirteen" unitname(14) = "Fourteen" unitname(15) = "Fifteen" unitname(16) = "Sixteen" unitname(17) = "Seventeen" unitname(18) = "Eighteen" unitname(19) = "Nineteen" unitword = unitname(amount) End Function Function TimeWords(Seconds As Long) As String f Seconds = 0 Then TimeWords = "Nothing": Exit Function Dim Minutes As Long Dim millions As Long Dim hundredthousands As Long Dim thousands As Long Dim hundreds As Long Dim tens As Long Dim unit As Long Dim strTime As String Minutes = Seconds \ 60 Seconds = Seconds - (Minutes * 60) thousands = Int(Minutes / 1000) millions = Int(Minutes / 1000000) hundredthousands = Int((Minutes - (millions * 1000000)) / 100000) thousands = Int((Minutes - (millions * 1000000) - (hundredthousands * 100000)) / 1000) hundreds = Int((Minutes - (millions * 1000000) - (hundredthousands * 100000) - (thousands * 1000)) / 100) unit = Minutes - (millions * 1000000) - (hundredthousands * 100000) - thousands * 1000 - hundreds * 100 If Minutes = 0 Then strTime = "Zero" Select Case millions Case 1 To 19 strTime = unitword(millions) & " Million" Case 20 To 99 strTime = Trim$(teenword(Int(millions / 10)) & " " & unitword(millions - Int(millions / 10) * 10)) & " Million" Case Is > 99 TimeWords = "100 million minutes or more" Exit Function End Select Select Case hundredthousands Case 1 To 9 strTime = strTime & " " & unitword(hundredthousands) & " Hundred" End Select Select Case thousands Case 0 If hundredthousands > 0 Then strTime = strTime & " Thousand" Case 1 To 19 strTime = strTime & " " & unitword(thousands) & " Thousand" Case 20 To 99 strTime = strTime & " " & Trim$(teenword(Int(thousands / 10)) & " " & unitword(thousands - Int(thousands / 10) * 10)) & " Thousand" End Select Select Case hundreds Case 1 To 9 strTime = strTime & " " & unitword(hundreds) & " Hundred" End Select If (millions + hundredthousands + thousands + hundreds) > 0 Then strTime = strTime & " and" Select Case unit Case 1 To 19 strTime = strTime & " " & unitword(unit) Case 20 To 99 strTime = strTime & " " & Trim$(teenword(Int(unit / 10)) & " " & unitword(unit - Int(unit / 10) * 10)) End Select strTime = strTime & " Minute" If Minutes <> 1 Then strTime = strTime & "s" Select Case Seconds Case 0 strTime = strTime & " Exactly" Case 1 strTime = strTime & " and " & unitword(Seconds) & " Second" Case 2 To 19 strTime = strTime & " and " & unitword(Seconds) & " Seconds" Case 20 To 59 strTime = strTime & " and " & Trim$(teenword(Int(Seconds / 10)) & " " & unitword(Seconds - Int(Seconds / 10) * 10)) & " Seconds" End Select TimeWords = strTime End Function -- Stuart McLachlan Lexacorp Ltd Application Development, IT Consultancy http://www.lexacorp.com.pg