Results 1 to 15 of 15
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VB6 - missing references (Vis Studio Enterprise)

    I have solved a problem that puzzled me.

    Several VBP files wouldn't compile, and balked at an innocuous "MID", "TRIM" or "FORMAT" function. Creation of a tiny standalone project confirms that these functions are indeed part of VB6.

    By accident I found that if I checked off the Missing Reference entry (and initially, but I think redundantly) added in any other valid DLL, the problem went away.


    I now suspect that a "Missing reference" causes the VB6 compiler to choke on the first function reference it comes across.

  2. #2
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 - missing references (Vis Studio Enterprise)

    EXACTLY! I had that same problem a while ago with my Excel VBA project. It took me a while to figure out that that reference was missing. I have since added code (stolen from John Green's Excel 2000 VBA book) that checks for any missing references at workbook open. It won't fix the error but at least warns me and quits before getting into trouble.

    Deb <img src=/S/bash.gif border=0 alt=bash width=35 height=39>

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 - missing references (Vis Studio Enterprise)

    Thanks for the confirmation. Any chance that you could post a copy of that stolen code, in its modified form?

    I'm looking at some form of batch compile, or at least a pre-compile.

    A report telling me which projects have potential problems would let me focus on the more pressing problems at hand.

  4. #4
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 - missing references (Vis Studio Enterprise)

    Chris,

    If you want to determine which projects might cause problems because of missing references, have a look at the VBP files using notebook.

    You've already seen that changing a reference changes a line in the VBP file.

    Then take a project file which has a problem, add the missing reference, and then compare the new vbp file with the old. There will be a new line in the vbp file. Scan to determine which vbp files do not contain that string.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 - missing references (Vis Studio Enterprise)

    > VBP files using notebook.

    Right. I think this is the equivalent of my "Sweep.com Change.com" proposal.

    I could automate the task to get most of it out of the way.

    Dear old DOS FIND would probably give me a pretty good list of all VBP projects that contain known (to me) problems, such as "c:winnt".

  6. #6
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 - missing references (Vis Studio Enterprise)

    Sure here it is... This is my slightly modified version of the code (from John Green's Excel 2000 VBA book, page 319). One of the many things I do in workbook_open is to check if there are any missing references. If yes, I post a message and close the workbook.

    Here's how I call the code:
    <pre>If Not ExtReferencesValid() Then
    ThisWorkbook.Saved = True
    Application.DisplayAlerts = False
    ThisWorkbook.Close
    Exit Sub
    End If
    </pre>


    The procedure is called ExtReferencesValid() and it returns true/false.

    <pre>Public Function ExtReferencesValid(Optional noArg As Boolean = True) As Boolean
    Dim objRef As Object, stDescn As String

    ExtReferencesValid = True
    For Each objRef In ThisWorkbook.VBProject.References
    ' Debug.Print "Checking references for: " & objRef.Name
    If objRef.IsBroken Then
    'some broken links don't have descriptions, ignore
    On Error Resume Next
    stDescn = "<Not know>"
    stDescn = objRef.description
    On Error GoTo 0

    'display message to install missing item
    ExtReferencesValid = False
    MsgBox "Missing reference to: " & vbCrLf & "Name: " & _
    stDescn & vbCrLf & "Path: " & objRef.FullPath & vbCrLf & _
    "Please re-install this file. The model will not work without it", _
    vbCritical + vbOKOnly, "Missing Required File"
    End If
    Next objRef

    End Function
    </pre>


    The "optional noArg" is my trick to make sure that public procedures do not appear in the macro list available to the user from Excel. I do not want users to see these procedures and then press 'Run'. This hides them since I can't always make everything private.

    Deb <img src=/S/compute.gif border=0 alt=compute width=40 height=20>

  7. #7
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 - missing references (Vis Studio Enterprise)

    Deb, thanks for this. I'm going to leave it in my InBox until I return from vacation on the 12th.


    > make sure that public procedures do not appear in the macro list available to the user from Excel.

    ?? I thought that Functions weren't visible, nor subroutines with arguments.

    In fact, my recent study suggests that a User Macro is "A Public Subroutine with no arguments stored in a User Module" (i.e. not a Public Sub NoArgs in a Form or Class Module etc).

    I'll take this up, too, in a week's time.

    In the meantime, thanks again for the code posting. Something for me to look forward to.

  8. #8
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 - missing references (Vis Studio Enterprise)

    TRUE, functions aren't visible (since they can't be recorded) and any public subs with arguments aren't visible. I was just pointing out that if you want to ensure that no one accidently runs any of your public subs that do NOT have args, then you need to add an optional (un-used) arg to those subs. This will result in them being hidden (not listed) in the macro list.

    Your definition of a macro is correct ("a public sub w/no args") but my offered solution doesn't change that, it merely solves the problem of someone accidently running your macro. Also, I just don't like people seeing what public subs I have in general as I always protect my projects.

    You're welcome for the code, J. Green's book is one of two that I covet daily.

    Deb <img src=/S/evilgrin.gif border=0 alt=evilgrin width=15 height=15>

  9. #9
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 - missing references (Vis Studio Enterprise)

    >I just don't like people seeing what public subs I have in general

    Me too, but see also: [img]/forums/images/smilies/cool.gif[/img]+writing+a+procedure+as+a+subroutine+is+an+admissi on+of+failure+on+my+part">([img]/forums/images/smilies/cool.gif[/img] writing a procedure as a subroutine is an admission of failure on my part</A>, he said, heading off on vacation and avoiding any argument (sic!) about arguments!

  10. #10
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 - missing references (Vis Studio Enterprise)

    So instead of admitting "failiure" as you say, you'd rather have multiple copies of the same code all over your project?! That is 100 times worse than merely one public procedure and violates all that is good about modular programming and maintenance. I've seen too many huge programs (100,000s of lines of code) which had duplicate procedures and it was a nightmare to manage (had to fix the same bug in multiple procedures assuming you knew where all the duplicates were). I'm glad you're not working on any of my projects <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Deb

  11. #11
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 - missing references (Vis Studio Enterprise)

    > you'd rather have multiple copies of the same code all over your project?

    Sorry for the delay. I've been away a week.


    I am not encouraging multiple copies of anything. I'm saying that if a procedure is not supposed to be accesible to the public (as a User Macro), than make it a function procedure, or else a subroutine procedure with arguments.

    Adding arguments to a subroutine doen't make multiple copies of the code. It changes the way a programmer invokes it.

    Now, If something I've written has misled you into thinking I'm proposing non-reusable code, please let me know what phrase it was, because that same phrase has probably confused other readers, who didn't have the courage to question me. I'd like to set this record straight!

  12. #12
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 - missing references (Vis Studio Enterprise)

    No intention to ruffle feathers... Let comment on each of your suggestions.

    1. "...if a proc is not supposed to be accesible to the public (a user macro...)" But a macro is public by default (if it's recorded and that's what I call macros, not when I write VBA from scratch. So if someone just records macros, then all their code is pubic and that was the problem I was referring to.

    2. ".. then make it a function procedure." But that only works if you want to return something, unless you just want to make everything functions and not do anyything with the result which isn't a good habit to get into (and generates an error in some languages).

    3. "... or else a subroutine proc with no args". If this is public w/o args it shows in the macros list which was the problem I was offering a solution to so that's not a solution either.

    You made the comment that you like to use all private code to which I said that that's nice if you can do it but when it's not possible AND you don't have args in your proc AND you don't want users to see/run them from the macro list then a good idea is to provide optional unused args.

    I did not say that adding args makes multiple copie of code, of course it doesn't. I said that if you want everything private but need that same code in multiple modules the only solution is to copy that private routine to the other modules thus duplicate code. This is how I interpreted what you said.

    All of this is only relevant in VBA where I can't make a .dll or .exe which hides my code.

    Deb <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  13. #13
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 - missing references (Vis Studio Enterprise)

    > No intention to ruffle feathers... Let comment on each of your suggestions.

    I'm not ruffled, but thanks anyway; mainly very very tired, but getting over that.


    > 1. "...if a proc is not supposed to be accesible to the public (a user macro...)" But a macro is public by default (if it's recorded and that's what I call macros, not when I write VBA from scratch. So if someone just records macros, then all their code is pubic and that was the problem I was referring to.


    OK. I see a problem when the user can see/have access to somthing I don't WANT them to see. A recorded macro is a recorded macro, and ought, by definition, to be visible to the user. However, a subroutine with no arguments, which (subroutine) is intended to be used only via VBA code ought not be visible to the user.

    I'm thinking of internal subroutines that do "stuff" to "global data items", assuming that, since they are internal, all the data has been checked and is OK; such subroutines tend to have limited error-checking and recovery. Those are subroutines I wouldn't want the user to run willy-nilly. Of the top of my head, a subroutine to delete the INI file or the LOGging file would be one. Maybe the name of the file is available globally, but my internal code makes a backup copy of the file before deleting. I don't want the user to run the subroutine and delete the file without knowing enough to have made a backup copy.

    Such a subroutine (which of course looks like a macro to the user via Tools, Macros, Macro) can be hidden by converting it to a FUNCTION or by adding arguemnts, or by marking it PRIVATE.

    Marking it PRIVATE means that I'd need multiple copies of it, one in each module that wanted to make use of it, and we don't want that, do we?



    As an aside, I'll relate that I maintain a template Utils.dot with one module U in which are all my utility procedures (natch!). As a test right now I ought to load Word with ONLY my Utils.dot visible, and check to see what code is visible via Tools, Macros, Macro. My argument is that if any code from Utils is visible to the user, then I feel that *I've* done something wrong. Utils.dot contains developer tools; my user ought not to be able to see any of that code directly. There's a list of my Utils functions on my web site, somewhere.

    I have another template Under.dot (as in "Under-the-hood") which DOES contain user macros on purpose. Under.dot has a copy of my U module to do its work, but nothing in the U module ought to be visible to the user.

    Utils.dot is for the developers eyes only; Under.dot is for the user's eyes.



    > 2. ".. then make it a function procedure." But that only works if you want to return something, unless you just want to make everything functions and not do anyything with the result which isn't a good habit to get into (and generates an error in some languages).


    There have been times when I've been stuck for a serious result from a function; most times I can dream up a result. A subroutine with no arguments is usually processing data, so there is a change being made somewhere to something. A function can always return the previous state of the data, if nothing else.

    As a simple example, even a subroutine that renames a file can return the timestamp of the file as it was at the time of renaming. Thus the Rename function says "I made the rename, and the last time the file had been modified was ....".





    > 3. "... or else a subroutine proc with no args". If this is public w/o args it shows in the macros list which was the problem I was offering a solution to so that's not a solution either.

    I'll have to go back and read this next time I'm on line. It may have been a typo on my part, looks like I meant to say "... or else a FUNCTION proc with no args".




    > You made the comment that you like to use all private code to which I said that that's nice if you can do it but when it's not possible AND you don't have args in your proc AND you don't want users to see/run them from the macro list then a good idea is to provide optional unused args.

    OK. If I said this "like to use all private code ", I've changed my mind since then. I'll go back and re-read. I suspect that back in those days I was still sorting through the visibility of the various parts of a template collection, and in exasperation had swung the pendulum to far to the PRIVACY side in an effort to reduce the number of "macros" popping up in my user's list box (via Tools, Macros, Macro).

    I know that I was confused enough not to realise that I could see every bit of VBA code while I was editing the template, but hadn't tumbled to the fact that most of it disappeared once the template was swung into production, loaded via the Startup Directory, for example.

    I'm still a genius, but at times very slow to realise my potential (grin).


    "a good idea is to provide optional unused args" and I agree with this. It's a good idea. I'd still rather turn the subroutine into a function and return a result than show unused arguments, which may confuse some later developer.



    > I did not say that adding args makes multiple copie of code, of course it doesn't. I said that if you want everything private but need that same code in multiple modules the only solution is to copy that private routine to the other modules thus duplicate code. This is how I interpreted what you said.

    I had misunderstood your comment, and so I am so glad that you have replied to my query.

    I agree with you - "if you want everything private but need that same code in multiple modules the only solution is to copy that private routine to the other modules thus duplicate code." and now it seems that we are on track. Multiple copies of code is not good. Privacy means that code is not visible to the developer across a module boundary. Code that must be visible across module boundaries must be public.

    And finally, public code in the form of a subroutine without arguiments, appears to the user as a macro, and can be run by the user from the Tools, Macros, Macro command.




    > All of this is only relevant in VBA where I can't make a .dll or .exe which hides my code.


    Hah! I can do that now, after a fashion (see "genius" above), and am looking forward to taking some of my more useful macros and releasing them as a DLL or EXE.

  14. #14
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 - missing references (Vis Studio Enterprise)

    > You made the comment that you like to use all private code

    Deb, for the life of me (not worth much these days ...) I can't find this. If you still have a reference to it, might you post it? Thanks.

    I hope my wordy reply has straightened out some of the confusion.

  15. #15
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB6 - missing references (Vis Studio Enterprise)

    I totally agree on all points <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23>.

    I found all public procs w/o args show in the macro list whether they were recorded or not. I don't want people accidently running the ones I wrote (there are no recorded ones in my project) so that's why I had to add the optional args to those public procs so they're not accessible by the user (only by the code).

    I like you idea of the util module. I only work in Excel VBA and don't use add-ins or templates as my users can't be bothered to use them they require all code embedded in my single .xls file which makes managing the code not as nice as it could be but I do use a lot of classes.

    Ok, I think we can bury this thread for good. <img src=/S/bash.gif border=0 alt=bash width=35 height=39> <img src=/S/rubbish.gif border=0 alt=rubbish width=15 height=15>

    Deb <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •