Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Scripting Dictionary to hold User Defined Type

I have an array of user defined types that hold info about some
columns in the spreadsheet. I currently loop through to find the
column name I am interested in. I would like to use the scripting
dictionary to do this since I think it would be a little faster. I do
this a lot in my addin. I have tried numerous things and it does not
appear to allow this. I thought someone may know of a way to do it.
Here is a simplified test case.

I thought of having the dictionary hold the index to the array of user
defined types. This would work but it would be cumbersome to manage.
Perl and Ruby do this with ease.

Option Explicit

Public Type headUT
colName As String
colWidth As Integer
End Type

Sub testdic()

' Add reference to Microsoft Scripting Dictionary.

Dim xDic As New Scripting.Dictionary
Dim x() As Variant
Dim z() As headUT

ReDim x(0)
ReDim z(0)
' Assign values to user defined type
z(0).colName = "This column"
z(0).colWidth = 12
' Cannot assign User type directly to Dictionary .
xDic("COL_INFO") = z(0) ' Comment out to try next item
' Cannot assign User type to Variant then assign variant to
Dictionary
x(0) = z(0)
xDic("COL_INFO") = x(0) 'Can assign variant to dictionary
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Scripting Dictionary to hold User Defined Type

I think it would be a little faster.

I'd happily bet the other side. Array processing is pretty quick in Excel
and the Dictionary object is pretty slow.

Frankly I think you might be going about this the hard way. How about:

ActiveCell.EntireColumn.Name = "ThisColumn"

and later:

MsgBox Names("ThisColumn").RefersToRange.Column

--
Jim
"billbell52" wrote in message
oups.com...
|I have an array of user defined types that hold info about some
| columns in the spreadsheet. I currently loop through to find the
| column name I am interested in. I would like to use the scripting
| dictionary to do this since I think it would be a little faster. I do
| this a lot in my addin. I have tried numerous things and it does not
| appear to allow this. I thought someone may know of a way to do it.
| Here is a simplified test case.
|
| I thought of having the dictionary hold the index to the array of user
| defined types. This would work but it would be cumbersome to manage.
| Perl and Ruby do this with ease.
|
| Option Explicit
|
| Public Type headUT
| colName As String
| colWidth As Integer
| End Type
|
| Sub testdic()
|
| ' Add reference to Microsoft Scripting Dictionary.
|
| Dim xDic As New Scripting.Dictionary
| Dim x() As Variant
| Dim z() As headUT
|
| ReDim x(0)
| ReDim z(0)
| ' Assign values to user defined type
| z(0).colName = "This column"
| z(0).colWidth = 12
| ' Cannot assign User type directly to Dictionary .
| xDic("COL_INFO") = z(0) ' Comment out to try next item
| ' Cannot assign User type to Variant then assign variant to
| Dictionary
| x(0) = z(0)
| xDic("COL_INFO") = x(0) 'Can assign variant to dictionary
| End Sub
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default Scripting Dictionary to hold User Defined Type

I couldn't get it to work either.
Would this be a workaround?

z(0).colName = "This column"
z(0).colWidth = 12
xDic.Add "Col_Info", Array(z(0).colName, z(0).colWidth)

--
HTH :)
Dana DeLouis


"billbell52" wrote in message
oups.com...
I have an array of user defined types that hold info about some
columns in the spreadsheet. I currently loop through to find the
column name I am interested in. I would like to use the scripting
dictionary to do this since I think it would be a little faster. I do
this a lot in my addin. I have tried numerous things and it does not
appear to allow this. I thought someone may know of a way to do it.
Here is a simplified test case.

I thought of having the dictionary hold the index to the array of user
defined types. This would work but it would be cumbersome to manage.
Perl and Ruby do this with ease.

Option Explicit

Public Type headUT
colName As String
colWidth As Integer
End Type

Sub testdic()

' Add reference to Microsoft Scripting Dictionary.

Dim xDic As New Scripting.Dictionary
Dim x() As Variant
Dim z() As headUT

ReDim x(0)
ReDim z(0)
' Assign values to user defined type
z(0).colName = "This column"
z(0).colWidth = 12
' Cannot assign User type directly to Dictionary .
xDic("COL_INFO") = z(0) ' Comment out to try next item
' Cannot assign User type to Variant then assign variant to
Dictionary
x(0) = z(0)
xDic("COL_INFO") = x(0) 'Can assign variant to dictionary
End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dictionary object: Error assigning user defined data type to item Paul Urbanus Excel Programming 2 December 1st 05 04:21 AM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM
"User-defined type not defined" message in Excel RW1946 Excel Discussion (Misc queries) 0 August 31st 05 12:14 PM
User-defined data type; Error: Only User-defined types... tiger_PRM Excel Programming 1 July 18th 04 03:32 PM
Word.Document - user defined type not defined jowatkins[_7_] Excel Programming 0 January 20th 04 08:46 AM


All times are GMT +1. The time now is 09:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"