Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-27-2017, 04:21 PM
Larry_1 Larry_1 is offline I don't understand event handling for the DoubleClick event Windows 10 I don't understand event handling for the DoubleClick event Office 2010 64bit
Novice
I don't understand event handling for the DoubleClick event
 
Join Date: Dec 2017
Posts: 9
Larry_1 is on a distinguished road
Default I don't understand event handling for the DoubleClick event


I'm slowly getting more comfortable with VBA, but I frequently don't understand the logic in sample code that I find on the net. My present problem is understanding the event handling for a double click event.

The upper code is how I edited the sample code (which is commented out). Both seem to function the same.

I understand the logic in my edited version, but not the logic in the sample:
If the intercept is Nothing, doesn't that mean that target cell is not within the designated range? So why the "Not"?
Why did the sample's author use the Not logic (I found a number of postings with this logic); does it have an advantage over my edited logic?
I'd sincerely appreciate any comments that you can offer.

Very respectfully,
Larry

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    ' If the cell is not within the range B1:B10, then cancel
    ' If the cell is within the range, then act
    If Application.Intersect(Target, Range("B1:B10")) Is Nothing Then
        MsgBox ("is NOT in B1:B10")     '  Action for out-of-range target
        Cancel = True
        Else: MsgBox ("is in B1:B10")   '  Action if target is within the range
    End If
        
  '  Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  '  If Not Application.Intersect(Target, Range("C40")) Is Nothing Then
  '      Cancel = True
  '      SelectPayFreq.Show
  '  End If
  '  End Sub

End Sub
Reply With Quote
  #2  
Old 12-27-2017, 04:32 PM
Logit Logit is offline I don't understand event handling for the DoubleClick event Windows 10 I don't understand event handling for the DoubleClick event Office 2007
Expert
 
Join Date: Jan 2017
Posts: 529
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

This means that the Range B1:B10 is blank / empty / does not have data :

Code:
If Application.Intersect(Target, Range("B1:B10")) Is Nothing Then

This means that the Range C40 has data / is not empty / is not blank :

Code:
If Not Application.Intersect(Target, Range("C40")) Is Nothing Then

When you see two negatives "Not" / "is Nothing" .. think in terms of your High School Algebra : Two Negatives make a positive.
Reply With Quote
  #3  
Old 12-27-2017, 06:07 PM
Larry_1 Larry_1 is offline I don't understand event handling for the DoubleClick event Windows 10 I don't understand event handling for the DoubleClick event Office 2010 64bit
Novice
I don't understand event handling for the DoubleClick event
 
Join Date: Dec 2017
Posts: 9
Larry_1 is on a distinguished road
Default

Thank you, Logit. That makes sense, but the approach seems to go around the barn unnecessarily. Yet that double negative logic was in all of the on-line samples that I found. Is there an advantage to it?

Larry
Reply With Quote
  #4  
Old 12-27-2017, 07:30 PM
Logit Logit is offline I don't understand event handling for the DoubleClick event Windows 10 I don't understand event handling for the DoubleClick event Office 2007
Expert
 
Join Date: Jan 2017
Posts: 529
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

.
"Is there an advantage to it ? "

I can't answer that question ... I'm not an expert programmer. It's a hobby that I take seriously. (Is that bad ?)

One advantage I understand is :

If you have code that basically says, "Range("A1"A12").Value = "XYZ", then the logic to that is Range("A1"A12").Value ALWAYS must equal "XYZ" for the remainder of the line of code to work correctly.

Now, if you use, "If Not Range("A1:A12").Value is Nothing Then" ... The Values in the stated range can be anything. The code has not restricted the value to always be XYZ in order for it to work.

I'm retired now but I still recall being in High School Algebra and wondering how that gobble-d-goop was ever going to be useful. It wasn't until I began hobby programming that I finally understood a use for variables, less than, greater than, equals, double negatives, etc. etc.

Most of the time I'm still as confused as I was 50 years ago !
Reply With Quote
  #5  
Old 12-28-2017, 02:38 AM
Larry_1 Larry_1 is offline I don't understand event handling for the DoubleClick event Windows 10 I don't understand event handling for the DoubleClick event Office 2010 64bit
Novice
I don't understand event handling for the DoubleClick event
 
Join Date: Dec 2017
Posts: 9
Larry_1 is on a distinguished road
Default

Logit,

It sounds like we're in very similar circumstances, but you're well up the learning curve from me.

I'd not thought of the cells' contents, and your logic would need to be considered for a test on the contents. But my understanding of the Intersect function is that it's only testing to see if the ranges have any cells in common and that it does not look at their contents. If that's correct, then the advantage doesn't seem to apply.

Very respectfully,
Larry
Reply With Quote
  #6  
Old 12-28-2017, 08:23 AM
NoSparks NoSparks is offline I don't understand event handling for the DoubleClick event Windows 7 64bit I don't understand event handling for the DoubleClick event Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 831
NoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really nice
Default

You're right Larry, cell content has no relevance with regards to range intersection (nor with the double click event).

I'm not sure there is any advantage to using either other than personal consistency.
Is Nothing and Not Is Nothing give opposite answers for the same condition.
If one says True the other always says False and both will be right.

For this old retired guy it's easiest to think in one direction only.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Event planning cajos Project 3 03-26-2016 05:19 PM
calendar event not showing licinio Outlook 0 05-18-2015 05:27 AM
I don't understand event handling for the DoubleClick event Document_ContentControlBeforeDelete Event Tejas.T Word VBA 5 02-27-2015 08:01 PM
Hyperlinks in Calendar Event? komobu Outlook 0 07-16-2014 08:09 AM
I don't understand event handling for the DoubleClick event Create calendar event groegee Outlook 1 12-05-2011 09:56 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:07 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft