Visual Basic conditional statement, is there anything wrong with this?

I have type this conditional statement in visual basic but there are problems:

If scheduleDate.DayOfWeek = 6 _

Or scheduleDate.DayOfWeek = 0 _

Or scheduleDate = #7/1/2011# _

And scheduleDate >= #8/1/2011# _

Or scheduleDate <= #8/31/2011# Then

Action

End If

The conditional statement I am stating says that if the scheduled date is saturday or sunday or PH is true and between 1st of August and 31st of August is true then do an action. End If otherwise

However, even if I the scheduled date is Monday or any other weekday, the action still takes place. Can someone suggest what may be the problem? Is it because I have more than one condition?

Comments

  • Use brackets for clarification

    So try

    If (scheduleDate.DayOfWeek = 6 _

    Or scheduleDate.DayOfWeek = 0)_

    And (scheduleDate >= #8/1/2011# _

    And scheduleDate <= #8/31/2011#) _

    Or scheduleDate = #7/1/2011# Then

    Have fun.

  • Programming stuff wherein the respond relies upon upon a quantity of interlinked variables is consistently slightly of an artwork. i don't understand VB and this looks too diverse to understand completely notwithstanding VB maximum possibly has a "case assertion" form of creation as stable and those can oftentimes be better than an prolonged sequence of if/else variety statements. As a representative i'm going to have a bent to seek for wherein think ofyou've have been given variables which could be standard over all distinctive (or lots) stipulations and charm those out those first. And in a matching way there'll probable be distinctive stuff that best applies to unique stipulations, so try this very final while you already know what the location are and best do it if youin case you need to. greater often than not you adjust into with 3 or 4 layers of nested if/else and case statements and that's agreeable. yet yet yet another way is to get your variables first and then decode them in each and each possible significant combination as a flat sequence of ifs and don't attempt to minimise the decoding. only remember to seize the location whilst no longer between the ifs get used.

Sign In or Register to comment.