473,396 Members | 2,139 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,396 software developers and data experts.

Using the And function

I would like a message box to display if one of my reception staff tries to check a customer in on a Monday or a Thursday between 15:30 and 17:30.

So I typed my times into excel and formatted the cell as a number to see how it was stored and then used those numbers in the following hoping that if it worked for one day I could simply add another if statement for the other day;

If Weekday(Date) =6 And Time() > 0.645833333333333 And Time() < 0.729166666666667 Then

Msgbox “Blah”

It doesn’t work. Any 2 of the 3 variables work but when I add the third I get nothing. I am guessing that you can’t use 3 variables in an and statement so I am hoping that somebody can point me in the right direction.

Thanks
Jan 14 '11 #1
9 2203
ADezii
8,834 Expert 8TB
Hopefully, the following will point you in the right direction:
Expand|Select|Wrap|Line Numbers
  1. Dim dteDate As Date
  2. Dim dteTime As Date
  3.  
  4. 'Will evaluate to True
  5. dteDate = #1/17/2011#           'Monday
  6. dteTime = #4:27:00 PM#          'Within Range (3:30 P.M. - 5:30 P.M.
  7.  
  8. 'Will NOT evaluate to True (Out of Range by 1 Minute, Date OK)
  9. 'dteDate = #1/13/2011#           'Thursday
  10. 'dteTime = #3:29:00 PM#          '1 minute < Lower Range Boundary
  11.  
  12.  
  13. If (Weekday(dteDate) = 2 Or Weekday(dteDate) = 5) And _
  14.    (dteTime >= #3:30:00 PM# And dteTime <= #5:30:00 PM#) Then
  15.   MsgBox "Monday or Thursday between 3:30 P.M. and 5:30 P.M."
  16. Else
  17.   MsgBox "Date and/or Time out of Range!"
  18. End If
Jan 14 '11 #2
Thanks for your reply. I can't work out why, but the above code always evaluates to NOT true and so the out of range msgbox is displayed? It is Monday today and I have set the first time variable (on line 14.) to 11:30 AM to ensure that the current time (1:45 pm) is in range to test everything. Am I being daft and missing something?

Thanks
Jan 17 '11 #3
ADezii
8,834 Expert 8TB
Post the Code so we can see exactly what is going on.
Jan 17 '11 #4
Hi ADezil and thanks for your help on this. I am using the code exactly as you posted it except that I quoted out lines 5 and 6 (Although I tried with the lines in). I am using it in the on update event of a textbox So it looks like this..

Private Sub Text188_AfterUpdate()

Dim dteDate As Date
Dim dteTime As Date

'Will evaluate to True
'dteDate = #1/17/2011# 'Monday
'dteTime = #4:27:00 PM# 'Within Range (3:30 P.M. - 5:30 P.M.

'Will NOT evaluate to True (Out of Range by 1 Minute, Date OK)
'dteDate = #1/13/2011# 'Thursday
'dteTime = #3:29:00 PM# '1 minute < Lower Range Boundary


If (Weekday(dteDate) = 2 Or Weekday(dteDate) = 5) And _
(dteTime > #11:30:00 AM# And dteTime < #5:30:00 PM#) Then
MsgBox "Monday or Thursday between 3:30 P.M. and 5:30 P.M."
Else
MsgBox "Date and/or Time out of Range!"
End If

End Sub
Jan 17 '11 #5
ADezii
8,834 Expert 8TB
Is Text188 a Text Box containing a Date Value?
Jan 17 '11 #6
Sorry I should have explained that bit. text188 is just a box I added to see if I could get this bit of code working before integrating it with my booking system. I am using its onupdate event as a means of testing my code easily. The box contains no relevant information and in the finished database will not be there.
Jan 18 '11 #7
ADezii
8,834 Expert 8TB
If you quoted out Lines 5 and 6 in Post #2, Date and Time Values for comparison would be non-existent.
Jan 18 '11 #8
I tried the code exactly as posted and then quoted out those lines to see if it made any difference. With the lines in, the code always evaluates to true. Quoted out it always evaluates to Not True.
Jan 19 '11 #9
ADezii
8,834 Expert 8TB
You must vary either the Date or Time in order to achieve different results.
Jan 19 '11 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Lenard Lindstrom | last post by:
I was wondering if anyone has suggested having Python determine a method's kind from its first parameter. 'self' is a de facto reserved word; 'cls' is a good indicator of a class method ( __new__...
1
by: pvdm | last post by:
Hi, I am writing an app which encapsulates a multimedia timer. I implemented a TimerProc as static member function and a static member variable pThis as pseudo this variable to access in the...
9
by: Fred H | last post by:
I'm currently trying to write a function template that can fill a variable of arbitrary type with 'random' stuff, but I can't seem to get my function template working. In my .h file I've...
16
by: WittyGuy | last post by:
Hi, What is the major difference between function overloading and function templates? Thanks! http://www.gotw.ca/resources/clcm.htm for info about ]
19
by: golson | last post by:
I have written a C function to copy a flash write routine that is in Flash memory to RAM memory. I have then created a function that uses a Function Pointer to run the copied function in RAM. ...
1
by: Mike | last post by:
In C, we can typedef pointer to functions, and therefore use function tables. But what's the advantage of using function table? Thanks, Mike
2
by: Newbie | last post by:
Could someone help: I have been searching the web trying to figure out a way to use function key's in my vb.net 2003 program (No luck!). What I would like to do is enable the user to press (for...
22
by: Daniel Rucareanu | last post by:
I have the following script: function Test(){} Test.F = function(){} Test.F.FF = function(){} Test.F.FF.FFF = function(){} Test.F.FF.FFF.FFFF = function(){} //var alias = function(){}; var...
3
by: drsantosh82 | last post by:
Hi, I am trying to implement a callback routine using function pointers. Basically, I am trying to avoid tying my callback invoking member to a particular class. Let me explain my problem...
2
by: nikhizumi | last post by:
advantages of using FUNCTION in C++
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.