0

No matter what I do, I end up with Object reference not set to an instance of an object at runtime. The problem is RptParamList().

The Structure is...

Partial Class WebReports_RptGeneric
    Inherits Page
    Protected ObjUtils As New Utilities
    Protected ObjDtn As New DataTable

    Structure SchedParms
        Shared ReportName As String
        Shared RptParamList() As ParameterValue
    End Structure

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim objSecurit As New STISecurity
        Dim intRc As Integer
        Dim objAudit As New Audits
        ...

    Public Sub XqtSaveSched(ByVal sender As System.Object, ByVal e As System.EventArgs)
        'Get Report Name and Report Parameters
        paramList.Clear()
        dt.Reset()
        dt = ObjUtils.GetDataTableForQuery("sp_GetPosFieldNames", paramList)
        ReDim SchedParms.RptParamList(13)
        SchedParms.RptParamList(0).Name = "rpFY" (BLOWS UP HERE!!)
        SchedParms.RptParamList(0).Value = CStr(Session("FY"))
        SchedParms.RptParamList(1).Name = "rpUserID"
        SchedParms.RptParamList(1).Value = "1000000"
        SchedParms.RptParamList(2).Name = "rpShowLinks"
        SchedParms.RptParamList(2).Value = CStr(False)

I tried adding the ReDim statement as an initializer, but that didn't work. I also tried SchedParms.RptParamList(0) = new ParameterValue() , but that didn't work either.

1 Answers1

0

You need to create an array with the New keyword, otherwise RptParamList will be Nothing

Shared RptParamList As ParameterValue() = New ParameterValue(13) {}

If the array can grow, use a List(Of ParameterValue), rather than redimmming an array. Lists do that automatically.

Shared RptParamList As New List(Of ParameterValue)()

Then add items with the Add method

SchedParms.RptParamList.Add(New ParameterValue())
Olivier Jacot-Descombes
  • 86,431
  • 10
  • 121
  • 160