Complie error w/ no line highlighted

  • Thread starter Steve Jorgensen
  • Start date
S

Steve Jorgensen

I created an ActiveX DLL library in Visual Basic 6, and tested it from Excel
VBA, and all my tests passed. Then I tried to help integrate this inot
someone else's Excel application, but we got a compile error somthing like
"User defined datatype not defined." We are both using Excel 2002.

The compiler does not move the cursor or highlight any line of code when
reporting this error, so there's no way to know where the error comes from. I
suspected the VBA project had become corrupted somehow, so I tried re-creating
all the code modules in a new Excel file, copied all the text from the old
modules into the new ones, added the reference to my library, and it worked.
Great - problem solded, right?

Today, the same person came back to me and said the problem is occurring
again, and she tried the same fix I used the first time, but to no avail.

Does anyone know what might be going on here or how to fix it?

Thanks,

Steve J.
 
W

Wei-Dong XU [MSFT]

Hi Steve,

For your scneario, I'd suggest you will need to debug your project to locate this exception thrown at which line. You can narrow down with exception
with the help of the codes: "Debug.Print" or "MsgBox <some string to be shown>". This way, when you find the line, you can check the syntax to see
which type has caused this error message.

Please feel free to let me know if you have any further questions.

Best Regards,
Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steve Jorgensen

Hi Steve,

For your scneario, I'd suggest you will need to debug your project to locate this exception thrown at which line. You can narrow down with exception
with the help of the codes: "Debug.Print" or "MsgBox <some string to be shown>". This way, when you find the line, you can check the syntax to see
which type has caused this error message.

Please feel free to let me know if you have any further questions.

Best Regards,
Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

I'll have to try that, but I have no way of knowing that the code will error
out on any line whatsoever. If so, that doesn't mean we're out of the woods,
it just means we can't check for comile errors in the code by hitting compile
anymore because there will always be a failure. And what kind of error goes
away once when you copy the code into fresh new modules, then fails to go away
when you do the same thing when it happens again? I'd like to have some idea
what causes this.
 
D

Dave

Using VBA I've seen this a couple of times, specifically Excel, Access and VB script(ASP). Heres a couple of things to look into.
When compling the VB dll make sure the "Version Compatibility" is set up correctly, ie the dll uses the same registry base address each time its compiled. If no compatibility is set for the dll a new address is assigned each time. Have a look here for more information.

How are you accessing the dll in excel?
Consider moving away from ....
Dim MyObj As WhateverObj

to the late binding approach of ....
Dim MyObj As Object
Set MyObj = CreateObject("LibraryName.WhateverObj")

Obviously you wont have intellisense in excel anymore but itll give you a bit more freedom and you can wrap up the object creation in a "Test" function to make sure its found correctly. You can also dynamically register your dll per code using the following if your test function fails.
' example of the MS xml dll registration.
Private Declare Function RegMSXML Lib "MSXML.DLL" Alias "DllRegisterServer" () As Long

hth,
Dave
ps. The error message is stating that the variable definitions in excel cannot be resolved. The error source is presumably any direct code reference to your library - assuming your library is the problem ;-),
welcome to dll hell :)
FWIW: I've never experienced this type of behaviour in VB 6.0, only in its subset languages?
 
S

Steve Jorgensen

Using VBA I've seen this a couple of times, specifically Excel, Access and VB script(ASP). Heres a couple of things to look into.
When compling the VB dll make sure the "Version Compatibility" is set up correctly, ie the dll uses the same registry base address each time its compiled. If no compatibility is set for the dll a new address is assigned each time. Have a look here for more information.

I was the first time I used that version of the dll on that machine, though I
had delivered code via cut-and-paste into the Excel VBE before and some
objects had the same names. We deleted the old objects before setting the
reference to the new library.

I was planning to give the DLL a new name for each roll-out, so I could let
users keep the previous version installed until they're confident the new one
isn't breaking anything in their applications. Doing it this way, I don't
need to worry about the compatability option setting, right?
How are you accessing the dll in excel?

Installing it as a package, then setting a reference under Tools -> References
Consider moving away from ....
Dim MyObj As WhateverObj

to the late binding approach of ....
Dim MyObj As Object
Set MyObj = CreateObject("LibraryName.WhateverObj")

Ouch - so there will be no compile-time type checking, then. I like to let
the compiler do a lot of the work for checking whether my code is sound.
Obviously you wont have intellisense in excel anymore but itll give you a bit
more freedom and you can wrap up the object creation in a "Test" function to
make sure its found correctly. You can also dynamically register your dll per
code using the following if your test function fails.
' example of the MS xml dll registration.
Private Declare Function RegMSXML Lib "MSXML.DLL" Alias "DllRegisterServer" () As Long

Hmm, similar code in Access will work even with explicit references, so long
as it happens before any othe code runs.
hth,
Dave
ps. The error message is stating that the variable definitions in excel cannot be
resolved. The error source is presumably any direct code reference to your library -
assuming your library is the problem ;-),
welcome to dll hell :)

Actually, I'm an Access programmer, so I'm -very- familliar with DLL hell,
just with Microsoft's DLLs, not with my own.
 
S

Steve Jorgensen

I created an ActiveX DLL library in Visual Basic 6, and tested it from Excel
VBA, and all my tests passed. Then I tried to help integrate this inot
someone else's Excel application, but we got a compile error somthing like
"User defined datatype not defined." We are both using Excel 2002.

The compiler does not move the cursor or highlight any line of code when
reporting this error, so there's no way to know where the error comes from. I
suspected the VBA project had become corrupted somehow, so I tried re-creating
all the code modules in a new Excel file, copied all the text from the old
modules into the new ones, added the reference to my library, and it worked.
Great - problem solded, right?

Today, the same person came back to me and said the problem is occurring
again, and she tried the same fix I used the first time, but to no avail.

Does anyone know what might be going on here or how to fix it?

Here's an update. Before I set a reference to the dll, I commented out all
the standard module code being replaced by code in the DLL and renamed the
class modules. After I actually deleted those modules, the problem went away.
I don't know exactly what that's all about, but the problem seems to be
solved.
 
W

Wei-Dong XU [MSFT]

Hi Steve,

That's a great news! Please feel free to let me know if you have any further question. Have a nice weekend!

Best Regards,
Wei-Dong Xu
Microsoft Product Support Services
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top