[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
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
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.
Re: Array displays Root Namespace
Quote:
Originally Posted by
justphilip
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?
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
Re: Array displays Root Namespace
Please ignore previous post - I found my error! Jp
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
Re: [RESOLVED] Array displays Root Namespace
I was referring to the data that filled the text boxes.