0

I wrote an ASPX file in VB.NET. Originally this file ran successfully but after adding one additional parameter it now fails on "Object reference not set to an instance of an object" on line "peType.DataSource = arrPEType" below.

This error does not make sense to me though because I have similar parameter, 'dType', which it does not error on. What is the cause of this error?

Here is some of my ASPX code file:

Sub Page_Load(Sender as Object, E as EventArgs)
    If Not IsPostback Then 

      Dim TheMonthDate As Date = DateAdd(DateInterval.Month, -1, Today)
      calStartDate.SelectedDate = CDate((TheMonthDate.Month) & "/1/" & Year(TheMonthDate)).ToString("MM/dd/yyyy")
      calEndDate.SelectedDate = GlobalFunctions.GlobalF.MonthLastDate(CDate((TheMonthDate.Month) & "/1/" & Year(TheMonthDate)).ToString("MM/dd/yyyy"))

      Dim arrType as New ArrayList()
      Dim arrOrgUnit as New ArrayList()
      Dim arrPEType as New ArrayList()
      Dim peType As ListBox

      arrType.Add("Product and Process")
      arrType.Add("Product")       
       arrType.Add("Process")             
      dType.DataSource = arrType
      dType.DataBind()

      arrPEType.Add("-INC")
      arrPEType.Add("-NC")
      arrPEType.Add("-QC")
      peType.DataSource = arrPEType
      'peType.DataTextField = "DisplayColumnName"
      'peType.DataValueField = "ValueColumnName"
      peType.DataBind()
...
      Dim TheType as String
      Dim TheOrgUnit as String
      Dim PE_Type as String

      Select Case dType.SelectedValue
        Case "Product and Process": 
          TheType = "((SMARTSOLVE.V_QXP_ALL_EXCEPTION.QXP_BASE_EXCEPTION)='PXP_PRODUCT_QXP' Or (SMARTSOLVE.V_QXP_ALL_EXCEPTION.QXP_BASE_EXCEPTION)='PXP_PROCESS_QXP')"
        Case "Product": 
          TheType = "((SMARTSOLVE.V_QXP_ALL_EXCEPTION.QXP_BASE_EXCEPTION)='PXP_PRODUCT_QXP')"
        Case "Process": 
          TheType = "((SMARTSOLVE.V_QXP_ALL_EXCEPTION.QXP_BASE_EXCEPTION)='PXP_PROCESS_QXP')"
      End Select

      Select Case peType.SelectedValue
        Case "INC": 
          PE_Type = "substring(a.QXP_EXCEPTION_NO, charindex('-', a.QXP_EXCEPTION_NO)+1, 4)='INC'"
        Case "NC": 
          PE_Type = "substring(a.QXP_EXCEPTION_NO, charindex('-', a.QXP_EXCEPTION_NO)+1, 4)='NC'"
        Case "QC": 
          PE_Type = "substring(a.QXP_EXCEPTION_NO, charindex('-', a.QXP_EXCEPTION_NO)+1, 4)='QC'"
      End Select
...
          <td>
            Product Exception Type:
          </td>
          <td>
            <ASP:DROPDOWNLIST ID="peType" RUNAT="Server" AUTOPOSTBACK="true" />
          </td>

2 Answers 2

2

You're not instantiating your ListBox, your simply declaring it.

Dim peType As ListBox()

...should be...

Dim peType As New ListBox()

Although the error may appear to be vague, it's telling you the exact problem. Your object, peType, is not set to an instance of an object.

Sign up to request clarification or add additional context in comments.

Comments

1

You haven't created the object.

You have:

Dim peType As ListBox

You should have:

Dim peType As new ListBox

or be finding an existing ListBox from your UI.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.