Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pass a method as an argument or somehow call a method of a form from a class 3

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
0
0
GB
Hi,

I want to be able to pass a method of a class the name of a form method (sub) to call.

I have..
Code:
Application.Run (sSub)

where sSub = "My_Form_Name.My_Method_Name"

But this errors with "cannot find procedure"

How do I get my class to accept an argument that is either the method on a form to run or a string name and eval it somehow and then execute the method?

Thanks,
1DMF

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
I take it you have created a class module called clsFileWatcher? You have defined oFileWatcher as a variable of type clsFileWatcher and I don't think there is any problem defining it as

Code:
Public WithEvents oFileWatcher As clsFileWatcher

in the form that is doing the work. Isn't that how the whole class object thing is meant to work? The form doesn't need to access the FileIOCompletionRoutine at all, it just needs to listen out for the event that you would define in clsFileWatcher. You would raise the event in FileIOCompletionRoutine then you would only have to do Form_Unload when it trapped the event. Isn't that the neatest way of doing this?

PeteJ
(Contract Code-monkey)

It's amazing how many ways there are to skin a cat
(apologies to the veggies)
 
The form doesn't need to access the FileIOCompletionRoutine

No FileIOCompletionRoutine needs to access the clsFileWatcher object.

Can a standard application module function raise a class event?

I'm a little confused here, isn't the class object WithEvents and so the class object should be raising the event for the form to handle?

Why would the module sub 'FileIOCompletionRoutine' be raising the event of a class object set WithEvents?


"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
The class module raises the event. The variable oFileWatcher is defined as a variable in the General section of the form code. As long as you have defined oFileWatcher as WithEvents then all you need to do is kick off the file watcher and wait for the event to happen. As soon as the the form traps the event (in the oFileWatcher_YourEventName procedure) then you tell the form what it needs to do next, in your case the Exit_Form procedure. In the code editor click on oFileWatcher in the object drop-down then the available events should show up in the other drop-down so just click on your event and add Exit_Form.

PeteJ
(Contract Code-monkey)

It's amazing how many ways there are to skin a cat
(apologies to the veggies)
 
OK, with a lot of refactoring I have an event being captured now on the parent form (not the Nav Control subform!)

Which means there was a lot of re-writing to talk to Form_Check_Docs.oFileWatcher , but I now have ...
Code:
            Case FILE_ACTION_ADDED
            
                ' stop watching
                Me.CancelWatcher = True
                    
                ' move dropped email file
                If Not (Me.MoveFile(Left(CStr(wombat.FileName), wombat.FileNameLength / 2))) Then
                    MsgBox "Error : " & Me.GetError
                End If
                
                [highlight #FCE94F]RaiseEvent FileMoved[/highlight]

This meant the actual drag/drop form initialisation of the watcher object had to be refactored

Code:
    ' set up filewatcher object
    Set Form_Check_Docs.oFileWatcher = New clsFileWatcher

            ' set folder watch details
            Form_Check_Docs.oFileWatcher.ContactID = oContact.ContactID
            Form_Check_Docs.oFileWatcher.CaseId = Nz(Form_Check_Docs.Case_ID, 0)
            Form_Check_Docs.oFileWatcher.Folder = sPath
            Form_Check_Docs.oFileWatcher.Target = oContact.FilePath & "\Emails"
            Form_Check_Docs.oFileWatcher.EmailType = "D"
            
            ' start watching
            Call Form_Check_Docs.oFileWatcher.FileWatch
            If Not (Form_Check_Docs.oFileWatcher Is Nothing) Then
                If Form_Check_Docs.oFileWatcher.GetError <> "" Then
                    MsgBox "Error : " & Form_Check_Docs.oFileWatcher.GetError
                    Call Exit_Form
                End If
            End If

But it is now working via the event instead of calling the drag/drop form's Exit_Form, I now have the following sub on the parent Check_Docs form

Code:
Public WithEvents oFileWatcher As clsFileWatcher

Private Sub oFileWatcher_FileMoved()
    Call UpdateView(True)
End Sub

And yes I know I have a user alert (msgbox) in the class object - I still have some tidying up to do ;-)

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top