Re: Format$() Function

From: Randy Birch (rgb_removethis_at_mvps.org)
Date: 01/16/05


Date: Sat, 15 Jan 2005 22:16:48 -0500

This works, albeit not pretty. The problem is that : is a special character
for date/time, so using it in the format expression causes VB to think
you're passing a valid time. This solution uses the decimal, then uses
Replace to change the decimal to a colon ...

Private Sub Command1_Click()

   Dim v As Single

   v = 42.574

   Label1.Caption = Replace$(Format$(v, "##0m.##s"), ".", ":")

End Sub

-- 
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
"Jerry West" <jwest@comcast.net> wrote in message 
news:10ujcakjb6mc137@news.supernews.com...
: I'm trying to set a label's caption property where it displays a minute 
and
: second value derived from GetTickCount. For example, after processing
: GetTickCount I may have a number like so 42.574
:
: I want that to display in the caption property as 42m:57s. I always want a 
0
: or higher for the minute value. I have tried using:
:
: Label1.Caption = Format$(siTime!, "##0m.##s")
:
: That will work except that I get a period separator versus a colon. If I 
try
: using a colon in the Format function I get the formatting wrong, i.e. 42 
is
: in the seconds versus minutes. I attempted several different things trying
: to get this to work. Finally I just processed it like the first example 
and
: then used the Replace function to replace the period with a colon. I know
: there must be an easier way, but how?
:
: JW
:
: 


Relevant Pages

  • Re: memory card formatter ??
    ... out the colon. ... So when i do it in WinXP, ... > format from within the mp3 player. ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: is there a quick easy way to input time?
    ... Click on Tools | Autocorrect and in the Replace box enter a full-stop ... and in the With box enter a colon, then click Add and then OK to close ... format may not show the seconds, but you change that by Format | Cells ...  How is military time input into a spreadsheet? ...
    (microsoft.public.excel.worksheet.functions)
  • Create custom text format?
    ... I'm trying to find and easy way to format a column of alphanumeric ... The problem is that our DHCP server expects these ethernet ... the data as 12 alphanumeric characters with no seperators. ... custom format that will just stick a colon after each 2 digits, ...
    (microsoft.public.excel.misc)
  • Re: Formating Time for calculation
    ... format the cell as ... spreadsheet. ... > I am having problems calculating time because when I import this text ... > Right now I have to add the zero in front of the colon manually. ...
    (microsoft.public.excel.programming)
  • Re: convert first 6 digits into date
    ... For Each SerialRng In SerialRng.cells ... > I did not know that the FORMAT function could do this, ... >>> 'You must compare Dates with Dates, ...
    (microsoft.public.excel.programming)