In the TextBox1 I have the following numbers:5 4.1 6.23 0 0 7 7.924
http://i53.tinypic.com/e0s5yh.png
Possible to calculate all the numbers in this way?
like replace all the "space" in "+" and get the answer or something?
Printable View
In the TextBox1 I have the following numbers:5 4.1 6.23 0 0 7 7.924
http://i53.tinypic.com/e0s5yh.png
Possible to calculate all the numbers in this way?
like replace all the "space" in "+" and get the answer or something?
I like your thinking.. maybe in the next version of VS :bigyello:
For now though, I would split the values into an array. Then you can loop through the results and add them up.
VB Code:
Dim TextboxText As String = "5 4.1 6.23 0 0 7 7.924" Dim ArrayOfValues() As String = TextboxText.Split(" ") Dim Sum As Double = 0 For Each Value As String In ArrayOfValues If Double.TryParse(Value, Nothing) Then Sum += CDbl(Value) Next MsgBox(Sum)
It's actually possible in 2005, and may be possible in other versions as well :-
It will also cope with brackets, for example :-Code:Dim TextBoxText As String = "5 4.1 6.23 0 0 7 7.924"
Dim Formula as String = TextBoxText.Replace(" ", "+")
Dim Evaluator As New DataTable
Dim Result As Double = 0.0
Result = Convert.ToDouble(Evaluator.Compute(Formula, ""))
MessageBox.Show(Result.ToString)
:DCode:Dim Formula As String = "5+(3*6)"
Cool, I'm liking that DataTable function InetiaM. I bet I will be able to find a use for it at some point in the future. :)