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. Value for uninitialized elements of array

Value for uninitialized elements of array

Scheduled Pinned Locked Moved Visual Basic
data-structuresjsonhelpquestion
9 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.
  • H Offline
    H Offline
    hsprasain
    wrote on last edited by
    #1

    Hi: I have created two dimensional 2 x 2 array, and assigned values for 3 elements of an array only which is shown in the following code. I was bit wondering what values will be stored in the rest of the elements of array. I assumed "nothing" will be stored for them. But I got some exception handling errors. Can any help me? My Code: Dim s(2, 2) As String Dim x As String s(0, 0) = 1 s(0, 1) = 1 s(1, 0) = 1 x = s(1, 1) If x.Equals("") Then MessageBox.Show("Uninitialied arrray stored nothing") End If hsprasain

    D 1 Reply Last reply
    0
    • H hsprasain

      Hi: I have created two dimensional 2 x 2 array, and assigned values for 3 elements of an array only which is shown in the following code. I was bit wondering what values will be stored in the rest of the elements of array. I assumed "nothing" will be stored for them. But I got some exception handling errors. Can any help me? My Code: Dim s(2, 2) As String Dim x As String s(0, 0) = 1 s(0, 1) = 1 s(1, 0) = 1 x = s(1, 1) If x.Equals("") Then MessageBox.Show("Uninitialied arrray stored nothing") End If hsprasain

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

      They will contain Nothing, or in C#, null.

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

      H 1 Reply Last reply
      0
      • D Dave Kreskowiak

        They will contain Nothing, or in C#, null.

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

        H Offline
        H Offline
        hsprasain
        wrote on last edited by
        #3

        Hey: If they contain nothing, can you tell me why I'm getting unhandled exceptional error while running my code? Dim s(2, 3) As String Dim x As String s(0, 0) = 1 s(0, 1) = 1 s(1, 0) = 1 x = s(1, 1) If x.Equals(Nothing) Then MessageBox.Show("The value of x is :" + x) End If

        K 1 Reply Last reply
        0
        • H hsprasain

          Hey: If they contain nothing, can you tell me why I'm getting unhandled exceptional error while running my code? Dim s(2, 3) As String Dim x As String s(0, 0) = 1 s(0, 1) = 1 s(1, 0) = 1 x = s(1, 1) If x.Equals(Nothing) Then MessageBox.Show("The value of x is :" + x) End If

          K Offline
          K Offline
          Kschuler
          wrote on last edited by
          #4

          probably because of this line: MessageBox.Show("The value of x is :" + x) you can't add/concat x because it is nothing. just say this: MessageBox.Show("The value of x is : Nothing")

          H 1 Reply Last reply
          0
          • K Kschuler

            probably because of this line: MessageBox.Show("The value of x is :" + x) you can't add/concat x because it is nothing. just say this: MessageBox.Show("The value of x is : Nothing")

            H Offline
            H Offline
            hsprasain
            wrote on last edited by
            #5

            No. I tried what you have suggested but it showed me some exceptional handling errors. The debugger is showing an error at: If x.Equals(Nothing) Then

            K D 2 Replies Last reply
            0
            • H hsprasain

              No. I tried what you have suggested but it showed me some exceptional handling errors. The debugger is showing an error at: If x.Equals(Nothing) Then

              K Offline
              K Offline
              Kschuler
              wrote on last edited by
              #6

              Try: If x = nothing Then or If x Is Nothing Then

              H 1 Reply Last reply
              0
              • H hsprasain

                No. I tried what you have suggested but it showed me some exceptional handling errors. The debugger is showing an error at: If x.Equals(Nothing) Then

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

                Because in order to execute the Equals method on X, X actually has to have a reference to an object. It doesn't, so the exception, which you haven't told us anything about, should be "Object reference not set to an instance of an object."

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

                H 1 Reply Last reply
                0
                • D Dave Kreskowiak

                  Because in order to execute the Equals method on X, X actually has to have a reference to an object. It doesn't, so the exception, which you haven't told us anything about, should be "Object reference not set to an instance of an object."

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

                  H Offline
                  H Offline
                  hsprasain
                  wrote on last edited by
                  #8

                  thanks!!!

                  1 Reply Last reply
                  0
                  • K Kschuler

                    Try: If x = nothing Then or If x Is Nothing Then

                    H Offline
                    H Offline
                    hsprasain
                    wrote on last edited by
                    #9

                    Thanks man! It works well now.

                    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