Let me start by saying that I know that Log is the natural logarithm function and that I used the word Log as the name of a subroutine, without thinking. But it caused no problem initially.
In project Personal.xlsb, if I define Log as follows in module IO, I can use Log in a different module within the project:
Here I use Log successfully in module Backup within the same project:
But if I use similar code in external project Blood.xlsm, the compiler highlights Log and gives the compiler error below:
Of course, the error is because the compiler isn't using the definition in module IO where I successfully redefined Log in project Personal.xlsb. It thinks Log is the natural logarithm function.
(I confirmed this by changing the statement with the error to msgbox Log(Exp(246)) and getting 246 as expected.)(Log and Exp are inverse functions, which "cancel" each other.)
I could simply change all instances of Log to Logg or Logit or Stump, etc. and be on my way. Or I could copy the code into project Blood.xlsm.
But the question is much deeper, as a similar situation isn't difficult to imagine. The compiler allowed use of the redefinition of Log in module Backup that is internal to Personal.xlsb, so surely there's a way to extend the scope of Log to external projects. I would call any attempted usage of Log an unresolved external reference for any attempted usage outside the project where it's defined.
So here's my question:
What declaration or option or hunk of code or ...(?)... will permit me to use Log as a subroutine accessible from any project external to (outside of) Personal.xlsb?
In project Personal.xlsb, if I define Log as follows in module IO, I can use Log in a different module within the project:
VBA Code:
Public Sub Log(filenumber, msg)
On Error GoTo skippy
Print #filenumber, msg
skippy:
Debug.Print msg
MsgBox msg
End Sub
Here I use Log successfully in module Backup within the same project:
VBA Code:
n = FreeFile()
Open outputFile For Output As #n
Log n, "Backing up these projects (to..." & staticBackupFolder & newBackupSubFolder & ")"
But if I use similar code in external project Blood.xlsm, the compiler highlights Log and gives the compiler error below:
VBA Code:
Log 0, "Wrote new values to " & STATE_FILE"
Wrong number of arguments or invalid property assignment
Of course, the error is because the compiler isn't using the definition in module IO where I successfully redefined Log in project Personal.xlsb. It thinks Log is the natural logarithm function.
(I confirmed this by changing the statement with the error to msgbox Log(Exp(246)) and getting 246 as expected.)(Log and Exp are inverse functions, which "cancel" each other.)
I could simply change all instances of Log to Logg or Logit or Stump, etc. and be on my way. Or I could copy the code into project Blood.xlsm.
But the question is much deeper, as a similar situation isn't difficult to imagine. The compiler allowed use of the redefinition of Log in module Backup that is internal to Personal.xlsb, so surely there's a way to extend the scope of Log to external projects. I would call any attempted usage of Log an unresolved external reference for any attempted usage outside the project where it's defined.
So here's my question:
What declaration or option or hunk of code or ...(?)... will permit me to use Log as a subroutine accessible from any project external to (outside of) Personal.xlsb?