Class Module Parameter

cuttsy

The Great Pretender
Local time
Today, 17:43
Joined
Jun 9, 2004
Messages
164
I have used classes in vb6 a while ago but never in vba so I am hopeing that I have missed something blindingly obvious.

I have a Class Module called FileObject
It has 3 Public Get Properties for FullPath, FilePath and FileName
It also has a Public Sub SetFile(ByVal sFullPath as String)

This sub amongst other things sets the fullpath, filepath and filename values.
Or at leat it should. When I call SetFile:

Code:
Dim oFile as New FileObject
Call oFile.SetFile ("S:\somefolder\somefile.mdb")

I have placed a breakpoint in SetFile and sFullPath = ""

Why would the code be failing to pass the parameters value?
 
Hi,

I've put this example together.

This is my class; CLS_F

Code:
Option Compare Database
Option Explicit
Private Fname As String
Property Let SetFileName(FileNme As String)
   Fname = FileNme   ' Assign filename.
End Property
Property Get GetFileName() As String
    GetFileName = Fname ' return file name
End Property

This is how i called it.

Code:
Private Sub Command0_Click()
Dim Clsf As New CLS_F


Clsf.SetFileName = "TEST"

MsgBox Clsf.GetFileName


Set Clsf = Nothing

End Sub

seems to work fine.

hth

K
 
Year that works for me too.

All of me Get and Let Propeties work just as I would expect and are similar to how you have shown.

but I have a sub in my class:

Code:
Public Sub SetFile(ByVal sFullPath As String)

But when I call it like this:

Code:
Call oFile.SetFile("S:\Lifelong\Contacts.mdb")

It does not work because my parameter sFullPath = "" instead of sFullPath = "S:\Lifelong\Contacts.mdb"
 
Hi,

I've added this to my class and it works :confused:

Code:
Public Sub SetFile(ByVal sFullPath As String)

MsgBox sFullPath

End Sub


Code:
Private Sub Command0_Click()
Dim clsf As New CLS_F

Call clsf.SetFile("path")

' this works as well
' clsf.SetFile "path"

End Sub


K
 
okay thanks, I was sure that the syntax was sound. So I'm glad you confirmed it.

I changed the Sub from

Code:
Public Sub SetFile(ByVal sFullPath as String)

to

Code:
Public Sub SetFile(ByVal sPath as String)

and now it works... :confused:

Thanks for going through that with me :)
 
No worries :) , as a matter of interest has you used sFullpath as a property or variable anywhere else in that class?
 

Users who are viewing this thread

Back
Top Bottom