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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run procedure as argument?

Status
Not open for further replies.

PSchubert

Technical User
Jun 6, 2006
57
AU
Hello All,

Is there a way to run a procedure as an argument of another procedure? For example:

Code:
Private Sub ProcedureA(ByVal X As String, ByVal Y As String, _
    [B]Z As ???[/B]) As Boolean

    [I]...code here...[/I]

End Sub
'_________________________________________________________________

Private Sub Procedure B()

    X = [I]string statement[/I]
    Y = [I]string statement[/I]
    [B]Z = ProcedureB[/B]

    Call ProcedureA(X, Y, Z)

End Sub

Basically, what I'm trying to achieve here is to run two procedures simultaneously; one of them (Z) contains a Loop, which in my trials so far has prevented the other one from running. If I am on the right track with the above code, what data type should I set for Z and what should I set Z to equal?

Thanks in advance.
 
Hi Randy,

Thank you for your response. ProcedureB copies the contents of one directory to another, using fs.CopyFolder,with X as the source and Y as the destination.
 
the way your code looks, Z is just the return type of procedure B. Unfortunatly, you have coded the procedure as recursive (e.g. Procedure B calls ProcedureB) but procedure B has no declared return type, so it defaults to "Boolean", so Z (since it is not explixcitly declared) will default to Variant and assume type Boolean. Dealing with ecursive procedures can be troublesome, so the sample code is at least troubling as you have not illustrated how the recursion can escape ...

Mayhap you could restate the problem in more complete (and actual) terms?

MichaelRed


 
PSchubert said:
what I'm trying to achieve here is to run two procedures simultaneously; one of them (Z) contains a Loop, which in my trials so far has prevented the other one from running
I don't think this will aleviate your problem of the Loop "preventing" the other sub from running. As soon as you hit that loop, nothing else in your program will proceed until the looping is done.
What you might be looking for is multiple threads, which I have no idea how to do in VB.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top