Visual Basic Development Bookmark and Share   
 Home > Visual Basic Interop and Upgrade > Can anyone Resolve this NullReferenceException?
 

Can anyone Resolve this NullReferenceException?

I'm pasting the whole code, for the ease of you, in this the bold line was giving continues error:

Option Explicit On
Option Compare Text

Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports Microsoft.Office.Interop.Excel


Public Class TestForm

Private Sub TestForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x() As Object = {2.648305, 4.934211, 7.04005, 9.014423, 11.09467, 13.0814, 15.06889, 17.08428}
Dim y() As Object = {15, 30, 45, 60, 75, 90, 105, 120}
Dim z(y.Length - 1) As Object
Dim i, j, k As Integer
Dim xstr, ystr, zstr As String
Dim exApp As Microsoft.Office.Interop.Excel.WorksheetFunction
Try
For i = 0 To x.Length
For j = 0 To y.Length
For k = 0 To z.Length
z(k) = exApp.Slope(y(j), x(i))
Next
Next
Next
For i = 0 To x.Length
xstr += x(i).ToString()
Next
For j = 0 To y.Length
ystr += y(j).ToString()
Next
For k = 0 To z.Length
zstr += z(k).ToString()
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
xLabel.Text = "X=" + xstr.ToString()
yLabel.Text = "Y=" + ystr.ToString()
zLabel.Text = "Z=" + zstr.ToString()
End Sub
End Class


The Bold Line always gives the same error:
System.NullReferenceException was caught
Message="Object reference not set to an instance of an object."
Source="AdsorptionSimulator"
StackTrace:
at ChemChart.TestForm.Button1_Click(Object sender, EventArgs e) in C:\ChemChart\ChemChart\Forms\TestForm.vb:line 39
InnerException:


Please Can Anyone Help me, I need the Code urgently.

Thanx in advance,

- Rajeev
Rajeev_RSD  Saturday, November 07, 2009 1:16 PM
Hi Rajeev,

Use 'Length - 1' as the upperlimit.
The follownig may work.

For i = 0 To x.Length -1
For j = 0 To y.Length -1
For k = 0 To z.Length -1
z(k) = exApp.Slope(y(j), x(i))
Next
Next
Next


hope this helps.

Regards,
Kalyan
  • Marked As Answer byRajeev_RSD Monday, November 09, 2009 12:34 PM
  •  
mepersona  Monday, November 09, 2009 12:18 PM
Hi Rajeev,

Use 'Length - 1' as the upperlimit.
The follownig may work.

For i = 0 To x.Length -1
For j = 0 To y.Length -1
For k = 0 To z.Length -1
z(k) = exApp.Slope(y(j), x(i))
Next
Next
Next


hope this helps.

Regards,
Kalyan
  • Marked As Answer byRajeev_RSD Monday, November 09, 2009 12:34 PM
  •  
mepersona  Monday, November 09, 2009 12:18 PM

You can use google to search for other answers

Custom Search

More Threads

• vb5 to vb2005 express
• Can't get Powerpoint to run through my slides, what am I doing wrong?
• Retrieving the COM class factory for component with CLSID...
• Application throws 'System.UnauthorizedAccessException' runnin without admin privileges
• Expose System.URI to VB6 Application
• Upgrade datagrid to vb2005
• VB 2008 expresess
• calling a vb .net callback from unmanaged c++
• Equivalent of VB5 Datacontrol and related objects/methods/properties in VB2008 ?
• Problem with Events