Click here to Skip to main content
15,900,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can we get output from "(5000+400-300)*12/100" in vb.net but output should be in numeric format not string format.

Output should be 612
How can i get it bacause array is niot working here.
Posted

You need to evaluate the expression. Have a look at this: Runtime C# Expression Evaluator[^] - it's in C#, but all the principles hold the same for VB.
 
Share this answer
 
there are 2 ways,
1. create function to resolve string & evalute it e.g. Runtime C# Expression Evaluator[^] as given in solution 1

2. if you are using sql server also, then
VB
equ= "(5000+400-300)*12/100"
cmd.commandtext="select " & equ
dim ans=cmd.executescalar()

Happy coding!
:)
 
Share this answer
 
Comments
Rohit rgdon 31-Aug-12 6:20am    
But I am Using postgresql.

Thanks and Regards
Rohit Gupta
Aarti Meswania 31-Aug-12 6:29am    
sorry, no experience for postgresql
but can you execute query 'select 1+2' = 3 in postgresql?
if it is then it will allow to execute 'select (5000+400-300)*12/100' also
please reply working in postgresql or not?
Rohit rgdon 31-Aug-12 6:33am    
No This Query is not working in postgresql.so I have no posibility to execute it in backend???????
Aarti Meswania 31-Aug-12 6:38am    
see this link,
http://www.postgresql.org/docs/8.0/static/functions-math.html
http://www.postgresql.org/docs/7.3/static/functions-math.html
http://www.postgresql.org/docs/7.1/static/functions-math.html
it shows possible
try without writing select just '1+2'
postgresql is database like sql so it is backend check how to execute equation in that else you have to use function in VB.net
in sql 'select 1+2' is working that's why i suggest
Rohit rgdon 31-Aug-12 6:38am    
But it is executing select 1+2. not 'select 1+2'
My question is solved .the solution is you have to make a function for like this (select '5000+1000'). which accept this string and calculate it then return value to you in numeric format.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900