Solved

Conversion from string expression to numeric value

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

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…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
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…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

734 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