Divide by zero error

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

Moderator: Alex

Post Reply
BillG
Posts: 47
Joined: Fri Oct 10, 2008 3:52 pm

Divide by zero error

Post by BillG » Thu Jan 14, 2010 3:37 am

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.");
}

Alex
Site Admin
Posts: 1474
Joined: Thu Jul 10, 2008 2:21 pm

Re: Divide by zero error

Post by Alex » Thu Jan 14, 2010 9:33 am

Hello Bill,

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

Here is correct code:

Code: Select all

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

BillG
Posts: 47
Joined: Fri Oct 10, 2008 3:52 pm

Re: Divide by zero error

Post by BillG » Fri Jan 15, 2010 12:25 am

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

Alex
Site Admin
Posts: 1474
Joined: Thu Jul 10, 2008 2:21 pm

Re: Divide by zero error

Post by Alex » Fri Jan 15, 2010 5:20 pm

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

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest