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 » Thu Jul 17, 2014 7:08 am

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
Site Admin
Site Admin
Posts: 2829
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: System.FormatException error

Post by Hitesh » Tue Jul 22, 2014 10:31 am

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.
Hitesh

Technical Support Engineer

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

Re: System.FormatException error

Post by Holger » Wed Jul 23, 2014 9:01 am

Hello Hitesh,

thanks yes it was a help for me.

Post Reply