![]() |
evaluate a function
I have a function which contains text and numbers which I want t evaluate.
For example, 3*x+3+y I use replace to replace the x with a number, say x = 3, then 3*3+3+y I want the answer to be displayed as 12+y I can't use the & symbol for some resons which I don't want to go through. Is there a way to get the above result without the use of &. |
evaluate a function
Here's one way:
Public Function Test(ByVal x As Integer) As String Dim arr(1) As Variant Dim sResult As String arr(0) = 3 * x + 3 arr(1) = "+ y" sResult = Join(arr) Test = sResult End Function ---- Nick Hebb BreezeTree Software http://www.breezetree.com |
evaluate a function
Thanks Nick
Your solution works but this is not what I wanted actually I have changeable string with x and y values and I just want the numbers to add up and the texts remains. I don't have a fixed equation. Say I have this equation, 3+ 4*y-3*(5*x-2) I want it to be displayed as 4*y-15*x+9 "Nick Hebb" wrote: Here's one way: Public Function Test(ByVal x As Integer) As String Dim arr(1) As Variant Dim sResult As String arr(0) = 3 * x + 3 arr(1) = "+ y" sResult = Join(arr) Test = sResult End Function ---- Nick Hebb BreezeTree Software http://www.breezetree.com |
evaluate a function
OK, I gotcha now.
This is a common CS problem often used in data structures classes to teach stacks. You can probably find loads of samples in the internet by searching on the terms "stack calculator" and maybe throw in some terms like "visual basic -.net" and "example" or "sample" to narrow it down a bit. Otherwise, the answer is too long (and time consuming) to figure out and post back here. |
All times are GMT +1. The time now is 04:20 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com