?
Solved

Want  in  MFC  equivalent  of Double.TryParse

Posted on 2014-08-22
1
Medium Priority
?
261 Views
Last Modified: 2014-09-04
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;
        }

Open in new window

0
Comment
Question by:ADITYA RAO
1 Comment
 
LVL 45

Accepted Solution

by:
AndyAinscow earned 2000 total points
ID: 40278397
There isn't any direct MFC equivalent of the TryParse.  You will have to write your own.
The following will help you get started:
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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

850 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