Jump to content

using the if statement


greneebb

Recommended Posts

Good Day all,

I am using the if statement in VBA: If i

but the code in the if block executes even though the condition is not met.

 

Can anyone explain this situation

Link to comment
Share on other sites

Private Function CheckIfTime() As Boolean

' Determine the current day of week and hour of day.

Dim dayW As DayOfWeek = DateTime.Now.DayOfWeek

Dim hour As Integer = DateTime.Now.Hour

 

' Return True if Wednesday from 2 to 4 P.M.,

' or if Thursday from noon to 1 P.M.

If dayW = DayOfWeek.Wednesday Then

If hour = 14 Or hour = 15 Then

Return True

Else

Return False

End If

ElseIf dayW = DayOfWeek.Thursday Then

If hour = 12 Then

Return True

Else

Return False

End If

Else

Return False

End If

End Function

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...