Newbie DateTime woes

N

News

Hi

I am using Visual Basic v5 Express (fully up-to-date for Vista), running on
a Vista machine.

I am having a terrible time trying to get to grips with DateTime use in VB.

I have tried countless code snippets as a starting point, but in *all*
cases, the code just bombs.

As an example, I copied the snippet below from a Microsoft page which is
supposed to show an example of 'fixing'
some bad code given in the example prior to it - yet with me, it just plain
doesn't work.

The most common error I get from most of my trials, and with the example
below is:

'Index was outside the bounds of the array'.


Example snippet:

Dim d As DateTime
d = DateTime.Parse("Dec 03, 2003 12:00:00 PM").ToUniversalTime()

I just can't find an example that actually works on my system that allows me
to use a string representation of a Date and Time that I can use in code.

There isn't anything wrong with my system as many other VB programs run just
fine.
 
C

Chris Dunaway

Hi

I am using Visual Basic v5 Express (fully up-to-date for Vista), running on
a Vista machine.

I am having a terrible time trying to get to grips with DateTime use in VB.

I have tried countless code snippets as a starting point, but in *all*
cases, the code just bombs.

As an example, I copied the snippet below from a Microsoft page which is
supposed to show an example of 'fixing'
some bad code given in the example prior to it - yet with me, it just plain
doesn't work.

The most common error I get from most of my trials, and with the example
below is:

'Index was outside the bounds of the array'.

Example snippet:

Dim d As DateTime
d = DateTime.Parse("Dec 03, 2003 12:00:00 PM").ToUniversalTime()

I just can't find an example that actually works on my system that allows me
to use a string representation of a Date and Time that I can use in code.

There isn't anything wrong with my system as many other VB programs run just
fine.

That code runs without error for me. Can you show a complete program
which exhibits your problem? Also, are you in a different locale than
The United States? Perhaps that format is not correct for your
locale.

If the locale is not the problem, please post a complete example that
illustrates the problem.

Chris
 
N

News

Chris Dunaway said:
That code runs without error for me. Can you show a complete program
which exhibits your problem? Also, are you in a different locale than
The United States? Perhaps that format is not correct for your
locale.

If the locale is not the problem, please post a complete example that
illustrates the problem.

Chris

Hi Chris

Although I have progressed quite far into my project, there isn't anything
pertinent in it so far - I am just trying to get my head around the DateTime
thing before starting to implement.

My location is the UK. I have the International settings for English (UK)
with dd/MM/yy dd MMMM yyyy H:mm:ss for date time formats.

In VB Options->International Settings I have tried both 'Same as Windows'
and 'English'.


In the meantime, I have had a little progress - I can get the following
snippet to run but the output in aDateString and aTimeString is unexpected.
Instead of day/month/year I get month/day/year? There is nothing I know of
on my system to set the U.S. format for dates! Also, the time is given in
12hour with AM/PM instead of 24hour clock that I need.

Dim aDateString, aTimeString As String
Dim aDate, aTime As Date
aDateString = "17/7/07"
aTimeString = "14:35:47"
' The following line of code sets aDate to a Date value.
aDate = CDate(aDateString)
' The following line of code sets aTime to Date value.
aTime = CDate(aTimeString)

I know this example isn't quite the same as the original example I quoted
(which still won't run), but I'm sort of glad I can get something to
recognize dates/times within VB :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top