I am having an issue with trying to take info from class and putting them into an array with the class data type. I am getting a null error. I can see its not adding the variable info into the array at all. I am unsure what it is I am missing. Can anyone point out to me what it is?
Here is the code:
Option Explicit On
Option Strict On
Option Infer Off
Public Class Form1
Public Class Chandelier
Private _strFinish As String
Private _intLights As Integer
Private _blnCrystal As Boolean
Private _dblTotal As Double
Public Property Finish As String
Get
Return _strFinish
End Get
Set(value As String)
_strFinish = value
End Set
End Property
Public Property Lights As Integer
Get
Return _intLights
End Get
Set(value As Integer)
If value > 0 Then
_intLights = value
Else
_intLights = 0
End If
End Set
End Property
Public Property Crystal As Boolean
Get
Return _blnCrystal
End Get
Set(value As Boolean)
_blnCrystal = value
End Set
End Property
Public Property Total As Double
Get
Return _dblTotal
End Get
Set(value As Double)
If value > 0 Then
_dblTotal = value
Else
_dblTotal = 0
End If
End Set
End Property
Public Sub New()
_strFinish = Nothing
_intLights = 0
_blnCrystal = False
_dblTotal = 0
End Sub
Public Function getCrystal() As Boolean
Return _blnCrystal
End Function
Public Function getPrice() As Double
Dim crystalPrice As Double
Dim price As Double
If _strFinish.Contains("Silver") Then
price = 39.99
If getCrystal() = True Then
crystalPrice = _intLights * 25.5
Else
crystalPrice = 0
End If
price = price + crystalPrice
End If
If _strFinish.Contains("Brass") Then
price = 49.99
If getCrystal() = True Then
crystalPrice = _intLights * 25.5
Else
crystalPrice = 0
End If
price = price + crystalPrice
End If
Return price
End Function
End Class
Public chandelierStyle(49) As Chandelier
Dim count As Integer = 0
Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
Dim ceilingOrnament As New Chandelier
ceilingOrnament.Finish = cboFinish.SelectedItem.ToString
Integer.TryParse(cboLights.SelectedItem.ToString, ceilingOrnament.Lights)
If chkTrimmings.Checked Then
ceilingOrnament.Crystal = True
End If
Dim dblTotal As Double = ceilingOrnament.getPrice()
ceilingOrnament.Total = dblTotal
If count <= 49 Then
'here is where the error starts
chandelierStyle(count).Finish = ceilingOrnament.Finish
chandelierStyle(count).Lights = ceilingOrnament.Lights
chandelierStyle(count).Crystal = ceilingOrnament.Crystal
chandelierStyle(count).Total = ceilingOrnament.Total
count += 1
End If
End Sub
_strFinish = Nothinginstead of setting it equal toString.EmptyorvbNullString? You cannot do_strFinish.Contains("Silver")if the string isNothing.