Re: Who yields - client or developer? Your opinion

From: Marshall Barton <marshbarton_at_mindspring.com>
Date: Sun, 02 Jun 2002 10:38:23 -0500
Message-ID: <gnckfusgrnf9squg04t6urs90ahv6bpb9d_at_4ax.com>


Graham Bellamy wrote:

>> I'm not sure I followed all this, but I think If you create
>> a table with the units in one field and the expression in a
>> second field.
>> Units QtyFormula
>> L/Sq.m/mm [Area] * [Rate] * [Thickness]
>> L/Sq/m [Area] * [Rate]
>> kg/Sq.m/mm [Area] * [Rate] * [Thickness]
>> kg/Sq.m [Area] * [Rate]
>> Sq.m/L [Area] / [Rate]
>> Sq.m/kg [Area] / [Rate]
>>
>> then you could Join that to your table/query on the units
>> field and calculate the QtyFormula with something like this:
>>
>> QtyRate: Eval(Replace(Replace(Replace(QtyFormula, "[Area]",
>> [Area]), "[Rate]", [Rate]), "[Thickness]", [Thickness]))
>>
>> Setting up to use a Replace function is different in
>> different version of Access. For A97 and earlier, you have
>> to write your own, in A2K you have to write a UDF that just
>> calls the built in Replace function and in AXP you can just
>> use the built in Replace function.
>
>Ok, that sounds like it could be a solution. Thanks for the tip. I am developing on Ac97,
>however the final product will be run on Ac2000, so I'll have to make my own function. I
>can set to doing this, but to save reinventing the wheel, if anyone out there has such a
>function already written, and is willing to share, could they point me in the right
>direction. If it's possible to do this, it would be great to have on which accepts
>multiple 'Find/ReplaceWith' pairs, so as to not need to repeat the function multiple
>times.

Here's my A97 variant of Replace:

Function Subst(Original As Variant, Search As String, _

                            Replace As String) As Variant
Dim pos As Long

    Subst = Original
    If IsNull(Subst) Then Exit Function
    If Len(Search) > 0 Then

        pos = InStr(Subst, Search)
        Do Until pos = 0
            Subst = Left(Subst, pos - 1) & Replace _
                            & Mid$(Subst, pos + Len(Search))
            pos = InStr(pos + Len(Replace), Subst, Search)
        Loop

    End If
End Function

The A2K wrapper function is just a one line call to the built in Replace.

If you want to create a function to do your specific three replace operations with a single call (probably a good idea) then, off the top of my head, I would think, depending on the details of your specific needs, it would be something like this air code:

Public Function CalcQR(Original As Variant, _

                A As Variant, R As Variant, T As Variant) As Variant Dim strExp As String

	strExp = Subst(Original, "[Area]", Nz(A, ""))
	strExp = Subst(strExp, "[Rate]", Nz(R, ""))
	strExp = Subst(strExp, "[Thickness]", Nz(T, ""))
	CalcQR= Eval(strExp)

End Function

And then the query field would be:

QtyRate: CalcQR(QtyFormula, [Area], [Rate], [Thickness])

--
Marsh
Received on Sun Jun 02 2002 - 17:38:23 CEST

Original text of this message