473,320 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

moved from the wrong location


From: "WindAndWaves" <ac****@ngaru.com>
Subject: Re: why use a class module
Date: Wednesday, 26 May 2004 6:25 p.m.

this is my code that takes a while to run:

I have put in the checks, because some fields may not contain proper date
fields or what have you.
Function fsimdat(Optional VFRO1, Optional VUNT1, Optional VFRO2, Optional
VUNT2) As Byte
'works out whether or not two date periods coincide
'0 = do not coincide
'1 = coincide
'2 = error
on error GoTo err
'--------------------------------------
Dim Fro1 As Date
Dim Unt1 As Date
Dim Fro2 As Date
Dim Unt2 As Date
'--------------------------------------
If IsNull(VFRO1) = True Or IsDate(VFRO1) = False Then GoTo data_error
Else Fro1 = VFRO1
If IsNull(VUNT1) = True Or IsDate(VUNT1) = False Then GoTo data_error
Else Unt1 = VUNT1
If IsNull(VFRO2) = True Or IsDate(VFRO2) = False Then GoTo data_error
Else Fro2 = VFRO2
If IsNull(VUNT2) = True Or IsDate(VUNT2) = False Then GoTo data_error
Else Unt2 = VUNT2
If Fro1 > Unt1 Or Fro2 > Unt2 Then GoTo data_error
If Fro1 = Unt1 Then Unt1 = Unt1 + 1
If Fro2 = Unt2 Then Unt2 = Unt2 + 1
'----------------------------'----------------------------
fsimdat = 2
'----------------------------'----------------------------
'1: |----|
'2: |---|
If Unt2 < Fro1 Then GoTo UnCoinciDe
'----------------------------'----------------------------
'1: |----|
'2: |---|
If Unt1 < Fro2 Then GoTo UnCoinciDe
'----------------------------'----------------------------
'1: |----|
'2: |-------|
If Fro1 >= Fro2 And Unt1 <= Unt2 Then GoTo CoinciDe
'----------------------------'----------------------------
'1: |---------|
'2: |-------|
If Fro2 >= Fro1 And Unt2 <= Unt1 Then GoTo CoinciDe
'----------------------------'----------------------------
'1: |------|
'2: |-----|
If Fro1 >= Fro2 And Unt1 >= Unt2 Then GoTo CoinciDe
'----------------------------'----------------------------
'1: |----|
'2: |-----|
If Fro1 <= Fro2 And Unt1 <= Unt2 Then GoTo CoinciDe

data_error:
fsimdat = 3
xit:
Exit Function
CoinciDe:
fsimdat = 1
GoTo xit
UnCoinciDe:
fsimdat = 0
GoTo xit
err:
fsimdat = 2
Resume Next
End Function
---
Please immediately let us know (by phone or return email) if (a) this email
contains a virus
(b) you are not the intended recipient
(c) you consider this email to be spam.
We have done our utmost to make sure that
none of the above are applicable. THANK YOU
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.690 / Virus Database: 451 - Release Date: 22/05/2004


---
Please immediately let us know (by phone or return email) if (a) this email
contains a virus
(b) you are not the intended recipient
(c) you consider this email to be spam.
We have done our utmost to make sure that
none of the above are applicable. THANK YOU
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.690 / Virus Database: 451 - Release Date: 22/05/2004
---
Please immediately let us know (by phone or return email) if (a) this email
contains a virus
(b) you are not the intended recipient
(c) you consider this email to be spam.
We have done our utmost to make sure that
none of the above are applicable. THANK YOU
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.690 / Virus Database: 451 - Release Date: 22/05/2004
Nov 13 '05 #1
1 1210
You code is extremely confusing, but it seems like you're trying to
figure out if two date periods overlap.

All you need to check is whether the start or ending date of your
second period occur before the ending date of the first period.

Period 1
May 1, 2004 to May 4, 2004

Period 2
May 3, 2004 to May 10, 2004

Period 3
April 29, 2004 to May 2, 2004

All you need to check is whether either one of two conditions is
met:

Start2 is between Start1 and End1

OR

End2 is between Start1 and End1

So, what you need to test is a single conditional:

(Start2 >= Start1 And Start2 <= End1)
Or (End2 >= Start1 And Start2 <= End1)

This assumes that you know that of your four dates, two are starting
dates, and two are ending dates.

So, to wrap that in a Function:

Public Function CheckDateOverlap(Optional dteStart1 As Variant, _
Optional dteEnd1 As Variant, Optional dteStart2 As Variant, _
Optional dteEnd2 As Variant) As Integer
'0 = do not overlap
'1 = overlap
'2 = invalid input
Dim intOutput As Integer
Dim ysnResult As Boolean

If (IsMissing(dteStart1) Or IsMissing(dteStart1) _
Or IsMissing(dteStart1) Or IsMissing(dteStart1)) _
Or Not IsDate(dteStart1) Or Not IsDate(dteEnd1) _
Or Not IsDate(dteStart2) Or Not IsDate(dteEnd2)) Then
intOutput = 2
Else
intOutput = (dteStart2 >= dteStart1 And dteStart2 <= dteEnd1) _
Or (dteEnd2 >= dteStart1 And dteStart2 <= dteEnd1)
End If
CheckDateOverlap = Abs(intOutput)
End Function

You could add error handlers if you wanted, but I can't see what
could possibly go wrong here that would be a recoverable error.

If the dates are unordered, then you'd want to check them and put
them in ordered variables. If you're interested in that, I can add
that in a followup.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Eino Mäkitalo | last post by:
It seems that urrlib2 default redirection does not allow me to handle Cookies. Service I'm trying seems to use IP switcher and session id's with cookies. After successful login it changes session...
8
by: Brian Basquille | last post by:
Hello all, Bit of a change of pace now. As opposed to the typical questions regarding my Air Hockey game, am also working on a Photo Album which uses an Access Database to store information...
0
by: Miquel | last post by:
Hi all. I felt frustrated when developing an 'UserControl' derivated from textBox, because sequence event (and Validate event) seems to fail. I Always thought my code was wrong. But after...
3
by: Trista | last post by:
I moved my folder to another location on the same drive and now my form's scroll bars don't work. Please help! Thank you.
0
by: zxo102 | last post by:
Hi everyone, As shown in the code below (modified based on the Image.py in wxpython demo), an image is created at location 1: (50,10) with rotated angle 1.12. Now, suppose I got another set of...
3
by: Fast Eddie | last post by:
Hi, We have an old MS Access frontend application which has a SQL Server backend. Recently the SQL Server database used as the backend was moved to a new server. I have updated the server...
2
by: shanmugam1976 | last post by:
Hi all, I am shanmugam. i am new to perl cgi. i have one problem here. When i wants to redirect "confirmation.cgi" page using "print redirect ('confirmation.cgi');" but it instead of go to...
14
by: thiswatt | last post by:
I've found severally topics that are close to what I'm trying to do, but as a beginner with SQL, I haven't been able to apply them to my situation. I'm using Access 2002. It's an inventory...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.