Question

VB .net Object Reference Error

Asked by: dumpsterdivingdave

I have the following Code that when run produces an error that states Object Reference Not Set to an Instance of an Object...

On Lines 31 - 34, if I change them so that they have a value in that line (ex change line 31 to read TW.Resolution = 300) then it works just fine.

I checked, and the values are getting read out of the file and are being parsed/interpreted correctly.  So it is not trying to assign blank values...

Imports Priore.Controls
Imports System.Runtime.InteropServices
Imports System.IO
Imports System.Collections
Imports System
Imports System.Xml 
Public Class Form1 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Hide() 
        Dim xDoc As New XmlDocument
        xDoc.Load("config.xml") 
        Dim DPI As XmlNodeList = xDoc.GetElementsByTagName("dpi")
        Dim colourType As XmlNodeList = xDoc.GetElementsByTagName("colourType")
        Dim showIF As XmlNodeList = xDoc.GetElementsByTagName("showInterface")
        Dim showPR As XmlNodeList = xDoc.GetElementsByTagName("showProgress") 
        Dim vDPI As Short = CShort(DPI(0).InnerText)
        Dim vColourType As Twain.TWAIN_CLASS_COLOURTYPE
        Select Case colourType(0).InnerText
            Case "twBW"
                vColourType = Twain.TWAIN_CLASS_COLOURTYPE.twBW
            Case "twGrey"
                vColourType = Twain.TWAIN_CLASS_COLOURTYPE.twGREY
            Case "twRGB"
                vColourType = Twain.TWAIN_CLASS_COLOURTYPE.twRGB
        End Select
        Dim vShowIF As Boolean = CBool(showIF(0).InnerText)
        Dim vShowPR As Boolean = CBool(showPR(0).InnerText) 
        Try 
            Dim TW As Twain
            TW = New Twain(Me.Handle)
            TW.Resolution = vDPI
            TW.ColorType = vColourType
            TW.ShowInterface = vShowIF
            TW.ShowProgress = vShowPR
            TW.StartScan()
            Dim args() As String = Environment.GetCommandLineArgs
            Dim img As New Bitmap(TW.Image)
            TW.Dispose()
            Dim saveLoc As String
            saveLoc = args(1) + "-" + DateTime.Now.Year.ToString + DateTime.Now.Month.ToString + DateTime.Now.Day.ToString + DateTime.Now.Hour.ToString + DateTime.Now.Minute.ToString + DateTime.Now.Second.ToString + ".jpg"
            img.Save(saveLoc, Drawing.Imaging.ImageFormat.Jpeg)
            img.Dispose()
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
        'End
    End Sub
End Class
                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-11-04 at 14:29:53ID24872791
Topics

Microsoft Visual Basic.Net

,

.NET Framework 3.x versions

,

.NET

Participating Experts
2
Points
0
Comments
27

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. par file
    Waht is a file with .par used for and what does this extension mean? Can I list the parameters for import in a .par file and use this file in imp, like imp file=filename.par Please suggest.
  2. Code Interpreter for VB
    This is a funky question and I don't know if it can be done. I have an application where a user does some data mining and statistics to generate a segmentation algorithm. This algorithm is basically script code that identifies customers based on behavioral characteristics. ...
  3. Please help interpreter
    Hi Experts Can anyone please point me to a website that has information on how interpreters work and how I can make one this is for a college project. anyway I looked in google and found nothing that is usfull I also looked at www.whatis.com that was a waste of time. I don...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: carmodykPosted on 2009-11-04 at 15:03:22ID: 25745043

Hmmm....
Well, let's first narrow the problem down.  Try this first, this should help discover the issue.  Move some of your Dim statements within the Try statement.

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Hide() 
        Dim xDoc As New XmlDocument
Dim strObject as string = "none"
        xDoc.Load("config.xml") 
                Try 
       'Begin
        Dim DPI As XmlNodeList = xDoc.GetElementsByTagName("dpi")
        strObject = "DPI"
        Dim colourType As XmlNodeList = xDoc.GetElementsByTagName("colourType")
        strObject = "colourType"
        Dim showIF As XmlNodeList = xDoc.GetElementsByTagName("showInterface")
        strObject = "showIF"
        Dim showPR As XmlNodeList = xDoc.GetElementsByTagName("showProgress") 
        strObject = "showPR"
        Dim vDPI As Short = CShort(DPI(0).InnerText)
        strObject = "vDPI"
        Dim vColourType As Twain.TWAIN_CLASS_COLOURTYPE
        strObject = "vColourType"
        Select Case colourType(0).InnerText
            Case "twBW"
                vColourType = Twain.TWAIN_CLASS_COLOURTYPE.twBW
            Case "twGrey"
                vColourType = Twain.TWAIN_CLASS_COLOURTYPE.twGREY
            Case "twRGB"
                vColourType = Twain.TWAIN_CLASS_COLOURTYPE.twRGB
        End Select
        Dim vShowIF As Boolean = CBool(showIF(0).InnerText)
        strObject = "vShowIF"
        Dim vShowPR As Boolean = CBool(showPR(0).InnerText) 
        strObject = "vShowPR"
            Dim TW As Twain
            TW = New Twain(Me.Handle)
            TW.Resolution = vDPI
            TW.ColorType = vColourType
            TW.ShowInterface = vShowIF
            TW.ShowProgress = vShowPR
            TW.StartScan()
            Dim args() As String = Environment.GetCommandLineArgs
            Dim img As New Bitmap(TW.Image)
            TW.Dispose()
            Dim saveLoc As String
            saveLoc = args(1) + "-" + DateTime.Now.Year.ToString + DateTime.Now.Month.ToString + DateTime.Now.Day.ToString + DateTime.Now.Hour.ToString + DateTime.Now.Minute.ToString + DateTime.Now.Second.ToString + ".jpg"
            img.Save(saveLoc, Drawing.Imaging.ImageFormat.Jpeg)
            img.Dispose()
        Catch ex As Exception
            MessageBox.Show(strObject & " - " & ex.ToString)
        End Try
        'End
    End Sub
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:

Select allOpen in new window

 

by: dumpsterdivingdavePosted on 2009-11-04 at 16:05:40ID: 25745546

I'll give that a shot first thing in the morning...

 

by: dumpsterdivingdavePosted on 2009-11-05 at 08:55:43ID: 25751462

I did as suggested and still get the error.  See new code below.  my error message is now dimArgs - System.NullReference.....  So it appears that it is happening on the following line:

Dim img as New Bitmap(TW.Image)

Imports Priore.Controls
Imports System.Runtime.InteropServices
Imports System.IO
Imports System.Collections
Imports System
Imports System.Xml 
Public Class Form1 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Hide() 
        Dim xDoc As New XmlDocument
        xDoc.Load("config.xml")
        Dim strObject = "none"
        Try
            Dim DPI As XmlNodeList = xDoc.GetElementsByTagName("dpi")
            strObject = "DPI"
            Dim colourType As XmlNodeList = xDoc.GetElementsByTagName("colourType")
            strObject = "colourType"
            Dim showIF As XmlNodeList = xDoc.GetElementsByTagName("showInterface")
            strObject = "showIF"
            Dim showPR As XmlNodeList = xDoc.GetElementsByTagName("showProgress")
            strObject = "showPR"
            Dim vDPI As Short = CShort(DPI(0).InnerText)
            strObject = "vDPI"
            Dim vColourType As Twain.TWAIN_CLASS_COLOURTYPE
            strObject = "vColourType"
            Select Case colourType(0).InnerText
                Case "twBW"
                    vColourType = Twain.TWAIN_CLASS_COLOURTYPE.twBW
                Case "twGrey"
                    vColourType = Twain.TWAIN_CLASS_COLOURTYPE.twGREY
                Case "twRGB"
                    vColourType = Twain.TWAIN_CLASS_COLOURTYPE.twRGB
            End Select
            Dim vShowIF As Boolean = CBool(showIF(0).InnerText)
            strObject = "vShowIF"
            Dim vShowPR As Boolean = CBool(showPR(0).InnerText)
            strObject = "vShowPR"
            Dim TW As Twain
            strObject = "dimTW"
            TW = New Twain(Me.Handle)
            strObject = "newTW"
            TW.Resolution = vDPI
            strObject = "setRes"
            TW.ColorType = vColourType
            strObject = "setColour"
            TW.ShowInterface = vShowIF
            strObject = "setIF"
            TW.ShowProgress = vShowPR
            strObject = "setPR"
            TW.StartScan()
            strObject = "StartScan"
            Dim args() As String = Environment.GetCommandLineArgs
            strObject = "dimArgs"
            Dim img As New Bitmap(TW.Image)
            strObject = "copyImage"
            TW.Dispose()
            strObject = "disposeTW"
            Dim saveLoc As String
            saveLoc = args(1) + "-" + DateTime.Now.Year.ToString + DateTime.Now.Month.ToString + DateTime.Now.Day.ToString + DateTime.Now.Hour.ToString + DateTime.Now.Minute.ToString + DateTime.Now.Second.ToString + ".jpg"
            img.Save(saveLoc, Drawing.Imaging.ImageFormat.Jpeg)
            img.Dispose()
        Catch ex As Exception
            MessageBox.Show(strObject & " - " & ex.ToString)
        End Try
        'End
    End Sub
End Class

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:

Select allOpen in new window

 

by: CodeCruiserPosted on 2009-11-05 at 09:12:48ID: 25751650

Looks like TW.Image is nothing.

 

by: carmodykPosted on 2009-11-05 at 09:34:26ID: 25751853

Let's try this:  Change Me.Handle to Process.handle

Me.Handle returns the Handle of the Form you are in.  While Process.Handle returns the Handle attribute of the entire process

See if that works.

 

by: dumpsterdivingdavePosted on 2009-11-05 at 09:37:08ID: 25751872

Right, but for some reason:

TW.Resolution  = vDPI
TW.ColorType = vColourType
TW.ShowInterface = vShowIF
TW.ShowProgress = vShowPR
TW.StartScan()

The above returns the error that is described.  However, if I change it so that instead of getting the values from the variable and assign them directly like below:

TW.Resolution  = 300
TW.ColorType = twGREY
TW.ShowInterface = false
TW.ShowProgress = true
TW.StartScan()

The above there now works correctly.

In a nutshell, if I hard code the settings, the software will correctly scan and save the image.  However, if I try and make those values dynamic, or read in from a config file, it generates the error.  I placed break points at each of the above assignments and it does in fact get, and assign the correct values.  So that's where I am confused.

 

by: dumpsterdivingdavePosted on 2009-11-05 at 09:38:39ID: 25751886

When I try to change Me.Handle to Process.Handle, it will not compile and says Error      1      Reference to a non-shared member requires an object reference.      C:\Users\Scott\documents\visual studio 10\Projects\scan\scan\Form1.vb      43      28      scan

 

by: carmodykPosted on 2009-11-05 at 10:00:48ID: 25752094

Bah!  Send an example of the XML document you are using.

 

by: dumpsterdivingdavePosted on 2009-11-05 at 10:04:37ID: 25752129

Here's the XML file.

<?xml version="1.0" encoding="utf-8"?>
<settings>
	<dpi>300</dpi>
	<colourType>twGREY</colourType>
	<showInterface>false</showInterface>
	<showProgress>true</showProgress>
</settings>

                                              
1:
2:
3:
4:
5:
6:
7:

Select allOpen in new window

 

by: carmodykPosted on 2009-11-05 at 10:36:12ID: 25752434

Change this :

Dim DPI As XmlNodeList = xDoc.GetElementsByTagName("dpi")
Dim colourType As XmlNodeList = xDoc.GetElementsByTagName("colourType")
Dim showIF As XmlNodeList = xDoc.GetElementsByTagName("showInterface")
Dim showPR As XmlNodeList = xDoc.GetElementsByTagName("showProgress")

To This:

Dim DPI As string =  xDoc.ChildNodes(0).ChildNodes(0).ChildNodes("dpi").InnerText()
Dim colourType As String = xDoc.ChildNodes(0).ChildNodes(0).ChildNodes("colourType").InnerText()
Dim showIF As String= xDoc.ChildNodes(0).ChildNodes(0).ChildNodes("showInterface").InnerText()
Dim showPR As string = xDoc.ChildNodes(0).ChildNodes(0).ChildNodes("showProgress") .InnerText()

 

by: carmodykPosted on 2009-11-05 at 10:38:40ID: 25752460

Oops!  Also

 Dim vDPI As Short = CShort(DPI)
            Dim vColourType As Twain.TWAIN_CLASS_COLOURTYPE
            Select Case colourType
                Case "twBW"
                    vColourType = Twain.TWAIN_CLASS_COLOURTYPE.twBW
                Case "twGrey"
                    vColourType = Twain.TWAIN_CLASS_COLOURTYPE.twGREY
                Case "twRGB"
                    vColourType = Twain.TWAIN_CLASS_COLOURTYPE.twRGB
            End Select
            Dim vShowIF As Boolean = CBool(showIF)
            strObject = "vShowIF"
            Dim vShowPR As Boolean = CBool(showPR)

 

by: dumpsterdivingdavePosted on 2009-11-05 at 10:50:55ID: 25752588

Now it fails as soon as it tries to read the first XML node...

 

by: carmodykPosted on 2009-11-05 at 10:52:58ID: 25752611

Hmmm....
Maybe I went too far....
Dim DPI As string =  xDoc.ChildNodes(0).ChildNodes("dpi").InnerText()
Dim colourType As String = xDoc.ChildNodes(0).ChildNodes("colourType").InnerText()
Dim showIF As String= xDoc.ChildNodes(0).ChildNodes("showInterface").InnerText()
Dim showPR As string = xDoc.ChildNodes(0).ChildNodes("showProgress") .InnerText()

 

by: CodeCruiserPosted on 2009-11-05 at 11:00:49ID: 25752705

There is no need of changing the xml code as the asker has mentioned already that the settings are being assigned correctly when he steps through the code.

 

by: dumpsterdivingdavePosted on 2009-11-10 at 06:35:35ID: 25785737

any ideas?

 

by: carmodykPosted on 2009-11-10 at 09:01:07ID: 25787354

Apparantly, I think you're pulling the wrong xml nodes.  Try this instead...

        Dim DPI As String = xDoc.ChildNodes(1).ChildNodes(0).InnerText()
        Dim colourType As String = xDoc.ChildNodes(1).ChildNodes(1).InnerText()
        Dim showIF As String = xDoc.ChildNodes(1).ChildNodes(2).InnerText()
        Dim showPR As String = xDoc.ChildNodes(1).ChildNodes(3).InnerText()


Dim vDPI As Short = CShort(DPI)
            Dim vColourType As Twain.TWAIN_CLASS_COLOURTYPE
            Select Case colourType
                Case "twBW"
                    vColourType = Twain.TWAIN_CLASS_COLOURTYPE.twBW
                Case "twGrey"
                    vColourType = Twain.TWAIN_CLASS_COLOURTYPE.twGREY
                Case "twRGB"
                    vColourType = Twain.TWAIN_CLASS_COLOURTYPE.twRGB
            End Select
            Dim vShowIF As Boolean = CBool(showIF)
            strObject = "vShowIF"
            Dim vShowPR As Boolean = CBool(showPR)

 

by: dumpsterdivingdavePosted on 2009-11-10 at 13:54:40ID: 25790305

If I add a breakpoint on line 35 (in the original code posted with the question), and I examine the values for each of the 4 variables, they are in fact correct, and of the correct type.  The data is being pulled in from the XML file, and is being pulled in and converted correctly without making any changes to the XML parsing part of the code.

I also do not simply want to reference the elements by index in case the order gets changed around in the file.  With it referenced by name the order of elements in the file does not matter, only the name of the tags encompassing them.

 

by: carmodykPosted on 2009-11-11 at 09:36:21ID: 25797095

OK, lets then example each variable before they get dumped into being made an image.  I truly believe that a value is not "pushed" correctly, if you know what I mean.

 TW.Resolution = vDPI
            TW.ColorType = vColourType
            TW.ShowInterface = vShowIF
            TW.ShowProgress = vShowPR
msgbox("TWR:" & TW.Resolution.ToString)
msgbox("TWC:" &   TW.ColorType .ToString)
msgbox("TWSI:" &  TW.ShowInterface.ToString)
msgbox("TWSP:" &  TW.Progress.ToString)

 

by: dumpsterdivingdavePosted on 2009-11-13 at 07:20:59ID: 25814611

Checking that now...  I'll let you know what happens.

 

by: dumpsterdivingdavePosted on 2009-11-13 at 07:48:33ID: 25814885

When adding messagebox.show(TW.Resolution.ToString) and the others, The message boxes all showed the correct values.  However, same error message still arises.

 

by: carmodykPosted on 2009-11-13 at 08:33:32ID: 25815282

So, to recap.  You put static values into your variables for scanning....

TW.Resolution  = 300
TW.ColorType = twGREY
TW.ShowInterface = false
TW.ShowProgress = true
TW.StartScan()

and everything works fine, every time.  But if you push variable values into the same functions, it cops out?  And from the message boxes, they all hold the same values necessary to function and are the same datatype that is required?  That is one freaky problem.  :(  I've looked over your code, and while I think I'm a knowledgable guy, I'm not really seeing the flaw that would be a show stopper.  

I'm going to throw a crazy suggestion here.  Move the code out of the form_load and make a new button.  Put the code into the button1_click function to see if that changes things.  Sometimes for no expectant reason,  that works.  

 

by: dumpsterdivingdavePosted on 2009-11-13 at 09:26:43ID: 25815789

no change

 

by: dumpsterdivingdavePosted on 2009-11-13 at 09:34:08ID: 25815875

This may also help, may not...

When I have the values hard coded, and the application reaches the point in the code where it is to begin scanning (TW.StartScan()), you can hear the scanner start up, and then it scans.  When the values are assigned in dynamically, you hear the scanner start up as it did with them statically set, however, it never scans after that.

I don't know if the program is feeding the scanner some variable that is causing it to seize up or what.  Like you, I too am stumped as the variables that it is feeding it are the correct type and value.

Essentially, what is happening is that the program is starting the scanner, but the scanner never completes and sends the program back an image, thus the object reference error.  changed the code to read as below, and when I did that, the program would hang (so no more error) right after the scanner initialized, and CPU usage spike to 100% (because of the while loop).

Dim myInt As Integer
myInt = -1
myInt = TW.StartScan()
While myInt <> 0 
End While
Dim img As New Bitmap(TW.Image)

                                              
1:
2:
3:
4:
5:
6:
7:

Select allOpen in new window

 

by: dumpsterdivingdavePosted on 2009-11-13 at 11:16:50ID: 25816834

It seems to me that the problem lies within the Twain Control that I had gotten.  After doing some more research, I found the following:  http://www.ciansoft.com/twaincontrolx/default.asp which I then tested.  I am now able to get the software to read in from the config file and save the image (and without having to copy it to another image first).

So in short, the problem is solved.

 

by: carmodykPosted on 2009-11-13 at 12:54:08ID: 25817611

Awesome!  Feels good doesn't it?  

 

by: dumpsterdivingdavePosted on 2009-11-13 at 21:11:02ID: 25819476

Yes.  Wish the other one would have worked, but I think this one ended up working for the better as it allows me a bit more control including multiple scanner support and jpeg resolution control using the same ammount of code.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...