[RESOLVED] Array displays Root Namespace-VBForums
Results 1 to 8 of 8

Thread: [RESOLVED] Array displays Root Namespace

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2016
    Posts
    125

    Resolved [RESOLVED] Array displays Root Namespace

    The problem logic displays the Root Namespace data in each field; since it appeared to work, I did not change it.
    First question: is ‘StateName’ unecessary redunance in USSTLoad(0, 0).StateName?
    Second question: is it causing the namespace display? I can see no problem in the For/Next logic. TIA JP

    Code:
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            ' Add six elements to the structered arrays.
    
            USSTLoad(0, 0).StateName = "Alabama"
            USSTLoad(0, 1).StdAbrv = "Ala."
            USSTLoad(0, 2).PostalAbrv = "AL"
            USSTLoad(0, 3).CapitalCity = "Montgomery"
    
            USSTLoad(1, 0).StateName = "Alaska"
            USSTLoad(1, 1).StdAbrv = "Alaaska"
            USSTLoad(1, 2).PostalAbrv = "Ak"
            USSTLoad(1, 3).CapitalCity = "Juneau"
    
            USSTLoad(2, 0).StateName = "Arizona"
            USSTLoad(2, 1).StdAbrv = "Ariz."
            USSTLoad(2, 2).PostalAbrv = "AL"
            USSTLoad(2, 3).CapitalCity = "Phoenix"
    
            USSTLoad(3, 0).StateName = "Arkansas"
            USSTLoad(3, 1).StdAbrv = "Ark."
            USSTLoad(3, 2).PostalAbrv = "AR"
            USSTLoad(3, 3).CapitalCity = "Little Rock"
    
            USSTLoad(4, 0).StateName = "California"
            USSTLoad(4, 1).StdAbrv = "Calf."
            USSTLoad(4, 2).PostalAbrv = "CA"
            USSTLoad(4, 3).CapitalCity = "Sacramento"
    
            USSTLoad(5, 0).StateName = "Colorado"
            USSTLoad(5, 1).StdAbrv = "Colo."
            USSTLoad(5, 2).PostalAbrv = "CO"
            USSTLoad(5, 3).CapitalCity = "Denver"
    
            MaxIndexInterger = 5
           ‘ Good Data Displayed
    
            MessageBox.Show("Last Entry: " & Environment.NewLine &
                    USSTLoad(MaxIndexInterger, 0).StateName & Environment.NewLine &
                    USSTLoad(MaxIndexInterger, 1).StdAbrv & Environment.NewLine &
                    USSTLoad(MaxIndexInterger, 2).PostalAbrv & Environment.NewLine &
                    USSTLoad(MaxIndexInterger, 3).CapitalCity & Environment.NewLine,
                     "Input Check!", MessageBoxButtons.OK, MessageBoxIcon.Question)
    
        End Sub
    Errant code that displays Root Namespace in each field!

    Code:
        Private Sub SearchByPostal()
            For RowIndex As Integer = 0 To MaxIndexInterger
    
    
                ' Error at 'If' statement not working, going to MaxIndexInteger then invokes DisplayFindings()
                ' at RowIndex = MaxIndexInteger + 1, USSTLoad(RowIndex, 2) Displays Root Namespace! Yet if I
                ' key in the first structure data point, it knows to stop and display. 
    
    
                If PostalAbrvTextBox.Text = USSTLoad(RowIndex, 2).ToString Then
    
                    DisplayIndex = RowIndex
    
                    DisplayFindings()
                    Exit For
                Else
                    MessageBox.Show("RowIndex = " & RowIndex, "Missing input!", MessageBoxButtons.OK,
                               MessageBoxIcon.Question)
    
                End If
            Next RowIndex
        End Sub
    
     Private Sub DisplayFindings()
    
            StateNameTextBox.Text = USSTLoad(DisplayIndex, 0).ToString
            StdAbrvTextBox.Text = USSTLoad(DisplayIndex, 1).ToString
            PostalAbrvTextBox.Text = USSTLoad(DisplayIndex, 2).ToString
            StateCapitalTextBox.Text = USSTLoad(DisplayIndex, 3).ToString
    
        End Sub

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,285

    Re: Array displays Root Namespace

    No... it's not redundant... it's a bad setup... you've got USSTLOAD defined as two dimentional array... and it's an array of a type of structure that has 4 properties to it. What you probably should be doing is a SINGLE dimention array...
    Code:
            USSTLoad(0).StateName = "Alabama"
            USSTLoad(0).StdAbrv = "Ala."
            USSTLoad(0).PostalAbrv = "AL"
            USSTLoad(0).CapitalCity = "Montgomery"
    OR a two-dimention array but no structure
    Code:
            USSTLoad(0, 0) = "Alabama"
            USSTLoad(0, 1) = "Ala."
            USSTLoad(0, 2) = "AL"
            USSTLoad(0, 3) = "Montgomery"
    Personally I'd go with the single-dimention array and the structure...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2016
    Posts
    125

    Re: Array displays Root Namespace

    Thanks for the response. Did I miss something?

    Code:
        Private USSTLoad(59)
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            ' Add six elements to the structered arrays.
    
            USSTLoad(0).StateName = "Alabama"
            USSTLoad(0).StdAbrv = "Ala."
            USSTLoad(0).PostalAbrv = "AL"
            USSTLoad(0).CapitalCity = "Montgomery"
    USSTLoad(0).StateName = "Alabama" Gave me this error message: System.NullReferenceException: 'Object variable or With block variable not set.'
    In researching 'Get' & 'Set' I found described as no longer supported, so what is the message telling me? TIA JP

    I assume the same error will occur in all lines.

  4. #4
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,126

    Re: Array displays Root Namespace

    Quote Originally Posted by justphilip View Post
    Thanks for the response. Did I miss something?

    Code:
        Private USSTLoad(59)
    Always work with Option Strict turned on. If you had it on, the IDE would be telling you that you need to provide an 'As' clause:
    Code:
    Private USSTLoad(59) As YourStructureType
    Presumably when you initialised your 2D array earlier, you specified the Type at that time?

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2016
    Posts
    125

    Re: Array displays Root Namespace

    Thanks for your response. Hopefully I have made your indicated changes; the ‘message.show’ in the load process displayed good data but when I reach the for/next logic I get the same Root Namespace displays. Do I have a data type problem? Why on no match does it not do the else? TIA JP

    Code:
      ' Declare Structure() And Module-level variables
        Public Structure USStateTable
            Public StateName As String
            Public StdAbrv As String
            Public PostalAbrv As String
            Public CapitalCity As String
        End Structure
    
        Private USSTLoad(177) As USStateTable
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            ' Add six elements to the structered arrays.
    
            USSTLoad(0).StateName = "Alabama"
            USSTLoad(0).StdAbrv = "Ala."
            USSTLoad(0).PostalAbrv = "AL"
            USSTLoad(0).CapitalCity = "Montgomery"
    
         USSTLoad(5).StateName = "Colorado"
            USSTLoad(5).StdAbrv = "Colo."
            USSTLoad(5).PostalAbrv = "CO"
            USSTLoad(5).CapitalCity = "Denver"
    
            MaxIndexInterger = 5
            MessageBox.Show("Last Entry: " & Environment.NewLine &
                    USSTLoad(MaxIndexInterger).StateName & Environment.NewLine &
                   USSTLoad(MaxIndexInterger).StdAbrv & Environment.NewLine &
                    USSTLoad(MaxIndexInterger).PostalAbrv & Environment.NewLine &
                    USSTLoad(MaxIndexInterger).CapitalCity & Environment.NewLine,
                     "Input Check!", MessageBoxButtons.OK, MessageBoxIcon.Question)
    ‘ good data displayed
        End Sub
    
            For RowIndex As Integer = 0 To MaxIndexInterger
    
            ' Error at 'If' statement not working, going to MaxIndexInteger then invokes DisplayFindings() instead of not found message
            ' at RowIndex = MaxIndexInteger + 1, USSTLoad(RowIndex, 2) Displays Root Namespace! Yet if I
            ' key in the first structure data point, it knows to stop and display. 
    
                If PostalAbrvTextBox.Text = USSTLoad(RowIndex).PostalAbrv.ToString Then
                    DisplayFindings()
                    Exit For
                Else
                    MessageBox.Show("RowIndex = " & RowIndex, "Missing input!", MessageBoxButtons.OK,
                               MessageBoxIcon.Question)
    
                End If
            Next RowIndex
        End Sub
    
       Private Sub DisplayFindings()
    
            StateNameTextBox.Text = USSTLoad(RowIndex).ToString
            StdAbrvTextBox.Text = USSTLoad(RowIndex).ToString
            PostalAbrvTextBox.Text = USSTLoad(RowIndex).ToString
            StateCapitalTextBox.Text = USSTLoad(RowIndex).ToString
    
        End Sub
    Last edited by justphilip; May 19th, 2017 at 10:17 AM.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2016
    Posts
    125

    Re: Array displays Root Namespace

    Please ignore previous post - I found my error! Jp

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,285

    Re: Array displays Root Namespace

    Also, just for clarification, those are structure properties, not namespaces. Namespaces are a completely different animal and isn't in play here.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Nov 2016
    Posts
    125

    Re: [RESOLVED] Array displays Root Namespace

    I was referring to the data that filled the text boxes.

Tags for this Thread

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.