How can I access hidden class variables in VB6?

I have this line in the declarations section:

Private filePath As String

And something like this below:

Public Sub Print(filePath As String)
...
End Sub

In part ..., I want to assign the filePath parameter at the module level of filePath . But how can I access the latter? Thank you very much.

+4
source share
4 answers

Phoenie I don’t think that I’ll look at the private class variable in VB6 / VBA anyway if you have something in the local area that is hiding it (I had a nice old google search but nothing came up). If you want to keep the naming convention and not modify the existing interface, the only workaround is to develop a private function to access the variable for you. eg.

 Public Sub Print(filePath As String) SetMyFilePath filePath End Sub Private Sub SetMyFilePath(ByVal passedFilePath as String) filePath = passedFilePath End Sub 
+2
source

How about changing the code to avoid confusion?

 Private mFilePath As String 

Change either the module level variable or the argument to the print function.

+5
source

So, you are allowed to modify Sub in such a way as to (if possible) allow you to set a private variable to a local variable ... but you are not allowed to rename any parameter? If you cannot make an offer to Ira Baxter either ... then your task is impossible in VB6. The restrictions imposed on you sound unreasonable.

+1
source

If you cannot change the parameter name in your function, you can always define another function:

 Public Sub SetfilePath(m As String) filePath = m End Sub 

and call SetfilePath in your ... code.

If this was my problem, I would think why you are not allowed to change the parameter name in your routine and change it. Obviously, you are permitting changes to your subroutine; why is this particular change prohibited?

0
source

All Articles