ilan Expert Licensed User Longtime User Nov 3, 2015 #1 hi i would like to make a math calculation from a given string like: B4X: dim mathproblem as string = "(25*2)-4" log(mathproblem) and i should get = 46 i found a great VB source that is really working very well but i dont know how to convert "redim" and "redim preserve" to b4x language i will attach the b4j project (vb code is inside) can someone make a working b4x code from it?? thanx Attachments mathString.zip 3.3 KB · Views: 364
hi i would like to make a math calculation from a given string like: B4X: dim mathproblem as string = "(25*2)-4" log(mathproblem) and i should get = 46 i found a great VB source that is really working very well but i dont know how to convert "redim" and "redim preserve" to b4x language i will attach the b4j project (vb code is inside) can someone make a working b4x code from it?? thanx
R Roycefer Well-Known Member Licensed User Longtime User Nov 3, 2015 #2 Have you looked at the ExpressionEvaluator and B4X Evaluator libraries? https://www.b4x.com/android/forum/threads/class-b4x-eval-expressions-evaluator.54629/#content Upvote 0
Have you looked at the ExpressionEvaluator and B4X Evaluator libraries? https://www.b4x.com/android/forum/threads/class-b4x-eval-expressions-evaluator.54629/#content
ilan Expert Licensed User Longtime User Nov 3, 2015 #3 Roycefer said: Have you looked at the ExpressionEvaluator and B4X Evaluator libraries? https://www.b4x.com/android/forum/threads/class-b4x-eval-expressions-evaluator.54629/#content Click to expand... no i have not... 2 days i am struggling with it thank you very much @Roycefer Upvote 0
Roycefer said: Have you looked at the ExpressionEvaluator and B4X Evaluator libraries? https://www.b4x.com/android/forum/threads/class-b4x-eval-expressions-evaluator.54629/#content Click to expand... no i have not... 2 days i am struggling with it thank you very much @Roycefer
MaFu Well-Known Member Licensed User Longtime User Nov 4, 2015 #4 You can also use MF_MathParser which is part of my jMFLib. Upvote 0
Daestrum Expert Licensed User Longtime User Nov 5, 2015 #5 You could also use my Nashorn library define a js function like B4X: function evaluate(a,b){ return new java.lang[b](eval(a)) } This also allows you to specify the data type for the return so you call it by B4X: script.invoke("evaluate",Array("Math.sqrt(12*(14-6)/7)","Float")) And in this case it will return a float value. (You can use Double,Float,Integer,String etc) Upvote 0
You could also use my Nashorn library define a js function like B4X: function evaluate(a,b){ return new java.lang[b](eval(a)) } This also allows you to specify the data type for the return so you call it by B4X: script.invoke("evaluate",Array("Math.sqrt(12*(14-6)/7)","Float")) And in this case it will return a float value. (You can use Double,Float,Integer,String etc)
ilan Expert Licensed User Longtime User Nov 5, 2015 #6 Daestrum said: You could also use my Nashorn library define a js function like B4X: function evaluate(a,b){ return new java.lang[b](eval(a)) } This also allows you to specify the data type for the return so you call it by B4X: script.invoke("evaluate",Array("Math.sqrt(12*(14-6)/7)","Float")) And in this case it will return a float value. (You can use Double,Float,Integer,String etc) Click to expand... thanks @Daestrum, but the class of erel is exactly what i needed because i am developing a b4i tool and his class runs on all b4x products. i use his class also with b4j where i build some assisting tools for my new app. Upvote 0
Daestrum said: You could also use my Nashorn library define a js function like B4X: function evaluate(a,b){ return new java.lang[b](eval(a)) } This also allows you to specify the data type for the return so you call it by B4X: script.invoke("evaluate",Array("Math.sqrt(12*(14-6)/7)","Float")) And in this case it will return a float value. (You can use Double,Float,Integer,String etc) Click to expand... thanks @Daestrum, but the class of erel is exactly what i needed because i am developing a b4i tool and his class runs on all b4x products. i use his class also with b4j where i build some assisting tools for my new app.