Test and Measurement Forum

System.FormatException error

Post your .Net discussions here

System.FormatException error

Postby 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
Holger
Newbie
 
Posts: 0
Joined: Thu Jul 03, 2014 10:32 am
Location: Germany

Re: System.FormatException error

Postby 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 Specialist
Pico Technology
Hitesh
Site Admin
Site Admin
 
Posts: 1997
Joined: Tue May 31, 2011 3:43 pm
Location: St. Neots, Cambridgeshire

Re: System.FormatException error

Postby Holger » Wed Jul 23, 2014 9:01 am

Hello Hitesh,

thanks yes it was a help for me.
Holger
Newbie
 
Posts: 0
Joined: Thu Jul 03, 2014 10:32 am
Location: Germany


Return to .Net Languages (C#, VB.Net, .)

Who is online

Users browsing this forum: No registered users and 0 guests