4 Replies - 1602 Views - Last Post: 13 January 2011 - 11:02 AM Rate Topic: -----

#1 sandrion9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-January 11

Not all code path return a value

Posted 12 January 2011 - 10:02 AM

internal static string Str2( double Nombre,  int? Decimale_optional,  object Separ_optional,  object Zero_optional)
		{
			int Decimale = (Decimale_optional != null) ? 0: Decimale_optional.Value;
			string Separ = (Separ_optional == Type.Missing) ? String.Empty: Separ_optional as string;
			string Zero = (Zero_optional == Type.Missing) ? String.Empty: Zero_optional as string;
			bool Negatif = false;
            object separ = (Separ_optional == Type.Missing) ? String.Empty: Separ_optional as string;;

			if (Nombre < 0)
             {
				Negatif = true;
				Nombre = Math.Abs(Nombre);
                return Separ; ;

			}
			else
			{
				Negatif = false;
			}
			if (Nombre < 0.1d)
			{
				Nombre *= 1000;
				Nombre = Convert.ToInt32(Nombre);
				Nombre /= 1000;
                return Separ;
			}
			if (Nombre < 0.001d)
			{
				Nombre = 0;
                return Separ;
			}
			//UPGRADE_TODO: (1069) Error handling statement (On Error Resume Next) was converted to a pattern that might have a different behavior. More Information: http://www.vbtonet.com/ewis/ewi1069.aspx
			string Texte = String.Empty;
			try
			{
				Texte = Conversion.Str(Nombre);
				//UPGRADE_WARNING: (2081) Err.Number has a new behavior. More Information: http://www.vbtonet.com/ewis/ewi2081.aspx
				if (Information.Err().Number == 94)
				{
					Texte = "0";
                    return null;
				}
			}
			catch (Exception )
			{
				NotUpgradedHelper.NotifyNotUpgradedElement("Resume in On-Error-Resume-Next Block");
			}
			Texte = Strings.Right(Texte, Texte.Length - 1);
			if (Nombre > 0 && Nombre < 1)
			{
				Texte = "0" + Texte;
                
			}
			int virgule = Texte.Length;
			if (Decimale_optional != null)
			{
				for (int i = 1; i <= Texte.Length; i++)
				{
					if (Strings.Mid(Texte, i, 1) == ".")
					{
						virgule = i;
					}
				}
				if (Texte.Length > virgule + Decimale)
				{
					Texte = Strings.Left(Texte, virgule + Decimale);
				}
			}
			if (Separ_optional != Type.Missing)
			{
				for (int i = 1; i <= Texte.Length; i++)
				{
					if (Strings.Mid(Texte, i, 1) == ".")
					{
						Texte = StringsHelper.MidAssignment(Texte, i, 1, Separ);
					}
				}
			}
			if (Texte.Length != 0)
			{
				if (Texte.EndsWith(".") || Texte.EndsWith(","))
				{
					Texte = Strings.Left(Texte, Texte.Length - 1);
				}
			}
			if (Negatif)
			{
				return "-" + Texte;
			}
			else
			{
				if (Zero_optional == Type.Missing)
				{
					return Texte;
				}
				else
				{
					if (Val2(Texte) == 0)
					{
						return "";
					}
					else
					{
						if (Zero is string)
						{
							//UPGRADE_WARNING: (1068) Zero of type String is being forced to double. More Information: http://www.vbtonet.com/ewis/ewi1068.aspx
							// (Double.Parse(Texte + " ") + ((double) Zero)).ToString();
						}
						else
						{
							return Texte;
						}
					}
				}
			}
		}

This post has been edited by modi123_1: 12 January 2011 - 10:09 AM
Reason for edit:: please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Not all code path return a value

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8367
  • View blog
  • Posts: 31,092
  • Joined: 12-June 08

Re: Not all code path return a value

Posted 12 January 2011 - 10:11 AM

Where's the error at? From your subject line it simply means one of your ifstatements can get to the bottom of a method and have no specific return value. Review your ifstatements and if need be put a return statement at the bottom of your functions.
Was This Post Helpful? 0
  • +
  • -

#3 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: Not all code path return a value

Posted 12 January 2011 - 10:17 AM

you have no return here
else 
 {  
  if (Zero is string)  
    {  //UPGRADE_WARNING: (1068) Zero of type String is being forced to double. More Information: http://www.vbtonet.com/ewis/ewi1068.aspx  
// (Double.Parse(Texte + " ") + ((double) Zero)).ToString();  

   return something??
 }  
 else 
 {  
     return Texte;  
 }  



or put a return at the end of the function as default, in case the function doesn't return till then.

This post has been edited by Ionut: 12 January 2011 - 10:18 AM

Was This Post Helpful? 0
  • +
  • -

#4 Guest_Sandrion9*


Reputation:

Re: Not all code path return a value

Posted 13 January 2011 - 10:44 AM

View PostIonut, on 12 January 2011 - 09:17 AM, said:

you have no return here
else 
 {  
  if (Zero is string)  
    {  //UPGRADE_WARNING: (1068) Zero of type String is being forced to double. More Information: http://www.vbtonet.com/ewis/ewi1068.aspx  
// (Double.Parse(Texte + " ") + ((double) Zero)).ToString();  

   return something??
 }  
 else 
 {  
     return Texte;  
 }  



or put a return at the end of the function as default, in case the function doesn't return till then.

Was This Post Helpful? 0

#5 Fungle  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 249
  • View blog
  • Posts: 337
  • Joined: 06-March 10

Re: Not all code path return a value

Posted 13 January 2011 - 11:02 AM

It's also worth noting that here:


return Separ; ;




and here:

object separ = (Separ_optional == Type.Missing) ? String.Empty: Separ_optional as string;;



Have double semi-colons, I don't think C# likes double Semi colons very much so this could cause a problem in your code if the variable isn't being defined properly :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1