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

Passing code to a sub thru a variable?

Status
Not open for further replies.

Quintios

Technical User
Mar 7, 2002
482
US
I have a subroutine that I use to set up Regular Expressions. From this I pull out certain pieces of text. Under certain circumstances, I want to pull out certain SubMatches from the Matches collection.

Can I send this code:
Code:
Match.SubMatches(1) & "," & Match.SubMatches(3) & ","

Through a variable to a subroutine such that this code:
Code:
For Each Match in Matches   ' Iterate Matches collection.
    RetStr = RetStr & sReplacement
    RegExp = RetStr
Next

will be intreperted as this code?
Code:
For Each Match in Matches   ' Iterate Matches collection.
    RetStr = RetStr & Match.SubMatches(1) & "," & Match.SubMatches(3) & ","
    RegExp = RetStr
Next


I tried setting a variable in both of the following ways but neither worked:
Code:
sReplacement= "Match.SubMatches(1) & "," & Match.SubMatches(3) & ",""   ' did not work
sReplacement= Match.SubMatches(1) & "," & Match.SubMatches(3) & ","   ' did not work

Many thanks!

Onwards,

Q-
 
you would be better to allow your sub to accept a boolean value and test if the value is true in the sub and then search for submatches
for example;
Sub FindStuff(blnSubs)

if blnSubs = true Then 'Search for submatches
'code here
else 'dont search for matched
code here
end if

End Sub
 
Well, I'm trying to come up with a Sub/Function that can accept general situations, so I don't have to code original things into each version I produce. Right now I have several variables that I'm sending to the sub. I guess adding one more won't hurt.

So you can't pass code through a variable?

Onwards,

Q-
 
Take a look at the
Code:
 Execute
instruction to deal with code passed thru variable..

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top