I finally had the opportunity to use the SetRuntimeParameter() Function today.
For a monthly payroll report, we have to some times split up the weeks between months depending on when the paydate falls. The report shows 5 weeks, but the first two weeks may belong to one month and the last three may belong to the next month.
Thus I have Hour Type formulas such as:
wk1OT + wk2OT + wk3OT + wk4OT + wk5OT 'Ovr Time
wk1DT + wk2DT + wk3DT + wk4DT + wk5DT 'Dbl Time[/font][/quote]Prior to Ver8, this led me to having to edit the model A LOT, depending on which weeks needed to be totaled.
I finally came up this idea. Set 5 numeric runtime parameters, (wk1...wk5), if the parameter equals 1, include the week, if it equals 0, do not include it.
Now my formulas look like this:
If(wk2, wk2ST, 0) +
If(wk3, wk3ST, 0) +
If(wk4, wk4ST, 0) +
If(wk5, wk5ST, 0)
If(wk1, wk1OT, 0) +
If(wk2, wk2OT, 0) +
If(wk3, wk3OT, 0) +
If(wk4, wk4OT, 0) +
If(wk5, wk5OT, 0)
If(wk1, wk1DT, 0) +
If(wk2, wk2DT, 0) +
If(wk3, wk3DT, 0) +
If(wk4, wk4DT, 0) +
If(wk5, wk5DT, 0)[/font][/quote]This lets me be creative in which weeks I can add, I can pass parameters to wk1, wk3, & wk5, if I so desired.
In my code, I have a form with the five weeks as check boxes and I pass their values to an array like this:
garWeeks(5) = "wk5=" & myform.chkbx5.value[/font][/quote]My code is a little more streamlined using a For..Next loop through the controls rather than hardcoding like that above.
I then pass the array to to a routine that seperates the field (runtime parameter) and the value:
Dim strItem As String
Dim strField As String
Dim strValue As String
Dim intPos As Integer
Dim idx As Integer
Dim intCnt As Integer
Dim retVal As Integer
On Error Resume Next
intCnt = UBound(garWeeks)
If intCnt = 0 Then Exit Sub
For idx = 1 To intCnt
strItem = garWeeks(idx)
intPos = InStr(strItem, "=")
If intPos = 0 Then Exit Sub
strField = Left(strItem, intPos - 1)
strValue = Mid(strItem, intPos + 1)
retVal = mapMonarch.SetRuntimeParameter(strField, strValue)
End Sub[/font][/quote]Pretty nifty, eh?
Send 1 Character parameter like this:
My formulas would now look like such:
If(Substr(parmWeeks,2,1)="1", wk2ST, 0) +
If(Substr(parmWeeks,3,1)="1", wk3ST, 0) +
If(Substr(parmWeeks,4,1)="1", wk4ST, 0) +
If(Substr(parmWeeks,5,1)="1", wk5ST, 0)
etc...[/font][/quote]That's about it. Unless someone else has another idea on how to do it differently?