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.
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.
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.
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"
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.
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
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.