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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. How can I correct these 5 lines of code in vb.net

How can I correct these 5 lines of code in vb.net

Scheduled Pinned Locked Moved Visual Basic
csharphelpquestion
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.
  • G Offline
    G Offline
    Gjm
    wrote on last edited by
    #1

    Dim myarray() As Integer Dim i As Integer For i = 0 To 15 myarray(i) = 2 Next In the 4th line I gets an error message as under: Variable 'myarray' is used before it has been assigned a value. A null reference exception could result at runtime. Please correct the code ....

    G F 2 Replies Last reply
    0
    • G Gjm

      Dim myarray() As Integer Dim i As Integer For i = 0 To 15 myarray(i) = 2 Next In the 4th line I gets an error message as under: Variable 'myarray' is used before it has been assigned a value. A null reference exception could result at runtime. Please correct the code ....

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      You have declared a reference for an array, but not created the array itself. The easiest way to create the array is to specify the size (i.e. the highest index to use) when you declare the reference: Dim myarray(15) As Integer

      Despite everything, the person most likely to be fooling you next is yourself.

      1 Reply Last reply
      0
      • G Gjm

        Dim myarray() As Integer Dim i As Integer For i = 0 To 15 myarray(i) = 2 Next In the 4th line I gets an error message as under: Variable 'myarray' is used before it has been assigned a value. A null reference exception could result at runtime. Please correct the code ....

        F Offline
        F Offline
        Fawxes
        wrote on last edited by
        #3

        The array you are using hasn't been initialised, try Dim myArray(15) as Integer I find arrays cumbersome in .Net compaired to VB6 and so I tend to use ArrayLists or other collection methods instead.

        An optimist's glass is half full. A pessimist's glass is half empty. An engineer goes and gets the right size glass.

        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