CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2008
    Posts
    12

    [Urgent] Timing Allocation Problem

    Lets say i do this to count the number of that particular hour:
    Code:
    If vDateTime.Hour > 0 And vDateTime.Hour < 24 Then
                            Dim hour As Integer = vDateTime.Hour
                            If hour = 0 Then
                                hour = 24
                            End If
    count(hour, 0) = count(hour, 0) + 1
    Refer to the data below:
    1.2008/06/24 02:00
    2.2008/06/24 12:00
    3.2008/06/24 06:00
    4.2008/06/24 17:00
    5.2008/06/25 06:00
    The first will be allocated to hour=02 and the second one will go to hour=12.
    However i face this problem: How if 3 and 5 having the same hour but different date? I need to get the date as well. Can i solve this problem using almost the same coding format above? I need to keep count(hour, 0) = count(hour, 0) + 1 this way. Thanks a lot.

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: [Urgent] Timing Allocation Problem

    You should always parse the date, rather than the hour, but you can also use DAY()

    http://msconline.maconstate.edu/tuto...bnet01-07.aspx
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jan 2008
    Posts
    12

    Re: [Urgent] Timing Allocation Problem

    Now i already simplify my coding to the format below:
    I need to allocate the 24-hour time selected by the user to an array of size 24, for example, If the user choose 2day 8AM until tomorrow 7AM, Then my idea is:
    hourarray(0)=8AM
    hourarray(1)=9AM.....
    ..hourarray(23)=7AM...
    How can i loop it? Thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: [Urgent] Timing Allocation Problem

    your fields ahould be date/time. you can use a function to change it to hour minute or second
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: [Urgent] Timing Allocation Problem

    Okay ..

    Look up DateDiff function.. and set up your code to do something alond the lines of ...

    1) Get start date and time..
    2) read in DATA ..(first/Next record)
    3) Compare data(2) to start date (1) and skip all data before start date (go back to 2)
    4) Get the Datediff of data(2) date and start date(1)
    5) if Datediff day = 1 (more than 24 hours) go back to 2..
    6) do your count...

    Hope this Helps...

    Gremmy...
    6)
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  6. #6
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: [Urgent] Timing Allocation Problem

    Why VB6 style solutions in the VB.NET forum...

    Simply use DateTime and TimeSpan...problems all solved with no explicit parsing or even calculating....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured