Home All Groups Group Topic Archive Search About
Author
1 Feb 2006 6:05 PM
Buc
Can someone help me on a format problem. I am trying to do this..
format a string to a number. The string has a number with a colon in the
middle.

Format("1:30","00:00")
returns 00:00 instead of 01:30

How can this be done?

Thanks
BUC

Author
1 Feb 2006 5:23 PM
Armin Zingler
<Buc> schrieb
> Can someone help me on a format problem. I am trying to do this..
> format a string to a number. The string has a number with a colon in
> the middle.
>
> Format("1:30","00:00")
> returns 00:00 instead of 01:30
>
> How can this be done?

"00:00" is not a valid format string for formatting strings. You already
have a string.

See also:
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconworkingwithbasetypes.asp



Armin
Author
2 Feb 2006 4:38 AM
Tom McL.
Dim s As Date = "1:30"

Dim myTime As String

myTime = Format(s, "HH:mm")
Author
2 Feb 2006 9:49 AM
Armin Zingler
"Tom McL." <tb***@cwnet.com> schrieb
> Dim s As Date = "1:30"

This doesn't compile. You can not assign a String to a Date variable.
Switching Option Strict Off creates the risk of overlooking unintended
implicit conversions.

> Dim myTime As String
>
> myTime = Format(s, "HH:mm")


Armin
Author
2 Feb 2006 11:58 AM
Phill W.
<Buc> wrote in message news:%2335SpG1JGHA.1760@TK2MSFTNGP10.phx.gbl...
> I am trying to do this.. format a string to a number. The string has a
> number with a colon in the middle.

> Format("1:30","00:00")

No you're not.  You're trying to format a String into a String
and "0" /isn't/ a valid formatting character when formatting a String
("@" is the only one I can think of).

Try this:

Format( CDate( "1:30" ),"00:00" )

Now that's taking a String, converting (CDate'ing) it to a Date, then
formatting /that/ back into a string again, using the formatting rules for
Dates and Times, as you'd expect.

Or, better still, since you're working in VB.Net

CDate( "1:30" ).ToString( "00:00" )

(OK, there's "better" ways of converting a string to a Date, but it's
the "new" way of /formatting/ I'm trying to show).  :-)

HTH,
    Phill  W.
Author
2 Feb 2006 9:02 PM
Tim Ferguson
<Buc> wrote in news:#35SpG1JGHA.1760@TK2MSFTNGP10.phx.gbl:

> Format("1:30","00:00")
> returns 00:00 instead of 01:30
>
> How can this be done?

I still learning the dotNet way of doing this, but the old fashioned

  Right("00" & someTimeString, 5)

would seem to get the right answer.


Tim F