passing operator as variable

T

TonyT

Hi,

I have a form for Importing parts lists into my database, however the format
of each is different, some have just List price & some list & cost, so I have
a series of Comboboxes so the user can select column name, operator +_*/ and
a textbox for a value between 0-100 (%).

I am trying to find a way to display sample data in text boxes to show the
results of the selected calculations, but I can't figure out how to pass the
operator as a variable.

Sample code;

Me.txtExCost = (Me.lstSample.Column(lngCol)) & strOpCost & (sglPerCost *
(Me.lstSample.Column(lngCol)) / 100)

returns '2.85-0.285' not 2.565 where
(Me.lstSample.Column(lngCol)) returns 2.85
strOpCost = -
sglPerCost = 10

How do I get round this?
 
M

mscertified

You cannot perform arithmetic using an operator in a variable. You will have
to 'decode' the operator in code e.g.
Function OpResult(op1 as long, oper as string, op2 as long) as long
select case oper
case "+" OpResult = op1 + op2
case "-" OpResult = op1 - op2
end select
end function

-Dorian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top