Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Problem in Integer array in VB.net

Problem in Integer array in VB.net

Scheduled Pinned Locked Moved Visual Basic
helpcsharpdata-structurestutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kokilaB
    wrote on last edited by
    #1

    My code is like this to assign values to an integer array but i am getting an error like Object reference not set to an instance of an object... Dim StepNumber() As Integer = Nothing Dim Aindx As Integer = 0 ds = bl.GetStepDS(Session.Item("TestCase").ToString()) For Each record As DataRow In ds.Tables(0).Rows StepNumber(Aindx) = Aindx StepNameList(Aindx) = record.Item(0).ToString() Aindx = Aindx + 1 Next Can anybody please help me how to create and use Integer array? Thanks in advance

    S D 2 Replies Last reply
    0
    • K kokilaB

      My code is like this to assign values to an integer array but i am getting an error like Object reference not set to an instance of an object... Dim StepNumber() As Integer = Nothing Dim Aindx As Integer = 0 ds = bl.GetStepDS(Session.Item("TestCase").ToString()) For Each record As DataRow In ds.Tables(0).Rows StepNumber(Aindx) = Aindx StepNameList(Aindx) = record.Item(0).ToString() Aindx = Aindx + 1 Next Can anybody please help me how to create and use Integer array? Thanks in advance

      S Offline
      S Offline
      SHatchard
      wrote on last edited by
      #2

      Your array is not instanciated, try Dim StepNumber() As Integer = new integer() {}

      1 Reply Last reply
      0
      • K kokilaB

        My code is like this to assign values to an integer array but i am getting an error like Object reference not set to an instance of an object... Dim StepNumber() As Integer = Nothing Dim Aindx As Integer = 0 ds = bl.GetStepDS(Session.Item("TestCase").ToString()) For Each record As DataRow In ds.Tables(0).Rows StepNumber(Aindx) = Aindx StepNameList(Aindx) = record.Item(0).ToString() Aindx = Aindx + 1 Next Can anybody please help me how to create and use Integer array? Thanks in advance

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        kokilaB wrote:

        Dim StepNumber() As Integer = Nothing

        You declared an unbound array of Integers, then set it to Nothing. Bad idea. You also cannot assign values to an unbound array. The array has to have bounds in order to use it.

        ds = bl.GetStepDS(Session.Item("TestCase").ToString())
        If ds.Tables.Count > 0 Then
        If ds.Tables(0).Rows > 0 Then
        Dim StepNumber(ds.Tables(0).Rows.Count - 1) As Integer
        For Aindex As Integer = 0 to ds.Tables(0).Rows.Count - 1
        StepNumber(Aindex) = Aindex
        StepNameList(Aindex) = record.Item(0).ToString()
        Next
        '
        ' Do whatever you need to save and/or return the array here, because
        ' it won't exist outside this nested If statement.
        '
        End If
        End If

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups