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. declare an array of structures

declare an array of structures

Scheduled Pinned Locked Moved Visual Basic
questioncomdata-structureshelp
5 Posts 4 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.
  • T Offline
    T Offline
    Tom Wright
    wrote on last edited by
    #1

    How would I declare and array of structure so that it's visible in my class. This is in my declaration section Structure passenger Public passName As String Public passAdd As String Public passPhone As String Public SeatNum As String End Structure Public passengers(15) As passenger When I try to access passengers(0).passName in a sub, I get an error that says "Object reference not set to an instance of an object." So how do I declare it so that my whole class can see it? Thanks

    Tom Wright tawright915@gmail.com

    G D 2 Replies Last reply
    0
    • T Tom Wright

      How would I declare and array of structure so that it's visible in my class. This is in my declaration section Structure passenger Public passName As String Public passAdd As String Public passPhone As String Public SeatNum As String End Structure Public passengers(15) As passenger When I try to access passengers(0).passName in a sub, I get an error that says "Object reference not set to an instance of an object." So how do I declare it so that my whole class can see it? Thanks

      Tom Wright tawright915@gmail.com

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

      When you create an array of structures, they are all initalized to zero. That means that all the string references in the structure are null (Nohting in VB). If you try to use a string that doesn't exist, you get that error message.

      --- It's amazing to see how much work some people will go through just to avoid a little bit of work.

      T 1 Reply Last reply
      0
      • T Tom Wright

        How would I declare and array of structure so that it's visible in my class. This is in my declaration section Structure passenger Public passName As String Public passAdd As String Public passPhone As String Public SeatNum As String End Structure Public passengers(15) As passenger When I try to access passengers(0).passName in a sub, I get an error that says "Object reference not set to an instance of an object." So how do I declare it so that my whole class can see it? Thanks

        Tom Wright tawright915@gmail.com

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

        See this[^] thread for an explanation of what's going on.

        Dave Kreskowiak Microsoft MVP - Visual Basic

        P 1 Reply Last reply
        0
        • D Dave Kreskowiak

          See this[^] thread for an explanation of what's going on.

          Dave Kreskowiak Microsoft MVP - Visual Basic

          P Offline
          P Offline
          Paul Conrad
          wrote on last edited by
          #4

          Dave Kreskowiak wrote:

          See this[^] thread for an explanation of what's going on.

          I thought I saw the same kind of problem going on earlier :-O


          If you try to write that in English, I might be able to understand more than a fraction of it. - Guffa

          1 Reply Last reply
          0
          • G Guffa

            When you create an array of structures, they are all initalized to zero. That means that all the string references in the structure are null (Nohting in VB). If you try to use a string that doesn't exist, you get that error message.

            --- It's amazing to see how much work some people will go through just to avoid a little bit of work.

            T Offline
            T Offline
            Tom Wright
            wrote on last edited by
            #5

            Okay, I think I was trying to do private mypassenger(15) as new passenger in my declaration section. However I get a compile error that says you cannot use te new operator on an array. BBBBUUUTTT now I see what I am doing wrong. I'll try it out and see what happens. Thanks Tom

            Tom Wright tawright915@gmail.com

            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