CLASSES

D

DotNetJunkies User

I’m getting an error “An unhandled exception of type 'System.NullReferenceException' occurred in 11_1_26.exe Additional information: Object reference not set to an instance of an object.†It points to st.num = CDbl(txtNumber.Text)
I cannot see what is wrong. Please help.


Dim statistic() As statistics
Dim lastnumber As Integer
Private Sub btnRecord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRecord.Click
Dim st As statistics
lastnumber += 1
st.num = CDbl(txtNumber.Text)
statistic(lastnumber) = st
txtNumber.Text = 0
txtNumber.Focus()
End Sub

Private Sub btnAverage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAverage.Click
txtAverage.Text = statistic(50).average
End Sub
End Class
Class statistics
Private m_count As Integer
Private m_num As Double
Public Property count() As Integer
Get
Return m_count
End Get
Set(ByVal Value As Integer)
m_count = Value
End Set
End Property
Public Property num() As Double
Get
Return m_num
End Get
Set(ByVal Value As Double)
m_num = Value
End Set
End Property
Sub addnumber()
Dim total As Double
total += m_num
End Sub
Function average() As Double
Dim av As Double
av = m_num / m_count
Return av
End Function
End Class
 
C

Cor Ligthert

Hi,
Dim statistic() As statistics
Dim lastnumber As Integer
Private Sub btnRecord_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnRecord.Click
Dim st As statistics

Dim st As New statics

However this will not help you, because I think you will use it in more
places in your program, and this is a new instance of statistics which lives
till the end of the sub.

One of the methods jto do this is to place

Private st As New statics

global (beneath the sentence designer created code).

I hope this helps?

Cor
 
H

Herfried K. Wagner [MVP]

* DotNetJunkies User said:
I’m getting an error “An unhandled exception of type 'System.NullReferenceException' occurred in 11_1_26.exe Additional information: Object reference not set to an instance of an object.� It points to st.num = CDbl(txtNumber.Text)
I cannot see what is wrong. Please help.

Dim st As statistics

\\\
st = New Statistics()
///
 

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