Results 1 to 16 of 16

Dictionary or Scripting.Dictionary. Binding Referencing Dim-ing. Sub routines and Function

Threaded View

Doc.AElstein Dictionary or... 07-12-2016, 04:48 AM
xlnitwit Re: Dictionary or... 07-12-2016, 05:49 AM
Doc.AElstein Re: Dictionary or... 07-12-2016, 07:37 AM
xlnitwit Re: Dictionary or... 07-12-2016, 05:58 AM
Doc.AElstein Re: Dictionary or... 07-12-2016, 07:38 AM
xlnitwit Re: Dictionary or... 07-12-2016, 07:54 AM
Doc.AElstein Re: Dictionary or... 07-12-2016, 08:00 AM
xlnitwit Re: Dictionary or... 07-12-2016, 06:01 AM
Doc.AElstein Re: Dictionary or... 07-12-2016, 07:39 AM
xlnitwit Re: Dictionary or... 07-12-2016, 06:06 AM
Doc.AElstein Re: Dictionary or... 07-12-2016, 07:39 AM
xlnitwit Re: Dictionary or... 07-12-2016, 07:58 AM
Doc.AElstein Re: Dictionary or... 07-12-2016, 08:15 AM
xlnitwit Re: Dictionary or... 07-12-2016, 08:02 AM
Doc.AElstein Re: Dictionary or... 07-12-2016, 08:28 AM
Doc.AElstein Re: Dictionary or... 07-12-2016, 07:49 AM
  1. #1
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Dictionary or Scripting.Dictionary. Binding Referencing Dim-ing. Sub routines and Function

    Help in understanding “Dictionaries in VBA”. General advice, Pros and Cons

    Hi, Just looking for some help to clear up a few things about “Dictionaries”
    Aka having Fun with my Fuking Dik Object...Lol .

    Question _1) A more specific Question. What is the difference between Dictionary and Scripting.Dictionary ? (If there is one, probably is not lol )

    To erlaberate: So I thought I knew what a Microsoft Scripting Runtime Dictionary ( MSRD) was and how to use it. ( Maybe I still do, lol.... **** ). I have used it quite a bit, mainly up to now by answering Threads using it as a way to learn about it.

    I have a file from an OP I am attempting to help. The Exact File origin is unknown ( No point asking the OP as I needed 6 month to teach him how to spell VBA in English and he has no idea.... about.... well anything I think, but he is nice, I like him lol... )
    It uses a “Dictionary” a lot, that is to say makes a lot of New instances of a thing which goes by the name of Dictionary. This appears to work similarly to a Microsoft Scripting Runtime Dictionary.

    So I am just trying to clear up if there is a subtle difference in the two, as I do see a minor difference in the Late binding use of it, or attempted use of it.

    Below is referenced a simple demo code. Anyone with an idea about Microsoft Scripting Runtime Dictionary will see I think exactly what it is doing.

    Rem 1 is a simple usage of a Microsoft Scripting Runtime Dictionary. (Scripting.Dictionary) ( I have it currently in Late binding, but it will work in early binding also if you comment out lines 80 and 90, and put back in lines 50 an 60 )

    Rem 2 is the same again but using the Dictionary, which to all intents and purposes seems to work like a Microsoft Scripting Runtime Dictionary in Early binding.

    ( It is a standalone code so you can run it without further a do...)
    _.....

    So Dictionary seems to work to all intents and purposes like an Early binding-ed Microsoft Scripting Runtime Dictionary(Scripting.Dictionary). And sure enough it fails at line 180 if I take off ( Uncheck ) the reference to the library Microsoft Scripting Runtime

    ***** As often , _....
    _...in carefully preparing my Post I may have the answer..... How’s this:
    Is the answer no more than Excel
    somehow guesses right in line 180 and 190 of my demo code that I mean
    Scripting.Dictionary ,
    whereas for some strange reason it will not guess that in line 197 ? ( In this Line 197 I try to do the typical second line of late binding
    = CreateObject("Scripting.Dictionary") ' No Problem here - it always works as I expect
    _..But_...._..
    = CreateObject("Dictionary") ' Run-time error '429': ActiveX component can't create object
    _......_....._...._ Does not work!! ===Minor difference===

    I note that after setting up Early binding, ( checking Microsoft Scripting Runtime in Extras, etc.. ) intellisense will offer me ( after I type = New ) both
    .Scripting.Dictionary
    and
    .Dictionary
    _ ... is this then that intellisense just offers what maybe / could be / perhaps, - but it is not an exact thing
    So bottom line to question 1). Is this the answer: There is no difference. Just VBA Syntax being a bit inconsistent in how it handles the two “Words”, -- “Dictionary” and “Scripting.Dictionary” ?

    _................::::..............

    Question _2)Help in understanding “Dictionaries in VBA”. General advice, Pros and Cons
    Is there really any advantage of using Dictonary , rather than for example a simple Array to do the same.

    I can see that Maybe some of the Properties of a dictionary are very handy/ convenient.., and that Adding increases automatically the size of a Dictionary by a “row” / record. , using a simple If __ Exists, rather than a .Match attempt to check for uniqueness... Etc.. etc... etc...
    There are lots of good references, for example.. ##
    To do all those Dictionary Methods and Properties with an Array involves, amongst other things, the Re- Dim Preserve stuff., which can get messy! .. But I guess one could do all that with Functions (I have !!!! – and it was messy, LOL.. !), or even make a Class, call it a Dictionary and make your own Add method, and all the other Methods and Properties .

    Is the point that a Dictionary references a Library and that telling me it uses something “outside” VBA that is particularly efficient, quick etc.??
    I lack the experience or time and resources to do extensive checks on this in the case of the Dictionary, but occaisionally I have seen that with simpler things, the theoretical advantage such as efficiencies seem to have been lost as computer speed has got so good. It is not that I am so enthusiastic about writing and maintaining the complicated Functions i have done to do similar things, but if , at the end of the Day with ever increasing computer speed they work as well, then at least I can see a bit more of what is going on and feel more “_...In control.... “ “_...lol !”.. )
    _................................................

    Question _3) Am I correct in saying that if I make a Function Declared as a Dictionary, then I must Early Bind
    because this:
    Fuction Dik( ) As Scripting.Dictionary
    Is pseudo doing this ( pseudoAlly ):
    Dim Dik As ( New ) Scripting.Dictionary __ ????( this is the first line of a typical 2 line way of declaring a variable in Early Binding , the second line would then be in the Function)

    _3)b).. ****EDIT: I have answered this..I think..
    And that will only work when I Early bind.. as in my code lines from line 250.......
    _...... Hmm .. I can late or Early bind within the Function though.... now there’s a Thought...

    Thanks
    Alan

    ****EDIT: I did a late Binding Function Also....( Edit Code from Line 300) so forget I Question _3

    But then , following on from that.. Question 3b) instead
    _ so then..
    Question _3b) as I demo in my code... there is no reason to Dim ( or is there ?? ) a variable, say Dik, to Take from a Function returning a dictionary itself As a dictionary ?
    I mean like this is OK to get a Dictionary from a function which returns a Dictionary
    Dim Dik As Object
    Set Dik = Fuk(___) ' In this case not New .. not a new instance
    Where Fuk can be defined as an Object an within that Function a Dictionary is created through late binding
    Question _C(ii) The thing receiving the Dictionary returned from a Function creating a Dictionary can be Dim ed As an Object. But I guess it is better practice generally to Dim that as a Dictionary ( .... or Scriptiung.Dictionary.... .. : )

    Just a last clarity here to answer my last ( 3) ) question....The answer is... I do not need to Dim a Function returning a Dictionary as Scripting.Dictionary ( or Dictionary )... ( but I guess it is probably more efficient to do that.. ?? )
    _.................................

    Demo Code Here:


    http://www.excelforum.com/showthread...70#post4431170

    Thanks again for reading
    Alan
    Last edited by Doc.AElstein; 07-12-2016 at 02:00 PM. Reason: Answered Question 3 I think maybe... mostly.... :)
    '_- Google first, like this _ site:ExcelForum.com Gamut
    Use Code Tags: Highlight code; click on the # icon above,
    Post screenshots COPYABLE to a Spredsheet; NOT IMAGES PLEASE
    http://www.excelforum.com/the-water-...ml#post4109080
    https://app.box.com/s/gjpa8mk8ko4vkwcke3ig2w8z2wkfvrtv
    http://excelmatters.com/excel-forums/ ( Scrolll down to bottom )

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Scripting dictionary help
    By leanne2011 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-04-2016, 09:32 PM
  2. [SOLVED] VBA Scripting.Dictionary Code Late Binding Error
    By NeedForExcel in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 07-20-2015, 03:06 AM
  3. Scripting dictionary help
    By leanne2011 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-14-2014, 09:51 AM
  4. need help with scripting dictionary
    By leanne2011 in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 10-04-2014, 04:33 PM
  5. [SOLVED] Using Dictionary in VBA scripting
    By vnzerem in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-04-2014, 02:54 PM
  6. Scripting Dictionary
    By Tendla in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-20-2013, 05:41 AM
  7. [SOLVED] Scripting Dictionary help
    By williams485 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-13-2012, 08:22 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1