Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Conversion from string expression to numeric value

Posted on 2010-11-09
Medium Priority
372 Views
How do you convert a string expression to a number?

I tried this: intVar = CInt("1+1") but I got a 'Type Mismatch' error.
0
Question by:Milewskp
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 65

Accepted Solution

ID: 34094990
Well its a string in cint, it is not going to do the maths

If you maybe evaluated that math first, see if that helps

intvar = CInt(Eval("1+1"))
0

LVL 2

Expert Comment

ID: 34094997
You can't do this.
A possible thing would have been CInt("1") + CInt("1")

But since ("1+1") cannot be cast into an int, you'll have to do something different.
0

LVL 65

Expert Comment

ID: 34095244
read up on the help pages for eval

eval - You can use the Eval function to evaluate an expression  that results in a text string or a numeric value.

An expression that evaluates to an alphanumeric text string. For example, stringexpr can be a function that returns a string or a numeric value. Or it can be a reference to a control  on a form. The stringexpr argument must evaluate to a string or numeric value; it can't evaluate to a Microsoft Access object .
0

LVL 75

Expert Comment

ID: 34095405
If your String expression is all Numeric, you can use

Dim x
x=Val(YourStringExpression)

Only place this fails is if your string expression starts with a zero.

Val(012345) returns 12345

mx
0

LVL 1

Author Closing Comment

ID: 34096088
Thanks rocki
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
###### Suggested Courses
Course of the Month5 days, 4 hours left to enroll