Solved

Conversion from string expression to numeric value

Posted on 2010-11-09
5
323 Views
Last Modified: 2013-11-27
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
Comment
Question by:Milewskp
5 Comments
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
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

by:Pacane
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

by:rockiroads
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
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

by:Milewskp
ID: 34096088
Thanks rocki
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now