Connecting Tech Pros Worldwide Forums | Help | Site Map

Build a string for arithmetic operation

Mike TI
Guest
 
Posts: n/a
#1: Nov 13 '07
Nov 13, 2007

Hi all

Can I build a string for arithmetic operation. (VB NET 2005)

e.g.

I want to build an arithmetic operation from within the program as

mVariable="A1+A2+A3" (where A1=1, A2=5, A3=10) (A1,A2 & A3 are variables
declared as integers)

mTotal=mVariable (mTotal should return 16)

If there is any other way to do what I want I would appreciate if someone
can guide me.

Thank you.
Mike TI



rowe_newsgroups
Guest
 
Posts: n/a
#2: Nov 13 '07

re: Build a string for arithmetic operation


On Nov 13, 8:31 pm, "Mike TI" <tanv...@creativepk.comwrote:
Quote:
Nov 13, 2007
>
Hi all
>
Can I build a string for arithmetic operation. (VB NET 2005)
>
e.g.
>
I want to build an arithmetic operation from within the program as
>
mVariable="A1+A2+A3" (where A1=1, A2=5, A3=10) (A1,A2 & A3 are variables
declared as integers)
>
mTotal=mVariable (mTotal should return 16)
>
If there is any other way to do what I want I would appreciate if someone
can guide me.
>
Thank you.
Mike TI
I'm confused - why not just do this?

Dim mVariable As Integer = A1 + A2 + A3

Thanks,

Seth Rowe

Cor Ligthert[MVP]
Guest
 
Posts: n/a
#3: Nov 13 '07

re: Build a string for arithmetic operation


Seth,

I think that Tom and know I find that a very good thread.

:-)

Cor
rowe_newsgroups
Guest
 
Posts: n/a
#4: Nov 13 '07

re: Build a string for arithmetic operation


On Nov 13, 1:38 pm, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl>
wrote:
Quote:
Seth,
>
I think that Tom and know I find that a very good thread.
>
:-)
>
Cor
lol

I love it when you two do all the work for me! Posting links is *so*
much easier than retyping a solution.

:-)

Thanks,

Seth Rowe

Mike TI
Guest
 
Posts: n/a
#5: Nov 14 '07

re: Build a string for arithmetic operation


Nov 14, 2007

Hi

I have checked links, still apparently they do not answer my question.

I want to build an expression from within the program and then store it in a
variable like

mVariable="A1+A2+A3"

Now I want to put the result of the above into another variable like

mTotal=Eval(mVariable)

The applications should return the value as if I had entered

mTotal=A1+A2+A3

Thank you.

Mike TI


"Mike TI" <tanveer@creativepk.comwrote in message
news:OB62MmfJIHA.588@TK2MSFTNGP05.phx.gbl...
Quote:
Nov 13, 2007
>
Hi all
>
Can I build a string for arithmetic operation. (VB NET 2005)
>
e.g.
>
I want to build an arithmetic operation from within the program as
>
mVariable="A1+A2+A3" (where A1=1, A2=5, A3=10) (A1,A2 & A3 are
variables declared as integers)
>
mTotal=mVariable (mTotal should return 16)
>
If there is any other way to do what I want I would appreciate if someone
can guide me.
>
Thank you.
Mike TI
>
>

rowe_newsgroups
Guest
 
Posts: n/a
#6: Nov 14 '07

re: Build a string for arithmetic operation


I have checked links, still apparently they do not answer my question.

And why not? Could you tell us what exactly didn't work?

Also you still never answered why you are needing this and why you
can't simply do:

mTotal = A1 + A2 + A3

And avoid all the messy Eval stuff.

Thanks,

Seth Rowe

Mike TI
Guest
 
Posts: n/a
#7: Nov 14 '07

re: Build a string for arithmetic operation


Nov 14, 2007

Hellow Seth

I am converting a Payroll application that I did in MS Visual Foxpro. In
this application how an Allowance or Deduction is defined is flexible. Just
to give you a simple example:

For one company the basis can be as below:

Allowances:

ALL01 1,000
ALL02 100
ALL03 500
ALL04 45% of ALL01+ALL02+ALL03
ALL05 10% of ALL01+ALL03 if no Leave
Without Pay

For another company the basis can be as below:

Allowances:

ALL01 1,000
ALL02 100
ALL03 500
ALL04 45% of ALL01+ALL02
ALL05 10% of ALL01+ALL02+ALL03 if no Leave
Without Pay

Now I want to build the calculation for ALL04 & ALL05 from within the
program. There are some other alternates. However I was wondering if I could
do the way I was doing in VFP.

Also I was wondering if I could load a form getting the name stored in a
variable.

Thanks
Mike TI

"rowe_newsgroups" <rowe_email@yahoo.comwrote in message
news:1195039765.991732.40720@57g2000hsv.googlegrou ps.com...
Quote:
Quote:
>I have checked links, still apparently they do not answer my question.
>
And why not? Could you tell us what exactly didn't work?
>
Also you still never answered why you are needing this and why you
can't simply do:
>
mTotal = A1 + A2 + A3
>
And avoid all the messy Eval stuff.
>
Thanks,
>
Seth Rowe
>

Armin Zingler
Guest
 
Posts: n/a
#8: Nov 14 '07

re: Build a string for arithmetic operation


"Mike TI" <tanveer@creativepk.comschrieb
Quote:
Nov 14, 2007
>
Hellow Seth
>
I am converting a Payroll application that I did in MS Visual
Foxpro. In this application how an Allowance or Deduction is defined
is flexible. Just to give you a simple example:
>
For one company the basis can be as below:
>
Allowances:
>
ALL01 1,000
ALL02 100
ALL03 500
ALL04 45% of ALL01+ALL02+ALL03
ALL05 10% of ALL01+ALL03 if no
Leave Without Pay
>
For another company the basis can be as below:
>
Allowances:
>
ALL01 1,000
ALL02 100
ALL03 500
ALL04 45% of ALL01+ALL02
ALL05 10% of ALL01+ALL02+ALL03 if
no Leave Without Pay
>
Now I want to build the calculation for ALL04 & ALL05 from within
the program. There are some other alternates. However I was
wondering if I could do the way I was doing in VFP.
You must write a parser and interpret the input on you own.
Quote:
Also I was wondering if I could load a form getting the name stored
in a variable.
Whenever I read this, I wonder how a class name, that is only relevant to
the developer, which means it gets out of interest after the source code has
been compiled, how this class names makes it's way through to run-time as
the content of a variable. The only exception is whenever the class name is
also stored externally. In this case, I recommend writing a Select Case
statment based upon the string and create the corresponding instance. This
enables the compiler to check the class name at compile time and it is more
straight forward than using Reflection (see System.Activator.Creatinstance).


Armin

Closed Thread


Similar Visual Basic .NET bytes