A Microsoft Excel forum. ExcelBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » ExcelBanter forum » Excel Newsgroups » Excel Programming
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

User-defined type not defined



 
 
Thread Tools Display Modes
  #1  
Old November 29th 16, 04:02 PM posted to microsoft.public.excel.programming
Walter Briscoe
external usenet poster
 
Posts: 279
Default 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
Ads
  #2  
Old November 29th 16, 05:40 PM posted to microsoft.public.excel.programming
GS[_6_]
external usenet poster
 
Posts: 695
Default 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
  #3  
Old November 29th 16, 07:40 PM posted to microsoft.public.excel.programming
GS[_6_]
external usenet poster
 
Posts: 695
Default 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
  #4  
Old November 30th 16, 07:27 AM posted to microsoft.public.excel.programming
Walter Briscoe
external usenet poster
 
Posts: 279
Default 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
  #5  
Old November 30th 16, 08:44 AM posted to microsoft.public.excel.programming
GS[_6_]
external usenet poster
 
Posts: 695
Default 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 Tools>References... 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
  #6  
Old December 1st 16, 12:07 AM posted to microsoft.public.excel.programming
Peter T[_7_]
external usenet poster
 
Posts: 131
Default 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


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile error: User-defined type not defined Ayo Excel Programming 3 April 23rd 09 07:42 PM
"User-defined type not defined" message in Excel RW1946 Excel Discussion (Misc queries) 0 August 31st 05 12:14 PM
Workspace faux user-defined type not defined Chris S[_2_] Excel Programming 3 November 11th 04 05:51 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 10:30 PM.


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