Re: Format$() Function
From: Randy Birch (rgb_removethis_at_mvps.org)
Date: 01/16/05
- Next message: Randy Birch: "Re: 25 textboxes on form - same code"
- Previous message: Ralph: "Re: On-line reference for controls and methods for EXCEL in VB"
- In reply to: Jerry West: "Format$() Function"
- Next in thread: Ralph: "Re: Format$() Function"
- Reply: Ralph: "Re: Format$() Function"
- Reply: Rick Rothstein: "Re: Format$() Function"
- Messages sorted by: [ date ] [ thread ]
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 : :
- Next message: Randy Birch: "Re: 25 textboxes on form - same code"
- Previous message: Ralph: "Re: On-line reference for controls and methods for EXCEL in VB"
- In reply to: Jerry West: "Format$() Function"
- Next in thread: Ralph: "Re: Format$() Function"
- Reply: Ralph: "Re: Format$() Function"
- Reply: Rick Rothstein: "Re: Format$() Function"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|