Evaluating Dynamic String Formulas In .NET?
Dec 5, 2010
I'm working on a project where I need to evaluate some formulas in VB.NET. I've been using the MS Script Control to evaluate some of the simple logical/mathematical formulasHowever, I'm now faced with dealing with string expressions that set variables in my program to certain values. So, for example, let's say I've got the following:
Dim netPrice As Decimal
Dim expressionFormula As String = "netPrice = 0"
[code]....
View 3 Replies
ADVERTISEMENT
Nov 27, 2010
I extracted text from a third party software application. All the text is now in string and correct in my Form Labels.
Text look like
Label1
0.25
Label2
[Code]....
But I can't convert the labels from string to double or Decimal.
View 9 Replies
Feb 17, 2010
Does anybody know of a call in vb.net that will evaluate a string expression. For example, how would one evaluate the expression "(1+2)*(3+4)"?I've looked all over and it seems that people are writing their own parsers. There has to be a better way. After all these years, VB.Net must have something that will take an expression and evaluate it.
Dim strMyExpression as string = "(1+2)*(3+4)"
msgbox( VBEvaluate(strMyExpression))
and the result would be 35.Also, when will microsoft start to use google as the search engine for these forums? Bing really sucks. Searching for "Evaluating a string expression in VB.net" gives the most bizarre links.
View 7 Replies
Nov 18, 2010
I am trying to figure out a way to set a string equal to vb code and then run that string as a line a of vb code.
for example
set string x = "TextBox1.Text =
"test1".ToString"
[code]....
View 4 Replies
Aug 27, 2009
I have a application that allows the user to enter a series of nested filtering commands. E.g "Name starts with x or ((Description contains y or Property1 is On) and Property2 > 100)"
I can preprocess this and distill it down to a string in the form of an expression of True and False's ie, To "True or ((False or True) and False)" Is there a simple way to have this final expression evaluated without having to write a complex evaluator myself?
I have seen a method of evaluating this by compiling a dummy function at runtime but as I need to process this against possibly thousands of records that solution is too slow.
BTW These are not all fields in a database so I cannot use Queries or SQL etc.
View 2 Replies
Jul 7, 2011
Is there a method that allows me to evaluate a mathematical expression in a string? Example (Not actual Code):
Input = "2+2"
Output = SomeMethod(Input)
Output = 4
Update: Nevermind, I found a way around it by using DataTable.Compute.
View 1 Replies
Nov 20, 2010
there is a datagridview, which will display Group Name in first column, Variables in second column.Users will populate it manually. will select a group name in first column, variable in second column. in similar, for some count of rows the group name remains similar, with different variables in second column.There may be different groups with lot of variables in second columns.our requirement is to insert a formula where ever its needed by the users.like getting subtotals at each level of groups.Also in case if they needed to have subtotal after two or three groups they must be able to define the row a formula to add those groups sum.
View 5 Replies
Mar 22, 2012
Say I have a string LineOfText = "UserName1 Password1 UserName2 Password2" how would I just grab the last word (Password2)
View 4 Replies
Feb 1, 2011
(using VB2008)I was wondering if it's possible to implement dynamic (runtime) formulas between objects and properties. My inspiration is Excel, where any cell can have a hardcoded value or be a function of other cells. So via analogy of a property acting like a cell, depending upon the situation, I would like to either give it a defined value or make it a function of other properties of objects of the same type.
There seem to be two basic levels of functionality, 1) the dependent property recalculates its value every time it's accessed, or better is 2) it detects when its input properties change value and recalculates itself only once (as in Excel). But so far I've failed to find any way to do either with ordinary properties. It seems like I would either have to turn each property into a class (and use events, references to parent properties, etc), or use reflection heavily. Either way I feel like I'm going off the beaten path and making things complicated. Has anyone done something like this?
View 8 Replies
May 4, 2011
Visual Basic 2010.I excel in transferring reports on problems in formulas..[code]
View 3 Replies
Oct 15, 2009
i want to autofill a formula down a column of cells in excel. to manually do this, i would double-click the little black square at the bottom right of the cell, but i cannot figure out a way to do this using a macro.
View 1 Replies
Feb 6, 2011
What I'm trying to do is extract values, colors, comments, and any formulas for a range of cells in a given worksheet. The ultimate goal is convert a spreadsheet someone has been using as a database into Access tables.
worksheet.Cells(row,column).Value 'extract value WORKS
worksheet.Cells(row,column).Font.ColorIndex 'extract color index WORKS
worksheet.Cells(row,column).Comment.Text 'extract comment WORKS
worksheet.Cells(row,column).Formula 'extract formula DOES NOT WORK
The return value for .Formula is same as .Value. That's not what I need. I'm looking for a textual representation of the formula (to extract rate information embedded within the formula).
View 1 Replies
Aug 2, 2011
I have a range of data that I want to replace with new data.So, I want to clear the old data and replace it with new data.But the formulas in the old data are also required to work on new data.[code]...
View 2 Replies
Dec 27, 2011
We have an automatic process that opens a template excel file, writes rows of data, and returns the file to the user. This process is usually fast, however I was recently asked to add a summary page with some Excel formulas to one of the templates, and now the process takes forever.
It successfully runs with about 5 records after a few minutes, however this week's record set is almost 400 rows and the longest I've let it run is about half an hour before cancelling it. Without the formulas, it only takes a few seconds to run.
Is there any known issues with writing rows to an Excel file that contains formulas? Or is there a way to tell Excel not to evaluate formulas until the file is opened by a user?
The formulas on the summary Sheet are these:
' Returns count of cells in column where data = Y
=COUNTIF(Sheet1!J15:Sheet1!J10000, "Y")
=COUNTIF(Sheet1!F15:Sheet1!F10000, "Y")
[Code].....
View 3 Replies
Dec 2, 2011
So I am trying to evaluate 3 conditions in an if statement. Its not working how I would assume it should. I basically want to do this:vb.net If PGN = &HEF007E And PGNData(0) = &H58 And (PGNData(1) And &H40) = &H40 Then IgnOn = True Else IgnOn = False If I write it in that manner it gives inconsistent results. If I workaround by writing it this way it works perfectly:vb.net If PGN = &HEF007E And PGNData(0) = &H58 Then If (PGNData(1) And &H40) = &H40 Then IgnOn = True Else IgnOn = False
View 1 Replies
Mar 20, 2011
how to create this certain program. In short, I must calculate the velocity of a ball thrown in the air after 1, 2, and 3 seconds. The formula for this is: -16t^2 +velocity(t)+height. the height for the ball is 5 feet per-second. So after defining each textbox of 1 sec, 2 sec, and 3 secs (Dim stuff) I need the button click to run through the formula then display the result for each second. How would I do this?
View 6 Replies
Aug 26, 2011
My DGV's last visible column in a boolean. I am needing to go through each row and determine if the value of dgv item bFlag is true then turn the row back ground red. Here is my start of it. It appears to be only making one loop then giving the message box.
Private Sub EvalGrid()
BindDGV(dgvResults)
Dim cnt As Integer = dgvResults.Rows.Count
[Code]....
View 9 Replies
Jun 19, 2009
I store a formula in the database such as the following:GrossIncome+(Overtime/0.5)-Deductions=BasicNetIncome
I am able to substitute the string representations with actually values entered, thus:1000+(150*0.5)-100=BasicNetIncome
Then I remove the '=BasicNetIncome', thus:
1000+(150*0.5)-100
How can evaluate the above equation to return a result:
[Code]...
View 1 Replies
Apr 4, 2011
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
With Me.PrintForm1
[Code]....
View 6 Replies
Jun 14, 2011
I'm looking to create an inline function (method) inside my NVelocity template. The solution to this appears to be to use Velocimacros. So, I mocked up the following template to test:
#macro( getOutput $one $two $three )
<td>$one</td>
<td>$two.Item2</td>
<td>$three</td>
#end
[Code] .....
When I run the template, the problem I'm having is that the output from the macro parameter $three is literally "$item.Item3" instead of evaluating to #3/3/2003#. (BTW - this happens with any of the 3 items in the tuple if they are passed with the .Item call, so it isn't about the data type). I can make a variable and pass it just fine ($one1). I can pass the tuple itself and call the .Item property inside the macro ($item.Item2), but for some reason I cannot call the .Item property when passing the argument to the macro.
View 1 Replies
Apr 8, 2009
We are working on a poker game as a class project. My part is to evaluate and then determine the value of a players hand. We are evaluating from highest to lowest (ie. determining whether the player has a straight flush, 4 of a kind, full house, flush and then going all the way down to a high card only "worthless hand"). My part is evaluating the 2 pair, 1 pair, and nothing hands. The hand will be a two-dimensional array with the row(0 thru 12),column (0) containing the numeric "face" value of the cards and the column(1) containing the value assigned to the suite (1=clubs, 2=diamonds,3=hearts,4=spades). I have NO IDEA where to even begin this evaluating procedure.
View 4 Replies
Apr 16, 2010
I am making a checkers program and I am in the phase of starting to evaluate jumps. This is what I currently have so far and allow me to fill you in a bit before you look at the code. Checker pieces are white/green. Each checker is created as a label at runtime and in the tag property a struct is held that possesses all of the information reguarding current and previous checker state.
The problem I am having is that as this sub runs each opposing checker is evaluated for jump capabilites which is all fine and dandy. It is even alright that currently if a jump is executed that the same side will continue to evaluate through the sub looking for additional jumps and if they are found they will be made because that is how it is currently coded. What I am trying to do is find a way to evaluate each piece that can jump. So if checker1 can only make one jump and checker2 can make a triple jump checker2 needs to be the guy making the jump and I honestly don't know how do start that. I am forseeing global vars being created to hold information or even a structure and taking the one that changes the most. If two checkers can only make 1 jump then I will rand the one that gets to jump (not looking to win any awards for AI here). Anyhow, any suggestions on how to start this, at least saving the information throughout the sub even if it is called recursively?
[Code]...
View 4 Replies
Apr 23, 2010
how do i give a string a dynamic name i.e. in the below for loop i want to create a string name using the item in question.
For i = 1 To NumNames
Dim userName & i.tostring As String
....
Next
View 3 Replies
Apr 5, 2012
I'm working with visual studio 2008 developing software for windows CE 6.0, compact framework.I'm having this "strange?" trouble with isNumeric method. Is there another better way to do this job? Why is getting me an exception? (two in facts...both of type FormatException)
dim tmpStr as object = "Hello"
if isNumeric(tmpStr) then // EXCEPTIONs on this line
// It's a number
else
// it's a string
end if
View 2 Replies
Sep 22, 2009
[URL]From what we can see on MSDN, it says to be careful about which expressions we put as they change from language to language. My question is: what are the supported languages for writing those expressions? If various languages can do it, how does it detect which language is being used?I've made my class in CLI, and coded the expression in c#, being that it works. I've tried in c++/CLI, but that way it doesn't.
Here is my code:
[DebuggerDisplay("z = {ToString()} Norm = {System.Math.Round(Norm,2)} Angle = {System.Math.Round(Angle, 2)}")]
Now, trying it the c++/CLI way:
[DebuggerDisplay("z = {ToString()} Norm = {System::Math::Round(Norm,2)} Angle = {System::Math::Round(Angle, 2)}")]
My assumption is that it will always read the expression as c# code. Is this true?
View 2 Replies
Jun 12, 2009
Im currently working on a project to build an application for Windows Mobile 6.I have a SQL query string:
Dim connectionString2 As String = "Data source = " + path + "HC.sdf"
Dim cmdText2 = "SELECT * FROM BigC_Rangsit_0_"
I want to substitute the table name ie. BigC_Rangsit_0_ with a variable which contains the table name.say, during runtime the user selects a table from the dropdown list , that variable should be substituted with the selected table name dynamically in the SELECT statement.
Dim cmdText2 = "SELECT * FROM "selected table name VARiable""
well, I need the right syntax for this.
View 8 Replies
Jul 14, 2011
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System.Configuration
Module Module1
[code].....
this is my connection string on my pc how can i make this as a dynamic connectionstring so i cant remove the db and get a new connectionstring?
View 9 Replies
Jan 7, 2012
I am trying to create a dynamic string statement[code]...
View 7 Replies
Nov 12, 2011
I'm making a calculator that would read a "string" from a textbox and parse it and follow Order-of-Operations/PEMDAS on the string. I have a couple of questions:
1) What would be the best way to parse the code so that it won't just take a "left expression" and "expression" and perform the operation on those 2.
2)How would I be able to make is so that 0 is considered valid, but prevent a 00 or 020 or 002 to be inputed.
View 3 Replies
Jul 11, 2011
I have an EnumerableRowCollection that looks like the following:
VendorCode | GroupType | Variance
01165 G .16
01165 G .16
01165 CH .16
01165 CH .18
07754 G .25
07754 G .25
07754 G .39
Essentially, this is a massive list of vendor codes, their groups, and price variances. I need to compose a query that will create a distinct list vendor codes and group types. The catch, however, is that I need to evaluate all of the variances associated with that particular VendorCode/GroupType to see if they are all the same - it they are not, I need to return some way of signifying that the group has a "custom" variance, otherwise it needs to return the value (ie: if they are all .16, then return .16, if there are multiple values, return "custom")
The result would look like this, based off of the list I showed above.
VendorCode | GroupType | Variance
01165 G .16
01165 CH custom
07754 G custom
I have no trouble getting a distinct list of VendorCode/GroupType - this is what I have so far:
Dim distinctList = From q In query Select q.VendorCode, q.GroupType, (evaluated q.Variance here?) Distinct
(where "query" is an EnumerableRowCollection(Of (anonymous type)))
I'm at a loss, though, on how to evaluate the variance property to get the result that I need?
View 1 Replies