Hello again guys,
So I have an error handler that formats cells displays a variety of different error messages depending on where the user is in the process:
sSubs is either a string or array of strings containing macro names that will be run.
iPhase and iSteps are for identifying what stage in the process the user is at.
sArgs is either nothing, a variant, an array of variants or an array of arrays of variants.
Usage:
eHandling "Macro1",1,1
eHandling "Macro2",1,2, "Arg1"
eHandling array("Macro3","Macro4"),1,3
eHandling array("Macro5","Macro6","Macro7"),2,1, array(vbnullstring,array("Arg1","Arg2","Arg3"),array("Arg1","Arg2")
It's the last scenario that I'm having trouble getting my head round. My current code is enclosed below:
The only way I can think of getting round variable numbers of arguments is by having a case statement counting the bounds of the Argument variant. Something like:
Any suggestions or is there something I'm missing?
Thanks in advance
So I have an error handler that formats cells displays a variety of different error messages depending on where the user is in the process:
sSubs is either a string or array of strings containing macro names that will be run.
iPhase and iSteps are for identifying what stage in the process the user is at.
sArgs is either nothing, a variant, an array of variants or an array of arrays of variants.
Usage:
eHandling "Macro1",1,1
eHandling "Macro2",1,2, "Arg1"
eHandling array("Macro3","Macro4"),1,3
eHandling array("Macro5","Macro6","Macro7"),2,1, array(vbnullstring,array("Arg1","Arg2","Arg3"),array("Arg1","Arg2")
It's the last scenario that I'm having trouble getting my head round. My current code is enclosed below:
Code:
Sub eHandling(sSubs As Variant, iPhase As Integer, iStep As Integer,Optional sArgs As Variant = vbNullString)
Dim iSubs as integer
If IsArray(sSubs) Then
For iSubs = LBound(sSubs) To UBound(sSubs)
If Not sArgs(iSubs) = vbNullString Then
Application.Run sSubs(iSubs), sArgs(iSubs)
Else
Application.Run sSubs(iSubs)
Application.Run
End If
Next iSubs
Else
If Not sArgs = vbNullString Then
Application.Run sSubs, sArgs
Else
Application.Run sSubs
End If
End If
...more code...
End Sub
The only way I can think of getting round variable numbers of arguments is by having a case statement counting the bounds of the Argument variant. Something like:
Code:
If isarray(sArgs(iSubs)) Then
Select Case ubound(sArgs(iSubs))
Case 1: Application.run sSubs, sArgs(iSubs)(0), sArgs(iSubs)(1)
Case 2: Application.run sSubs, sArgs(iSubs)(0), sArgs(iSubs)(1),sArgs(iSubs)(2)
...etc
Any suggestions or is there something I'm missing?
Thanks in advance