Results 1 to 19 of 19

Thread: [RESOLVED] Object reference not set to an instance of an object

Threaded View

  1. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2004
    Location
    Bloomingdale, IL USA
    Posts
    284

    Re: Object reference not set to an instance of an object

    Maybe I am not coding something right... I am new to VB.NET, most of my experience is in VBA and VB6.

    cmbX is a combobox passed from my load event of the form. The cmbTax is already drawn on the form... can I not pass it byRef to a class? Do I need to do something different with cmbX after it is passed to UpdateTaxProjectionCombobox?

    Code:
    Private Sub frmEntityTemplate_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    'This is in my form load event where cmbTax is a combobox that is drawn on my form.
            Dim TaxProj As New clsTaxEntity
            TaxProj.UpdateTaxProjectionCombobox(cmbTax)
    End Sub
    
    
     Public Sub UpdateTaxProjectionCombobox(ByRef cmbX As ComboBox)
            Try
    'I updated the code per your comments.
                Dim desc As New List(Of clsComboTag)
                Dim rsTax As New clsSQLData
    
                cmbX.Items.Clear()
    
                rsTax.ExecuteQuery("SELECT projection_year , tax_desc , ktax FROM tax_projection ORDER BY Projection_year")
    
                For Each drTax As DataRow In rsTax.sqlDataSet.Tables(0).Rows
                    desc.Add(New clsComboTag(String.Format("{0} {1}", drTax("projection_year").ToString.PadRight(10), drTax("tax_desc")), drTax("ktax").ToString))
                Next
    
                cmbX.DisplayMember = "Description"
                cmbX.ValueMember = "Value"
                cmbX.DataSource = desc
    
                rsTax = Nothing
    
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            End Try
        End Sub
    Last edited by si_the_geek; Jul 6th, 2018 at 01:50 PM. Reason: fixed typo in tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width