0

I have a legacy code - some macro for Autocad - and I got it running on Autocad 2015 with enabled VBA. There are some string-related function as Trim, Mid, etc. And these functions are missing references, VBA can't find their definitions. I can find them manually in object browser, so I use Strings.Trim and it works. How can I avoide adding module name to every call of the function in VBA? Is there something like include String'?

Edited: I got a compile error "Can't find project or library" and here is a screen shot of References window just after this message:

enter image description here

And Microsoft Word Library is selected be default. I double-checked, the path to it is correct. There is no libraries with MISSING prefix (or just can't see it). Maybe, some of them must be excluded since it is a legacy code, but I am not sure wild guessing will be fine in this case, maybe there is a way to get problem libraries marked?

Community
  • 1
  • 1
Pavel Oganesyan
  • 6,774
  • 4
  • 46
  • 84
  • 2
    What are the current references to the code? See if there are any broken or missing reference. If so fix them : http://www.access-diva.com/d5.html – PaulFrancis Oct 09 '14 at 09:33
  • @PaulFrancis Thank you for attention, I updated the post. – Pavel Oganesyan Oct 11 '14 at 16:18
  • Something tells me that the bit version of the Autocad is not 32. Is this correct? Your error might not be because of the reference but because of a compiler error stuck somewhere. Did you try a Compile on the VBA code? – PaulFrancis Oct 13 '14 at 08:42
  • @PaulFrancis Yes, it's a 64 bit version. After all i got project compiled - I deleted reference to DAO 3.6 and added reference to the newest Access library. Compilation was fine but now there are some strange run-time errors. – Pavel Oganesyan Oct 13 '14 at 15:24
  • Yes, you still have not actually solved the problem. See what are the library declarations you have in your code. Make sure they are made **PtrSafe**. – PaulFrancis Oct 13 '14 at 15:40
  • @PaulFrancis How do I find a library declaration? Code starts with `Option Expilicit` and some variable declarations. Just a new VBA user here, sorry. – Pavel Oganesyan Oct 13 '14 at 15:57
  • Browse through the code and see if you can fins something like `Private Declare Sub......` you need to declare them using `Private Declare PtrSafe Sub.....` – PaulFrancis Oct 13 '14 at 16:03

1 Answers1

1

It is possible one of your references (newer versions of AutoCAD, or more likely Microsoft Word) now has function or method names matching Left, Mid, Trim and so on, that didn't exist before. This will make those function names Ambiguous. Try selectively removing references to see the effect on those functions, or observe the intelliSense when typing Mid to see if it has a different meaning.

Consider writing wrappers for those string functions. For example, write a Left function that internally calls strings.Left in a module visible to where those functions are used.

While this doesn't solve your problem immediately, it will allow you to minimise changes to the legacy code.

reckface
  • 5,678
  • 4
  • 36
  • 62