Results 1 to 6 of 6

Thread: [RESOLVED] Want a challenge? SoonestDateTime 2

  1. #1

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Resolved [RESOLVED] Want a challenge? SoonestDateTime 2

    I posted a similar question here:
    http://www.vbforums.com/showthread.php?t=539532
    But now I need something more robust.

    I've put together some controls for a user to input Shop Hours and days.
    It then formats the info into a string that can be stored in a DB.
    There's more code that can take the string and set the controls.
    Those parts are all working.

    Name:  StoreHrs.gif
Views: 128
Size:  21.1 KB

    Here are some of the strings it can produce,
    7 Days a Week, 24 hrs a day
    Mon - Fri, 8:00 AM To 6:00 PM
    Mon - Thu, 8:00 AM To 6:00 PM; Fri - Sat, 8:00 AM To 10:00 PM '''notice Sunday is closed
    Mon - Wed, 10:00 AM To 4:00 PM; Fri - Sat, 24 hrs a day '''notice Sun and Thu are closed

    Now I need a function that can take that date/time string and find the soonest time that the shop could be visited.
    The function would be sent the BizHrs string and the soonest time you would be available.
    It would return the soonest date/time that you could go there, i.e. a day and time of day when they'd be open.

    (Frankly, I've intimidated myself with this one )
    Edit: Removed the code, look below for the new upload
    Last edited by longwolf; Oct 24th, 2008 at 03:10 PM.

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Want a challenge? SoonestDateTime 2

    If you wanted to store it internally as a string (at the expense of storage) then you should have used XML... not only would it make data extraction (parsing) easier, it would also decouple the GUI implementation and will facilitate front-end changes such as shift to browser based clients. Functionality would also be easier to extend, e.g. data structure version tag, additional information (nodes), etc.

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Want a challenge? SoonestDateTime 2

    How about similar logic to the following:
    1. You know you are dealing with a week, 7 Days.

    2. If you have a 2D array (i.e., OpenDays(1 To 7, 0 To 1)) you can store the earliest time open in one of the lower dimensions & the latest in the other.
    For 24hrs on Sunday: OpenDays(1,0)=00:00, OpenDays(1,1)=23:59
    For Wed, 10A-4P: OpenDays(4,0)=10:00, OpenDays(4,1)=15:59
    etc

    3. Get the current date/time, and extract from it the weekday then see if the current time is between the min & max for that weekday. Example: If today was Wed, WeekDay(Date)=4. Check current time against OpenDays(4,0) and OpenDays(4,1).

    Recommendation: Don't assume days of week begin on Sunday. Recommend forcing the issue by using the optional parameter in the WeekDay function.
    Last edited by LaVolpe; Oct 23rd, 2008 at 07:47 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Want a challenge? SoonestDateTime 2

    Quote Originally Posted by leinad31
    you should have used XML...
    Thx,
    But this is only one small part of a large encrypted DB program that's 99% done.
    It has 26 tables and almost 2 mb of code.
    And I'm not about to re-write it now

    Of course you could save and load the 8 Dates and 4 Booleans in separate fields,
    but I'm not sure that would save enough space(compared one string field with a max length of 60) to make it worth the extra work.

  5. #5

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Want a challenge? SoonestDateTime 2

    Quote Originally Posted by LaVolpe
    How about similar logic to the following:
    2. If you have a 2D array .....
    I came to a similar idea myself. But I went with a UDT.
    Code:
    Public Type typHrs
        bOpen As Boolean
        Earliest As Date
        Latest As Date
    End Type
    
    Public tHrs() As typHrs
    Quote Originally Posted by LaVolpe
    Recommendation: Don't assume days of week begin on Sunday. Recommend forcing the issue by using the optional parameter in the WeekDay function.
    Thx, I would have missed that!

    All in all, it wasn't as bad as I though it would be.
    I'm uploading the working code.
    Try running the app and pasting this string into the txtBizHrs box.
    Code:
    Mon-Tue, 7:00 AM To 4:00 PM; Fri-Sun, 10:00 AM To 11:00 PM
    Then hit the 'To Controls' button.
    Next you can hit the 'Get Visit Time' button to see the second part work.

    What do y'all think, should I add this to the Code Bank?

    Edit: Removed the code, look below for the new upload
    Last edited by longwolf; Oct 24th, 2008 at 03:11 PM.

  6. #6

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: [RESOLVED] Want a challenge? SoonestDateTime 2

    Been playing with this an found that it need special handling for 'Bar Hours' like Fri 4PM to 2AM.

    Fixed that and also made a tweak for days set to '24 Hours'.
    But I'm not sure the 24Hr tweak covers things well.

    Fri-Sat, 24 hrs a day; Sun-Thu, 8:00 AM To 4:00 PM
    Attached Files Attached Files

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