Tracy
asked on
Error calling Class Module
Hi guys,
I have a class module called cls_Cfg and this is a function in the class module:
Private Function EncryptFile(ByVal InFile As String, ByVal OutFile As String, _
ByVal Overwrite As Boolean, ByVal Key As String) As Boolean
I want to call this routine from a regular module, but when I try the below code I get a compile error saying method or data members not found. I'm not sure what the syntax is, I don't use class modules that often.
Thanks,
Tracy
I have a class module called cls_Cfg and this is a function in the class module:
Private Function EncryptFile(ByVal InFile As String, ByVal OutFile As String, _
ByVal Overwrite As Boolean, ByVal Key As String) As Boolean
I want to call this routine from a regular module, but when I try the below code I get a compile error saying method or data members not found. I'm not sure what the syntax is, I don't use class modules that often.
Thanks,
Tracy
Sub testCall()
Dim clsX As cls_Cfg
Set clsX = New cls_Cfg
clsX.EncryptFile("H:\tracy\cfg\temp.txt", "H:\tracy\cfg\temp2.txt", True, "test") = True
Set clsX = Nothing
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes, open Excel, expand the modules are and open the cls_Cfg file and search for the EncryptFile
If the intellisense works and shows that when you put in clsX with the dot after it, then it should be value and ready to receive information as described. However, show us at least the signature (Sub line)
If the intellisense works and shows that when you put in clsX with the dot after it, then it should be value and ready to receive information as described. However, show us at least the signature (Sub line)
hmmm...also just noticed that you end the line with "= True"
Why are you trying to assign something to a method...I think that might be the problem.
Try just this:
clsX.EncryptFile("H:\tracy \cfg\temp. txt", "H:\tracy\cfg\temp2.txt", True, "test")
Why are you trying to assign something to a method...I think that might be the problem.
Try just this:
clsX.EncryptFile("H:\tracy
ASKER
>>Can you share the class module?
Yes, I'll post in a few
>>hmmm...also just noticed that you end the line with "= True"
Yeah, I put that in because I was getting an "expected = error", so I was just trying stuff.
>>if the function declaration inside the class is "Private" you cannot see this function from the outside world (as in your module) - change the declaration to "Public" and the method will be found
I thought I had tried that, but maybe it was a different function I changed to public
>>If the intellisense works and shows that when you put in clsX with the dot after it, then it should be value
No intellisense
Yes, I'll post in a few
>>hmmm...also just noticed that you end the line with "= True"
Yeah, I put that in because I was getting an "expected = error", so I was just trying stuff.
>>if the function declaration inside the class is "Private" you cannot see this function from the outside world (as in your module) - change the declaration to "Public" and the method will be found
I thought I had tried that, but maybe it was a different function I changed to public
>>If the intellisense works and shows that when you put in clsX with the dot after it, then it should be value
No intellisense
ASKER
Attached is the code in the class module.
I changed to Public and now intellisense is there, which is good. However, when I take the "= True" part off it gives the "expected =" error again.
Thanks,
Tracy
cls-Cfg.cls
I changed to Public and now intellisense is there, which is good. However, when I take the "= True" part off it gives the "expected =" error again.
Thanks,
Tracy
cls-Cfg.cls
OK, so I see this signature:
Public Function EncryptFile(ByVal InFile As String, ByVal OutFile As String, _
ByVal Overwrite As Boolean, ByVal Key As String) As Boolean
So it will return a boolean and expects 4 parameters.
You're giving this:
clsX.EncryptFile("H:\tracy \cfg\temp. txt", "H:\tracy\cfg\temp2.txt", True, "test") = True
String, String, boolean, String.
Excellent!
Try this calling line instead:
Debug.Print clsX.EncryptFile("H:\tracy \cfg\temp. txt", "H:\tracy\cfg\temp2.txt", True, "test") '= True
See if a result shows up in the Intermediate / Output window.
Public Function EncryptFile(ByVal InFile As String, ByVal OutFile As String, _
ByVal Overwrite As Boolean, ByVal Key As String) As Boolean
So it will return a boolean and expects 4 parameters.
You're giving this:
clsX.EncryptFile("H:\tracy
String, String, boolean, String.
Excellent!
Try this calling line instead:
Debug.Print clsX.EncryptFile("H:\tracy
See if a result shows up in the Intermediate / Output window.
ASKER
>> Debug.Print clsX.EncryptFile("H:\tracy \cfg\temp. txt", "H:\tracy\cfg\temp2.txt", True, "test")
Yes, it returns True
Yes, it returns True
I think your problem was that VB likes to have functions stored somewhere. When it said that "=" was missing, it wanted it on the left of the function and assigned to some variable. I applied it to the print command but you'll probably want to save it in a variable for future use like:
strEncryptedFile = clsX.EncryptFile("H:\tracy \cfg\temp. txt", "H:\tracy\cfg\temp2.txt", True, "test")
strEncryptedFile = clsX.EncryptFile("H:\tracy
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great, thanks for the help.
Guess i am late for the party :)
Good Job Rob :)
Sid
Good Job Rob :)
Sid
Tracy,
Happy to see you got the help you needed.
In the future, if you want to make a class property/method "invisible" to the outside world, but accessible from the rest of your project, try declaring the property/method as Friend instead of Private.
Patrick
Happy to see you got the help you needed.
In the future, if you want to make a class property/method "invisible" to the outside world, but accessible from the rest of your project, try declaring the property/method as Friend instead of Private.
Patrick
ASKER
Good tip Patrick, thank you.
Can you share the class module?
Sid