Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Evaluate String As An Expression

u can do the above in javascript using the eval function is it something similar in vb?

say i have 2 objects with names pots1 and pots2 these 2 objects have one property called name i want to do something like the following

for i=1 to 2
debug.print evalsomething( "pots" & i & ".name")
next i

is it possible ?


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Evaluate A String Expression Like A Math Function
I feel like such a stupid newbie, but isn't there a VB function that will evaluate a string expression like a mathematical function?

Eval("5+1-14") or some such thing?

Or am I on crack again?



If Or Only Evaluate First Expression
This code gives me an Invalid use of null error
Dim vData As Variant
vData = Null
If IsNull(vData) Or Trim$(vData) = "0" Then
'Do something
This is due to the second expression evaluating.
Is there a construct that will evaluate the first expression (IsNull) and if it is true, ignore the second expression as it is redundant in the logic?

Sort of like the || vs | shortcut operator in Java?

Nested Ifs will get around it if there is no equivalent.

Evaluate Expression?
How can I evaluate an expression, so as I can type "Label1.caption = "hi"" and it will do that... ? (It won't be .caption, iot will be just like VB's debug window...)


Help Me Force Vb To Evaluate Something As An Expression PLEASE?
Form1.Caption = intdigit1 & stroperator & intdigit2 with stroperator being a "+, -, or * sign" does not evalute as an expression. It merely gives text putout. form1.caption = 5 + 7 gives the expressions output. Is there a way to force vb to view something as an expression?

Evaluate Numeric Expression
Is there any way to easily evaluate a numeric expression in VB. For example, in a textbox, a user enters 3*4 + (2^5). Of course it would be simple to code this expression into the program, but if a user enters it as a string, is there a simple way so solve the expression. I'd like to avoid writing a big long function if something already exists.

Evaluate Mathematical Expression
Basically, i want the user to be able to input something like "1+1" in a textbox and then be able to calculate what that is. I know that this can be done in other languages using eval or a similar function, but i can't find one to do it in vb.

If Statements - Need A Keyword To Evaluate One Expression At A Time
If boolx and booly then
'do something
end If

I want my program to evaluate boolx. If boolx is true, it evaluates booly. However, if boolx is false, i don't want it to evaluate booly at all. Is there a keyword to do this, or do i have to break this up into two if statements?

RESOLVED .Empty String, Null String, How To Evaluate
Placed my question in ActiveX board.
But no one is looking over there.

My question

Thanks for helping me out.

Evaluate String As Variable

I'm trying to do something like:
Call fpDisplayMessage(10)

Function fpDisplayMessage(ByVal sMsgNr as integer)
Const msg10 = "aaaaaa"
Const msg20 = "bbbbbb"

MsgBox Eval (msg & Str(sMsgNr))

End Function

But obviously in VB 6.0 I do not have an eval function.....


Evaluate A String As Code?
I've tried using both the ScriptControl and Access methods of using Eval(), and neither of them works for my application. See below:

Public Function Find(data As Collection, field As String, search As String) As myObj

For Each myObj In data
If (Eval("myObj." & field) = search Then
Find = myObj
Exit Function
End If
Find = -1
End Function

Because the Eval() is in its own environment, it has no clue that myObj exists. How can I get around this?


Evaluate Math Expressions In String
Hi all!!!

Is there a way to evaluate math expressions provided in a string?

For example, maybe we can build a math editor. In a textbox a user could write something complicated and with something (function, api, ...) wed solve it.

Any clue?

This isnt an easy one, its not obvious.

Evaluate String Expressions With Vba6.dll And EbExecuteLin
Hello !
Please answer me:
How can I use, for evaluating string expresion, the file vba6.dll (and EbExecuteLine). Any information about that (links, attachments, examples) ?
Thank you !

(To forum administrators
I think that this question is related to this subforum. Sorry if not and for the repetition.)

Which Vb Function Can Evaluate A Literal String Like A Variable?
when i type this

tempData = request.form("tempStr")

i want it to evaluate like this

tempData = request.form(tempStr)

i know there is a function to do it, i just can't remember what it is!!

thanks for any info!

Storing Expression In String
I'm trying to store an expression in a string, which you sould say thats easy,
string = "expression", but the problem is the expression i am trying to store also has a " inside it. so it sees string = "expre"ssion" and thinks everything after the 2nd " isn't to be included. how do i avoid this?

Do You Know Eval One Expression String In Pl/sql
I have a expression in oracle as

I want in pl/sql transform my expression to number...
Do you know one function in oracle 8i that I can use to do it??

I have tried with translate and later TO_NUMBER but when I try to associate with a number var I get in error.
I need your help u

Executing A String Expression
ok, this is probably easy, and i couldnt find an answer by searching, so here it is:

i have a string expression (for example: "5 * 7 +4") and i would like to know how to get my project to evaluate it and put it in a variable.

pleeze help


Convert String To Expression
Maybe there is another solution (other than converting to expression), but here is what I am trying to do.

I have multiple comboBoxes that need to be filled with an array of numbers (font size choices). They all need to be filled with the same array, but some are on different forms and they all have different names.

Currently I have something like this:

VB Code:
Public Sub fillFontSizes(callerForm As Object, Index as Integer)  ...  ' fill font arrray using callerForm.fontSizes(i).AddItem  ...End Sub

I would perfer to do it with something like this:

VB Code:
Public Sub fillFontSizes(callerForm As Object, callerObj AsObject)  ...  ' fill font arrray using callerForm.callerObj.AddItem  ...End Sub

The problem arrises when I try to pass cboPreviewFontSize to the sub. It passes the default propertu of cboPreviewFontSize (which is .Text I think). What I need to use is the .Name property but that passes a string.

My question is: Is there any way to convert that string to an expression and use is in the expression above (the 2nd one)?

Evaulating String Expression
How will we evaulate an expression inside a string variable

we have eval(strExpression) in vbscript what about VB?

Evaluating String Expression??
Hello, I'm new to VB-- and have this question:

for example if I have a textbox that contains this string "2+2": How can I evalute it and return the answer of that? In python you can just do eval("2+2"), but how do I do this in VB?

Hope anyone understand what I mean. Thank you


String Containing Math Expression

Having a variable expressing for example the following string: "4+6*2"

How can i get the mathematic result from that string?

Because the string is containing two no-numeric characters, it is not possible just to convert the string to an integer.

Regular Expression NOT Equal To String
I'm trying to write an expression that matches any country code NOT equal to USA. Heres what I have, it doesn't work.

regexpr1 = "[01] 1st Order?: (NO|UNSURE)(.*
){1,}[15] Country: [^U][^S][^A]"

The above doesn't match UK or SIN or AUS because they both start with U or S or A. How can I make it so it tries to match exactly against USA? I'm struggling with this one...

String Search For Regular Expression
I am trying to search a string for the first occurance of a number. Now I could write a do loop and look character by character but I was wondering if the Instr function can use regular expressions. Looking through the message board I see some mention of regular expressions with .Pattern but I don't know where to use .Pattern. Ideally I would like the following to work.

strData = " C1, C10, C2, C3, C100"
pos = InStr(strData, [0-9])

But i probably have to do the following

strData = " C1, C10, C2, C3, C100"
pos = 1
Do Until IsNumeric(Mid(strData, pos, 1))
pos = pos + 1
If pos > len(strData) then Exit Do

String Manipulation Using Regular Expression

How to find first non space character in a string.

Let's say I have a string:

VB Code:
sMainExpression = "    test 7 expression"

here, I want to find the first non space character. In the above example, it is 5.

Similarly, how to find the first numeric character. In the above example, it is 10.

Thanks in advance.


Checking The Syntax Of A Expression String

I need a function to check the syntax of a expression string. e.g.:
((a>1 and b<2) or (d="2")). It's the same as in MS Access Query builder. When we work at "Criteria line" in the Grid. If we type a incorrect expression, we will receive an error message).

Are there anybody know how to build this function in VB? or Do we have a API function do this? or How can I inherit this from MS Access?

Thanks in advance,

Trung Luu

Any Function To Convert A String To Expression ?

I want to know if there is a function to convert a string to an expression?

Like in this exemple, I want the message box to return 7, not "a + b", is it possible ???

Private Sub Command1_Click()
Dim a As Integer
Dim b As Integer
Dim sFunc As String

a = 5
b = 2

sFunc = "a + b"

MsgBox :o :o anyFunction:o :o (sFunc)

End Sub



Arena Sees A String Not An Expression
I am drawing in expressions from a text file with VBA to be used as an expression in Arena - e.g. statistical distributions "Gamm(2,3)". The simulation software is interpreting this as a string - how do i get Arena to evaluate this expression the way its supposed to?

Code: Delay1 = "Gamm(2,1)"
Code: Patient.EntityAttribute(Patient.ActiveEntity, 2) = Delay1

I've tried declaring it as a variant but Arena still sees a string. Can I get around this?

Evaluating An Expression Stored In A String

I have a problem. I will be thankful If any one can suggest a solution.
My Problem is I have a string as follows.
Dim x as String
x = "(10+2)/3"
How can i compute this.

Syntax Error In String In Query Expression ''

I am attempting to insert data into an mdb table using an Insert statement. I get the following error when I execute the statement through the ADODB.Connection object:

Syntax error in string in query expression ''

This is the Insert statement:
('A3040164898%G]BK3Pau','Brantwood House','Bodiam Business Park',
'Junction Road, Bodiam','East Sussex','Solica Consulting Ltd.',
'Paul Redstone','England','FRANCES','Paul','','','','','',
'44(0)1580 830902','Partner','SOLCON','','','A3040164898%G]BK3Pau',
'16-05-2005','Redstone','14:11','FRANCES','',' ','',
'44(0)1580 830802','','','Trish','','','I0','Managing Director','TN32 5UP')

Any help on this would be greatly appreciated! Thanks!


Syntax Error In String In Query Expression
Hi, may someone pls tell how can I correct my error? Thanks.

VB Code:
conn.Execute "Update CarDetails set Status ='Available'," & "custid='" & Text3.Text & "" & "where CarRegNo='" & Text4.Text & "'

Regular Expression To Replace String W/ Pattern
I am trying to replace email addresses inside a richtextbox. I know I can loop through the entire string, try to find an email address and then replace it with the new string.
However, I am trying to do this more efficiently using Regular Expressions?

Is this possible or I am wasting my time?

Let me give you an example:
I want to put the word mailto: before every email address found in a string.

ie. "This is a test for the replacement function for the email address"

The Result should be:
"This is a test for the replacement function for the email address"

The function shoud replace every email address in the string if there is more than one.
Can somebody provide some insight on how it would be possible without looping through every word in the string?

The following is the regular expressions code to recognize an email address. I can loop through every word, pass it to the function and if it is true do the replacemente using REPLACE but there has to be a way without looping

VB Code:
Function ValidEmail(strText As String) As BooleanDim oRegEx As RegExpDim oResults As MatchCollection Set oRegEx = New RegExp oRegEx.Pattern = "^([a-zA-Z0-9_-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)" & _    "|(([a-zA-Z0-9-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$"                 Set oResults = oRegEx.Execute(strText) If oResults.Count > 0 Then    ValidEmail = TrueElse    ValidEmail = FalseEnd If Set oResults = NothingSet oRegEx = Nothing End Function

Any help is appreciated. Thanks

Re: Syntax Error In String In Query Expression
I get the following error when I try to run a query in a VB 6 program that I am writing.

-2147217900 : [Microsoft][ODBC Microsoft Access Driver] Syntax error in string in query expression

I get the error on this line

search.Open SQL, CN, 1, 2

and following is the SQL, which I am getting through debug.print, that generates the error.

SELECT * FROM PersonalInfo WHERE DOB BETWEEN #2/6/2003# AND #2/6/2003# AND firstName LIKE '%muhammad%' OR DOB BETWEEN #2/6/2004# AND #2/6/2004# AND firstName LIKE '%muhammad% ORDER BY lastname, firstname

Could some one please tell me whats wrong with this statement.

Thanks a lot.

Regular Expression Taking A Long Time If String Is Over 30 Chars.
My regular expression is hanging for 5 extra seconds per character for each character that is added to the string, when the string exceeds 30 characters in length.

The regular expression checks for correct email addresses.
the following example has 33 chars and hangs for about 20 seconds. Try adding more chars and see what happens.

here is the code:-

    Dim regEx As RegExp
    Set regEx = New RegExp
    regEx.IgnoreCase = True
    regEx.Pattern = "^([a-z0-9_-.]+)*[a-z0-9]@[a-z][w.-]*[a-z0-9].[a-z][a-z.]*[a-z]$"

Why ?

I need to evaluate the contents of a string expression. Is there a VB equivalent to the EVAL function in MS Access?

How do I convert the Evaluate function in VBA to VB6?

In VBA, Evaluate could evaluate object names eg.

Evaluate(CommandButton + buttonNumber).BackColor = &HFF&

In VB6, there seems to be no function for doing this.

Pb With Evaluate .....
first excuse me for my broken english, i'm french
i try to use the command evaluate and it don't work ...

I have a lot of check box
i have a big array, and when i read the array i want to change value of check box according of the value of the array ...

someone can help me ?

Thank's by advance

Exemple :

Check01.value = 0
Check02.value = 0
Check03.Value = 0
Check04.Value = 0
Check05.Value = 0
Check06.Value = 0
Check07.Value = 0
Check08.Value = 0
Check09.Value = 0
Check10.Value = 0
Check11.Value = 0
Check12.Value = 0
Check13.Value = 0
Check14.Value = 0
dim myarray(0 , 0 to 11) as integer

for valeur = lbound(myarray) to ubound(myarray)
next valeur

Evaluate Min &amp; Max
Newbie here needs help. How can I evaluate the numeric value of 7 variables and determine which is the largest and which is the smallest? If one of the variables is zero, it cannot count as the lowest. Also, I cannot use arrays.

How Do I Evaluate This?
How can I check if the Chr(2) is empty?

If InStr(tmp(x), Chr(2)) <> 0 Then

I have a simple function to evaluate basic maths.

if A + B = C then Msgbox "Yup Adds Up."

How can i make it so i can put in there

If A & anOperatorAsAString & B = C then msgbox "Yup Adds Up."

it changes the whole line to a string, which doesn't match an integer.
Now Val doesn't work, i need it to evaluate the string and compare it to C

Any Ideas?
Thanks for a quick reply.

Evaluate The Value??
I submitted my pre class project to the instructor and got this back in email. I dont see what he is getting at. Any help?

txtweight_change doesn't evaluate the value of the weight. this should be a
click event or lost focus when freight is selected

My code

Private Sub txtWeight_Change()

   'If the value is a number larger than 125, keep the focus.
   'With Freight selected, weights below 125 pounds should produce a warning message stating "Weights
   'below 125 pounds should be shipped Ground."- done
   If Services.Selected(1) And Val(txtWeight.Text) < 125 And Len(txtWeight.Text) = 3 Then
   MsgBox "Weights below 125 lbs. should be shipped via Ground Service"
End Sub

What is suppose to happen is when someone selects freight and enters a weight less than 125 the message box appears. That is exactly what is happening.


I have 12 text boxes. When the "LostFocus" event is triggered, I call a sub routine (see below) "OrderTickers".
I need to capture the the actual text in box X (1-12). Currently my variable is returning the string 'txtTick1.Text' instead of 'AMZN'. How can I capture the string that is in txtTick1.Text?

private Sub OrderTickers(tickNum as Integer)
Dim ii as Integer
Dim MyVal
Dim curVal

curVal = "txtTick" & tickNum & ".Text"
for ii = 1 to 12
MyVal = "txtTick" & ii & ".Text" 'eg: txtTick1.Text (I need to see AMZN)
If len(Trim(MyVal)) &gt; 1 then
MyVal = curVal
End If

End Sub

My First Game! Please Evaluate
Hi guys!!

I just finished the basic shell of a bingo first program outside of the crap I do at work....I am an extreme newbie....

Anyone wanna take a look at it, maybe play it - tell me anything I did wrong or anything?? I appreciate any feedback you could give me...even if its mean! Be as mean as you feel necessary

Its in zip format because there's a few forms and a resource file

Need Help On Evaluate Command!
I think I'v ceased to understand Visual Basic... Reason:

Simpliest task: I have variable name stored in variable and I want to get variable value like this:

public Test
sub TestRoutine()
end sub
But ... I can't !!!!

So I need to get value of Test variable using reference from VariableName ... In any other language that can do that it's simple, like: VariableValue = (VariableName) in FoxPro, or anything else ... But this ... Just won't work

Without such ability my code will grow up like 15-20 times (I have many similar array variables and don't want to write search, IO, convertation etc function for each array. So instead of 50 lines I will have 800-1000??? Plus with one little change I'll need to make change in 15 other places?

In C++ I can use array of variable addresses, in FoxPro, Perl - just eval, but in VBA ... Nothing????

Evaluate Datevalue
I am trying to write a function for converting dates. The following is the last 3 lines of code in the function. The first line of code works. If varmonth is 12, varday is 31 and va year is 2003, it will show 12/31/2003. However, this is formatted as text. In the second line of code I am using the evaluate method to convert the date to a numerical value. Why doesn't the second line of code work?

vardate = varmonth & "/" & varday & "/" & varyr 'This line works
vardate = [Datevalue(varyr,varmonth,varday)] 'This line doesn't work.
datechange = vardate

Evaluate Formula
Hi. Is it possible to evaluate a formula in VB the same way that excel does?

For example. I want to enter the following into a textbox

I can use the replace function to put numbers in where y is and any other things i decide to add but x will be the return value

I would like to complicate things even more by doing this

I would like it to realize that i can re-write it as

and still return the correct value.

Speed is important too so i would like to simplify them. If the user enteres...

I would like it to realize its the same as x=y. The reason is that the values will be updated frequently so simplifying it should speed up processing time when evaluating

Im guessing theres nothing already out there that will do this or if there is what would it be called? Where would i start coding something that can do it?

VB6: Evaluate Function
Is there a function that mimics exactly what MS Access' Eval() Function and MS Excel's Evaluate() Function???

I have a need to have a textbox where users can do some simple calculations if they need to. So they can just type: 120+636+12+89 and then I can use the function on that to display the result.

I know I can just bind to Access or Excel and use the function that they offer, but the end-user may or may NOT have Access or Excel installed.

The calculations won't be limited to just addition, but rather addition, subtraction, multiplication and division.

I'm sure I could write a function to parse it all out and work it out that way, but I'd like to find out if there is already something predefined that could do this for me.

Thanks for any help provided.

Evaluate Strings Please!!!!
I am looking for a visual basic equivalent to the EVAL, you would use in other languages such as PHP. It's really simple but I am not sure how to do it. Here is an example of what I am trying to do.

temp1 = "MONKEY"
test = "temp" & 1


I want to evaluate the string test to be the value in temp1. Therefore when printing out test, it should print "MONKEY", not "temp1". Any help would be greatly appreciated.


Evaluate A Sentence?
how can i evaluate a sentence?
example :

For i = 8 To 11
If (Cells(aktzeile, i) = 0) Then ("CH" & i).Value = False
Next i
in this case CH8, CH9, cH10, CH11 are checkboxes

if you know matlab, the command in matlab is EVAL()


Evaluate Function In VB 6?
i'm passing a field name with the text property (text1.text) to a Sub. i then want to output the value of that passed field name.

lets say i want to output it using a msgbox.


text1.text = "This is my data"

Private Sub MySub(FieldName as string)

msgbox fieldname

end sub

however, when i do that the msgbox displays "text1.text" and not the value of text1.text (which is "this is my test data"). how can i evaluate the data of "text1.text" via the variable.


Evaluate Formula
Is there a formula that could evaluate given expression as ="="&3&"+"&5 to number 8?

Copyright 2005-08, All rights reserved