Solved

Conversion from string expression to numeric value

Posted on 2010-11-09
5
365 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
[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
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

630 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