System.FormatException error

Post your .Net discussions here
Post Reply
Holger
Newbie
Posts: 0
Joined: Thu Jul 03, 2014 10:32 am
Location: Germany

System.FormatException error

Post by Holger »

Hi ,

ich have a problem with the C# example for PicoScope 2206A.
The Microsoft Visual Studio 2012 say my:

"An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll.

Additional information: Input string was not in a correct format."

in line 786 in PS2000ACSConsole.cs.

Code: Select all

variant = Convert.ToInt16(line.ToString());
Thanks
Holger

Hitesh

Re: System.FormatException error

Post by Hitesh »

Hello Holger,

The error is a result of the function attempting to convert a string containing the letter 'A' to a number.

Please replace the if statement with the following:

Code: Select all

if (i == 3)
{
	if (line.ToString().EndsWith("MSO"))
	{
		variant = Convert.ToInt16((line.ToString().Remove(4, 3)));  // Use the numeric part of the variant num
	}
	else if (line.ToString().EndsWith("A"))
	{
		variant = Convert.ToInt16((line.ToString().Remove(4, 1)));  // Handle 'A' variants
	}
	else
	{
		variant = Convert.ToInt16(line.ToString());
	}

}
This change will appear in the next SDK release.

Hope this helps.

Holger
Newbie
Posts: 0
Joined: Thu Jul 03, 2014 10:32 am
Location: Germany

Re: System.FormatException error

Post by Holger »

Hello Hitesh,

thanks yes it was a help for me.

Post Reply