VintaSoft Twain .NET SDK Discussions

Questions, comments and suggestions concerning VintaSoft Twain .NET SDK.

Board index < VintaSoft Twain < VintaSoft Twain .NET SDK Discussions

We are migrating to new forums engine, no new registration or posting currently available. TIA for your patience.

Divide by zero error



Divide by zero error

Post by BillG »

I finally figured out what I was doing wrong and now it is saving multiple pages properly. Every one and awhile though, the user gets a divide by zero error, they exit the program, log back in and it works fine. Later just out of the blue, after working for a while it happens again. Here is the code.

if (vsTwain1.FeederLoaded)
{
vsTwain1.ShowIndicators = true;
while (vsTwain1.AcquireModal())
{
try
{
pictureBox1.Image = vsTwain1.GetCurrentImage();
vsTwain1.SaveImage(0, dirPath + filePath);
}
catch (TwainException ex)
{
if (vsTwain1.ErrorCode != Vintasoft.Twain.ErrorCode.None)
MessageBox.Show(vsTwain1.ErrorString);
else
MessageBox.Show(ex.Message);
}
}
myController.SaveScannedRecord(Int32.Parse(rdType.ToString()), filePath, DescriptionTextBox.Text.ToString(), numOfPages);
vsTwain1.StopDevice();
MessageBox.Show("Scan completed.");
}


Re: Divide by zero error

Post by Alex »

Hello Bill,

First of all you must dispose the image in the PictureBox when you replace it.

Here is correct code:
if (vsTwain1.FeederLoaded)
{
  vsTwain1.ShowIndicators = true;
  while (vsTwain1.AcquireModal())
  {
    try
    {
      if (pictureBox1.Image != null)
      {
        pictureBox1.Image.Dispose();
        pictureBox1.Image = null;
      }
      pictureBox1.Image = vsTwain1.GetCurrentImage();
      vsTwain1.SaveImage(0, dirPath + filePath);
    }
    catch (TwainException ex)
    {
      if (vsTwain1.ErrorCode != Vintasoft.Twain.ErrorCode.None)
        MessageBox.Show(vsTwain1.ErrorString);
      else
        MessageBox.Show(ex.Message);
    }
  }
  myController.SaveScannedRecord(Int32.Parse(rdType.ToString()), filePath, DescriptionTextBox.Text.ToString(), numOfPages);
  vsTwain1.StopDevice();
  MessageBox.Show("Scan completed.");
}
Could you tell me in which line of code the "divide by zero" error occurs?

Best regards, Alexander


Re: Divide by zero error

Post by BillG »

That solved the problem of the divide by zero error. When the user scans a one page document everyone works fine, but when the user scans a document with two pages it actually scans the first page multiple times into the file. I can't duplicate this on my system. Tthey and I are using a HP Scanjet N6010 and using the WIA drivers.

Bill


Re: Divide by zero error

Post by Alex »

Hello Bill,

Please try to download and use version 2.0 driver for HP N6010 scanner from this link:
http://driverscollection.com/?H=ScanJet%20N6010&By=HP
and let me know results.

Best regards, Alexander


Page 1 from 1: 1