By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,215 Members | 1,920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,215 IT Pros & Developers. It's quick & easy.

Find line that throws exception

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

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

Dim openingForm As New Form1

Ken
---------------
"John" <Jo************@AOL.net> wrote in message
news:um*************@tk2msftngp13.phx.gbl...
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

Nov 21 '05 #2

P: n/a
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
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:u8**************@TK2MSFTNGP15.phx.gbl...
Hi,

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

Dim openingForm As New Form1

Ken
---------------
"John" <Jo************@AOL.net> wrote in message
news:um*************@tk2msftngp13.phx.gbl...
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

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.