Q: Hours

  • Thread starter Thread starter Geoff Jones
  • Start date Start date
G

Geoff Jones

Hi

I'm hoping that somebody can help me with the following question.

I have a DataView which contains a column which contains a Time.

I would like to create an array which will store the times within one hour.
For example, all the times between 12:00 and 13:00 will be placed in one
index of the array, all the calls from 13:00 to 14:00 will be placed in the
next.

Can anybody give me some code to do this?

Thanks in advance

Geoff
 
Geoff,
Just out of curiosity, why have you moved to the
microsoft.public.dotnet.languages.csharp newsgroup?

Do you really want this part in csharp or would you like VB.NET like the
rest has been?

Can you define a little better what "all the times between" means? Do you
mean all the DataRows that fall within that time frame or ever minute
(outside of the rows) that falls within that range?

Just curious
Jay
 
Hi Jay

VB has been put on hold for now. I'm trying to work on some C# now (oh joy!)
LOL

Sorry I didn't make the original post very clear. Suppose I have a list of
dates as follows:

15:02, 09:23, 14:34, 17:02, 15:45, etc.

These would be in order i.e. each one would have its own unique identifier
in terms of order e.g. 15:02 is 1, 09:23 is 2 etc.

I'd like to be able to create an array that would, for example, have:

index 0 having all the items in the list with times from 01:00 to 02:00 (but
not including)
index 1 having all the items in the list with times from from 02:00 to 03:00
(but not including)

etc.

Interested in hearing your thoughts

Geoff
 
Geoff said:
Hi

I'm hoping that somebody can help me with the following question.

I have a DataView which contains a column which contains a Time.

I would like to create an array which will store the times within one hour.
For example, all the times between 12:00 and 13:00 will be placed in one
index of the array, all the calls from 13:00 to 14:00 will be placed in the
next.

Can anybody give me some code to do this?

That is the simplest thing in the world.

Read an article or two and you'll have it.
 
Geoff,
I would use an array of arrays or an array of ArrayLists.

I would expect index 0 be from midnight to 1:00?

Then you can simply use the hour of the Time (DateTime.Hour) as your index,
and use ArrayList.Add to add the time to that row...

Hope this helps
Jay
 
That helps a lot. Thanks Jay

As you can gather, I'm very new to programming. Your help and others is
invaluable during my steep learning curve.

One question that occurs to me now how to tell the ListArray what values I
need to store. I know for an array this can be done as:

Dim x() As Integer

However, and forgive me if this is wrong, I set up an array of an ListArray
by

Dim y() As ListArray

but that doesn't say if it holds strings, doubles or integers etc.

Can you help?

Geoff
 
Geoff,
but that doesn't say if it holds strings, doubles or integers etc.
ArrayList holds objects, when you take a value out you need to cast the
value to the specific type you put in.

If you want strongly typed, either use pure arrays, either:

Dim y()() As DateTime ' Array of Arrays of DateTime

Dim x(,) As DateTime ' 2 dimensional

The "problem" with both of these is that both dimensions are "fixed",
System.Collections.ArrayList is dynamic, in that you can add elements to it.

If you want a strongly typed "ArrayList" you can inherit from
System.Collections.CollectionBase and create a strongly typed list.

NOTE: VS.NET 2005 (.NET 2.0) (Whidbey) due out sometime next year, will
support Generics so it will be easier to get an array of list of datetime...

Hope this helps
Jay

Geoff Jones said:
That helps a lot. Thanks Jay

As you can gather, I'm very new to programming. Your help and others is
invaluable during my steep learning curve.

One question that occurs to me now how to tell the ListArray what values I
need to store. I know for an array this can be done as:

Dim x() As Integer

However, and forgive me if this is wrong, I set up an array of an ListArray
by

Dim y() As ListArray

but that doesn't say if it holds strings, doubles or integers etc.

Can you help?

Geoff
<<snip>>
 
Jay

One final question

I've tried the following just to test a few ideas:

Dim x(10) As ArrayList

x(0).Add(7)

Debug.WriteLine(CInt(x(0).Item(0))

thinking that this would print the integer 7.

However, I get an exception i.e. Object reference not set to an instance of
an object

Hope you can help.

Geoff
 
Geoff,
Doh!

I forgot to mention you need to initialize each element of your array as
ArrayList is a reference type.

For index As Integer = 0 to 10
x(index) = New ArrayList()
Next

Hope this helps
Jay
 
Thanks Jay. It works a treat!

Geoff

Jay B. Harlow said:
Geoff,
Doh!

I forgot to mention you need to initialize each element of your array as
ArrayList is a reference type.

For index As Integer = 0 to 10
x(index) = New ArrayList()
Next

Hope this helps
Jay
 
Back
Top