> is there any function in vb.net to do that ??

No. However, you CAN use VB.Net to do that. All you have to do is write the

code.

Of course, first you have to analyze the problem. Programming is a

problem-solving process. Remember when you took Algebra in high school, and

they gave you word problems that you had to convert to math problems? Think

of it that way. Analysis is the process of converting a word problem to a

math (programming) problem.

>I have a string

> str="10*12*14"

> now I want the total of this value

> i.e. 10 multiply 12 multiply 14

> how do i get it ?

Okay, first we start with a string. A string has no numbers in it. We want

to parse the string, as it contains text symbols that represent both data

(numbers) and process (math operators). Now, not all text is symbolic of

numbers and math operators, such as the comma for example. So, we first need

to identify what symbols of text we will use as numbers (the easy part -

0,1,2,3,4,5,6,7,8,9), and what symbols of text we will use as operators. I

cannot assume that you are only talking about multiplying numbers here. In

fact, I would guess that you may want to be able to perform all types of

arithmetical computations, IOW adding, subtracting, multiplying, and

dividing. So, for the purpose of this explanation, I'll say that our

operators are +, -, *, and /. Possibly % and \ as well.

Okay, now for the hard part. Your example is good because it contains no

spaces. We can't necessarily assume that there are spaces in the string (you

could, but I can't, since I don't know where your string will come from).

So, we need a means to parse a string into an unknown number of known single

characters, and an unknown number of combinations of 1 or more digit

characters. What is the best programmatic mechanism for doing such complex

string parsing? Offhand, I would say a Regular Expression. So, we have

solved the first part of the problem, which is how to parse the string into

a set of separate strings.

Once we have these separate strings, we must convert the numeric string

expressions to numbers, and the operators to operators, and build a purely

mathematical expression from them. Converting strings to numbers is easy,

and I don't need to explain that. Converting the operators cannot be done

directly, so we need to use selection to identify the operators, in order to

perform math on the numbers. This can be done with a Select Case Statement.

Now we need to know the rules of math, and for arithmentic they are fairly

simple. In this case, the simplicity comes in handy. We know, for example,

that (10*2*4) is equivalent to (10*2) * 4, and is equivalent to 10 * (2*4),

etc. If all we are doing is multiplying, the order of operation is not

important. But, what if we parse 10*2+4? 10*2 = 20. Add 4 and you get 24.

But 10 * (2+4) = 60. So, we're looking for a rule, and we introduce another

possible set of characters that we may need to parse, which is parentheses.

We need to identify whether we will allow the use of parentheses to change

the default rules regarding order of operation, and if so, we need to parse

parentheses, and use them in our math, not directly, but in order to perform

the operations in the correct order. Again, we're talking about selection

here. If there are no parentheses, the default order of operations applies.

If there ARE parentheses, we have to modify the order of operations, as a

program can only perform one operation at a time.

Now that we have analyzed the problem, it's a relatively straightforward

exercise to write the code. And I'll leave that to you!

--

HTH,

Kevin Spencer

Microsoft MVP

..Net Developer

What You Seek Is What You Get.

"vips" <(E-Mail Removed)> wrote in message

news:%(E-Mail Removed)...

>I have a string

> str="10*12*14"

> now I want the total of this value

> i.e. 10 multiply 12 multiply 14

> how do i get it ?

>

> is there any function in vb.net to do that ??

> if i put it as query to database I get the result, but I want to do it in

> the code.

>

> vips

>

>

>

>

>

>

>