ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   User-defined type not defined (https://www.excelbanter.com/excel-programming/452887-user-defined-type-not-defined.html)

Walter Briscoe

User-defined type not defined
 
In another thread, today, I mentioned Regular Expressions.
The subject of my posting is an XL 2003 Compile error.
I regularly find people mention user-defined types without saying where
they are defined.

In another thread, today, I mentioned Regular Expressions.
I reported:
Public RE As RegExp ' _
Needs Tools/References/Microsoft Vbscript Regular Expressions 1.0 or 5.5

Can somebody point me to code which:
1) Searches type libraries for a type
or
2) Enumerates the interfaces provided by a particular type library or
all type libraries on a system.

I have a book Windows Scripting Secrets by Tobias Weltner from 2000.
Herr Dr. Weltner produced a book with much interesting content.

In the accompanying CD, there is \install\typelib\setup.exe.
That installs code to enumerates all typlelib interfaces on the running
system.
I don't have a CD reader to hand.

Can somebody (Gary?) please point to a mechanism to go from a type name
to a type library?
--
Walter Briscoe

GS[_6_]

User-defined type not defined
 
A UDT is not a typelib! Typelibs require a reference; UDTs require
definition same as variables do.

"User-defined type not defined" error suggests you're passing a ref to
a UDT that doesn't exist. For example...

Type udtMyType
My1 As Boolean: My2 As Long: My3 As String
End Type
Public MyType As udtMyType

...and somewhere in code you'd use these like this...

Sub InitGlobals
MyType.My1 = ThisWorkbook.Saved
If MyType.My1 Then
MyType.My2 = 1: MyType.My3 = "Yes"
Else
MyType.My2 = 0: MyType.My3 = "No"
End If
End Sub

...where this will compile without error. Note that as soon as you type
"MyType." intellisense displays the list of types as defined in your
Type declaration.

Trying to compile 'MyType.My0' will throw an error!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion

GS[_6_]

User-defined type not defined
 
Better help if you show the offending code!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion

Walter Briscoe

User-defined type not defined
 
In message of Tue, 29 Nov 2016 14:40:03 in
microsoft.public.excel.programming, GS writes
Better help if you show the offending code!


Garry,
I DID show offending code.
I will try again.
I have just recorded and edited the following code:

Option Explicit

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 30/11/2016 by IBM
'
Dim RE As Regexp
'
End Sub

When compiled, it gets
Compile error
User-defined type not defined

I happen to "know" the way to deal with this is to add a reference to
Microsoft Vbscript Regular Expressions 1.0 or 5.5.
How would I find that out, if I did not have that "knowledge"?
I mentioned "Windows Scripting Secrets" code which enumerates all
typelibs. I am looking for VBA code with the same capability.
--
Walter Briscoe

GS[_6_]

User-defined type not defined
 
In message of Tue, 29 Nov 2016 14:40:03
in microsoft.public.excel.programming, GS writes
Better help if you show the offending code!


Garry,
I DID show offending code.
I will try again.
I have just recorded and edited the following code:

Option Explicit

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 30/11/2016 by IBM
'
Dim RE As Regexp


Regexp by itself is not defined, nor is it fully qualified. This
compiles without error for me in xl2003...

Option Explicit

Sub test()
Dim re As regexp

End Sub

...where I have ToolsReferences... set for the lib.
'
End Sub

When compiled, it gets
Compile error
User-defined type not defined

I happen to "know" the way to deal with this is to add a reference to
Microsoft Vbscript Regular Expressions 1.0 or 5.5.
How would I find that out, if I did not have that "knowledge"?


That's part of the VBA developer's skill set; -knowing what to do and
how to do it!

If you add a ref to the VBScript Regular Expressions object lib then
you'll be 'early binding' your project. This is fine for project dev
but is always better, IMO, to use late binding for runtime...

Option Explicit

Sub test2()
Dim re
Set re = CreateObject("VBScript.Regexp")

End Sub

...which also compiles without error.

I mentioned "Windows Scripting Secrets" code which enumerates all
typelibs. I am looking for VBA code with the same capability.


Perhaps this is what the References dialog does?! Surely the code in
that book can be translated to VB same as other VBScript can...

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion

Peter T[_7_]

User-defined type not defined
 

"Walter Briscoe" wrote in message
...
In message of Tue, 29 Nov 2016 14:40:03 in
microsoft.public.excel.programming, GS writes
Better help if you show the offending code!


Garry,
I DID show offending code.
I will try again.
I have just recorded and edited the following code:

Option Explicit

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 30/11/2016 by IBM
'
Dim RE As Regexp
'
End Sub

When compiled, it gets
Compile error
User-defined type not defined

I happen to "know" the way to deal with this is to add a reference to
Microsoft Vbscript Regular Expressions 1.0 or 5.5.
How would I find that out, if I did not have that "knowledge"?
I mentioned "Windows Scripting Secrets" code which enumerates all
typelibs. I am looking for VBA code with the same capability.
--
Walter Briscoe


Bit confused with what you're doing and why.

First, you say you set the reference, can you see in object browser (ensure
your file is selected), if it is you should see RegExp listed in Classes. If
it's not there what are you using Win64, if so is your Office default 32 or
64 bit. Either way, if you are in Win64 did you set the correct reference
for your office version.

Not sure if related but FWIW there were some recent vbscript updates
recently, typically for security reasons but they sometimes cause problems.
If it was working but nothing has changed in your setup try rolling back.

Second, I don't follow the rest of what you say, "with the same
capability" - do to what?

I agree with Garry, develop with Early Binding, then adapt and distribute
with Late Binding for a better chance of finding it in different setups.

Peter T




All times are GMT +1. The time now is 03:55 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com