Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #9  
Old 09-20-2013, 09:59 AM
BobBridges's Avatar
BobBridges BobBridges is offline VBA sort table code Windows 7 64bit VBA sort table code Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default

Actually, that's exactly how I'd describe a method: a function written by a programmer (or programming team), but for that object and for no other. That's where my assumptions used to lead me astray. For example: I had learned of a "method" (which I thought of as a VBA function) that I could use to determine whether a certain item exists in a Dictionary object:
Code:
Set od = CreateObject("Scripting.Dictionary")
' ...populate the Dictionary, then
If Not od.Exists("History") Then Abend "Missing History key."
Very good; that's useful. So later on I try to use this Exists "function" in other places in my program:
Code:
If Not ThisWorkbook.Worksheets.Exists("MySheet") Then...
...and I get an error: This object does not support this property or method.

For years that drove me crazy. Why could I use the Exists function one time and not another?! It wasn't until later—not until I finally wrote my own object, in fact—that I saw, very simply, that Exists was not a function of the VBA language, nor even a function of the Excel application, but a function of the Dictionary object. The folks who created the Dictionary object wrote an Exists method into it; but the folks who wrote the Worksheets collection in Excel did not—and a method exists only in the object it's written for.

Likewise, when you're adding an item to most Collections, the first argument for the Add method is the item you're adding and the second item is the optional key. But in a Dictionary's Add method, the first argument is the required key and the second is the contents. Different objects, different rules. Different subroutines, in fact, despite the fact that they have the same name.

It's my understanding that this is common to object-oriented programming, not specific to one language or environment or another. If this VFP thingy (is that Visual FoxPro?) had a great deal of consistency in the methods between various objects, it's probably because the architects decided to maintain an overall design philosophy rather than let each item be constructed from scratch.

I don't usually let it bother me, now. When I decided I wanted an Exists method for Collections, I went ahead and wrote it as a function and use it all the time, now.
Reply With Quote
 

Tags
range, sort, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook Combobox Sort Code lms Outlook 1 09-18-2013 09:56 AM
VBA sort table code How to Sort Table Cells from Left to Right tamaracklodge Word Tables 4 03-04-2013 04:00 AM
Sort table using macro saslotteroy Word VBA 2 09-15-2011 02:41 PM
VBA sort table code How to sort table having three columns? Bahir Barak Word 2 01-20-2011 01:52 PM
Can I sort a Pivot table by subtotals? oshkosh Excel 1 12-07-2010 06:20 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:57 AM.


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