viewpoint-particle

Author Topic: WIN10 Collection Issues  (Read 23 times)

stanl

  • Pundit
  • *****
  • Posts: 808
WIN10 Collection Issues
« on: December 09, 2018, 08:16:46 am »
My Win10 has Office 2019 and Visual Studio 2017 Community [updated], and I assume I have the same collection objects as with Win 7.  The following now gives an invalid COM Object


Code: Text
]
d = CreateObject("VBA.Collection")
d.Add( "Athens" )
d.Add( "Belgrade" )
d.Add( "Cairo" )
 

[/font]But I can initialize

Code: Winbatch

d = CreateObject("Scripting.Dictionary")
d.Add( "a", "Athens" )
d.Add( "b", "Belgrade" )
d.Add( "c", "Cairo" )
 
Which errors with k = d.Keys(i) is NOT a Collection

Code: Winbatch
For i= 0 to (n - 1)
   k = d.Keys(i)
   t = d.items(i)
   message( "Item %t%","key %k%")
Next
[code]


Basically just checking on a few script snippets that worked in Win 7 using COM Objects.[/size][/font]

 

stanl

  • Pundit
  • *****
  • Posts: 808
Re: WIN10 Collection Issues
« Reply #1 on: December 09, 2018, 08:48:25 am »
I hate stumbling on something that works after posting... this worked.


Code: Winbatch

ForEach k in d.Keys
   message(k,d.item(k))
Next
 

td

  • Tech Support
  • *****
  • Posts: 2653
    • WinBatch
Re: WIN10 Collection Issues
« Reply #2 on: December 09, 2018, 08:50:26 am »
Or

Code: Winbatch
a = d.keys()
for i = 0 to d.count - 1
   k = a[i]
next
 
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


td

  • Tech Support
  • *****
  • Posts: 2653
    • WinBatch
Re: WIN10 Collection Issues
« Reply #3 on: December 09, 2018, 08:54:18 am »
Or just use WIL maps.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


stanl

  • Pundit
  • *****
  • Posts: 808
Re: WIN10 Collection Issues
« Reply #4 on: December 09, 2018, 09:21:17 am »
Thanks. I'm really more interested in not being able to initialize vba.collection - it exists in my Excel 2019 Object Inspector and the references are correct, but even using it in an excel macro I get the 429 error. My AccessDatabase Engine is for 2016, I had 2010 but had issues scripting with the ACE.OLEDB provider. There is also a Microsoft.VisualBasic.Collection which may work with WB and the CLR.  Basic rock and hard place - While I prefer a strict WB solution because it is generally easier and a real coding time saver - I need to hedge my bets by linking in COM or NET objects or pushing Powershell code.