Re: Format$() Function

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

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: TOC is adding spaces that arent in Heading text
    ... If you're adding the colon manually, it should be added immediately after the number (assuming there's not a space following the number in the "Number format" box), but this brings up another possibility I did not mention before: although I don't have much experience with numbered headings in TOCs, I think the TOC may add a space or tab following the number. ... This would allow you to have a style with just the numbering and another style with just the title. ...
    (microsoft.public.word.pagelayout)
  • 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: Syntax to combine MID() and FIND("LastPost:") to extract the Last
    ... the colon can be returned with the InstrRev function and subtract that from ... double quotes to change the format to any valid date format. ... Dim sht As Worksheet ...
    (microsoft.public.excel.programming)
  • 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)
  • 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)