Solved

Conversion from string expression to numeric value

Posted on 2010-11-09
5
358 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
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…

680 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