Format Problems

  • Thread starter Thread starter Armin Zingler
  • Start date Start date
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
 
Tom McL. said:
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
 
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.
 
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
 
Back
Top