Solved

# Want  in  MFC  equivalent  of Double.TryParse

Posted on 2014-08-22
Medium Priority
261 Views
I  have to convert  following  C#  code as  it is MFC. In  following  code it is  used Double.TryParse,I  am  unable to  find equivalent  for  same  in MFC,Please  help  for  same
``````public bool IsValidCutOffFormula(String StrExpression )
{
try
{
Int16 iFirstOperator=0;
Int16 iSecondOperator = -1;
String StrOperators = "+-/*";
String StrOprand="";
double dblResults;
for (Int16 iCount = 0; iCount < StrExpression.Length ; iCount++)
{

if (StrOperators.Contains(StrExpression.Substring(iCount, 1)))
{
iFirstOperator = iSecondOperator;
iSecondOperator = iCount;
StrOprand = StrExpression.Substring(iFirstOperator + 1, iSecondOperator - iFirstOperator-1);
if (StrOprand == String.Empty)
{
return false;
}
else
{

if (Double.TryParse(StrOprand, out dblResults) == false)
{
if (StrOprand == "NC" || StrOprand == "PC" || StrOprand == "COC")
{
//return true;
}
else
return false;
}

}

}
}
if (iFirstOperator == 0 || iSecondOperator == -1) // No operator found
{
if (ExpressionValidate(StrExpression) == false) //NC Or PC or Constant value used as cut-OFf
return false;
}
else if (iSecondOperator == StrExpression.Length - 1) // Expression shuold not be terminated with operator
{
return false;
}
else
{
if (iSecondOperator> 0)
{
//StrExpression = StrExpression.Substring(iSecondOperator+1);
if (ExpressionValidate(StrExpression.Substring(iSecondOperator + 1)) == false) //NC Or PC or Constant value used as cut-OFf
return false;
}

}
return true;
}
catch (Exception ex)
{
return false;
}
}
//Checking expression in cut off formula for NC,PC,COC added @20 mar 2014.
public bool ExpressionValidate(String StrExpression)
{
double dblResults;
if (StrExpression == "NC" || StrExpression == "PC" || StrExpression == "COC" || Double.TryParse(StrExpression, out dblResults) == true) // NC Or PC or Constant value used as cut-OFf
{
return true;
}
else
return false;
}
``````
0
1 Comment

LVL 45

Accepted Solution

AndyAinscow earned 2000 total points
ID: 40278397
There isn't any direct MFC equivalent of the TryParse.  You will have to write your own.
http://msdn.microsoft.com/en-us/library/5948ysye.aspx
which is about the _atodbl function (string to double).  There is also an atof (and related functions) that performs a similar task but handles errors in a different way.
0

## Featured Post

Question has a verified solution.

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

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview
###### Suggested Courses
Course of the Month16 days, 6 hours left to enroll