Find line that throws exception

J

John

Hi there,

I'm fairly new to VB.Net (and VB generally) so please bear with me if these
are stupid questions!

I'm trying run a procedure on multiple Visio files from a form created in VS
2003. This has worked fine when run from a click event on a single form at
the start. It selected the items in a listbox (lstWorkFiles) and then went
through each one. Now however, I moved the code to a second form (fmOps),
which has some check boxes, and is run from a click event on btProcess and
I'm getting a "Object reference not set to an instance of an object" error
from the exception handler. So my questions are:

a) Is there a way to add a value to the exception message showing the line
number that threw the exception?

b) Can anyone see what I'm doing wrong in the code below to produce this
error? (I'm assuming the problem is that I'm not referencing the Form1 in
the right way?)

c) When you step through code with F8 the respective line is highlighted
yellow, but when a form is showing this seems to disappear. Is there a way
around this?

Many thanks in advance

John



Public Sub btProcess_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btProcess.Click

Dim openingForm As Form1

Try

Dim vDoc As Document 'Visio Document

Dim vWin As Window 'Visio Window

m_appVisio = GetObject(, "visio.application")

Dim itm As ListViewItem

For Each itm In openingForm.lstWrkFiles.Items

vDoc = m_appVisio.Documents.Open(itm.Text)

'Whole Page View

If ckBxWholePageView.Checked = True Then

AllPageWholeView(vDoc)

End If

System.Windows.Forms.MessageBox.Show("Done", MessageBoxButtons.OK)

vDoc.Close()

Next

Catch ex As Exception

System.Windows.Forms.MessageBox.Show(ex.Message)

End Try

End Sub
 
K

Ken Tucker [MVP]

Hi,

You never created openingform before you used it. Try something like
this.

Dim openingForm As New Form1

Ken
---------------
Hi there,

I'm fairly new to VB.Net (and VB generally) so please bear with me if these
are stupid questions!

I'm trying run a procedure on multiple Visio files from a form created in VS
2003. This has worked fine when run from a click event on a single form at
the start. It selected the items in a listbox (lstWorkFiles) and then went
through each one. Now however, I moved the code to a second form (fmOps),
which has some check boxes, and is run from a click event on btProcess and
I'm getting a "Object reference not set to an instance of an object" error
from the exception handler. So my questions are:

a) Is there a way to add a value to the exception message showing the line
number that threw the exception?

b) Can anyone see what I'm doing wrong in the code below to produce this
error? (I'm assuming the problem is that I'm not referencing the Form1 in
the right way?)

c) When you step through code with F8 the respective line is highlighted
yellow, but when a form is showing this seems to disappear. Is there a way
around this?

Many thanks in advance

John



Public Sub btProcess_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btProcess.Click

Dim openingForm As Form1

Try

Dim vDoc As Document 'Visio Document

Dim vWin As Window 'Visio Window

m_appVisio = GetObject(, "visio.application")

Dim itm As ListViewItem

For Each itm In openingForm.lstWrkFiles.Items

vDoc = m_appVisio.Documents.Open(itm.Text)

'Whole Page View

If ckBxWholePageView.Checked = True Then

AllPageWholeView(vDoc)

End If

System.Windows.Forms.MessageBox.Show("Done", MessageBoxButtons.OK)

vDoc.Close()

Next

Catch ex As Exception

System.Windows.Forms.MessageBox.Show(ex.Message)

End Try

End Sub
 
J

John

Hi Ken,

Thanks very much for this. It seems very easy for such a little word!

Did you have any advice on a) and c)?

Best regards

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top