azyet24
asked on
Handling Arrays
I am having an issue with an array (actually two). I am parsing a string from a database to display it on a website. The string is like value;position,value;posit ion
My code first splits on the comma which give me value;position in one array. I then split that into another array on the semicolon. This works great most of the time. However, some instances the "position" in the string will be missing from the data so I get an out of index error. I've tried to look for floor.length > 0 or see if this is null but that doesn't help. below is the code snippet
My code first splits on the comma which give me value;position in one array. I then split that into another array on the semicolon. This works great most of the time. However, some instances the "position" in the string will be missing from the data so I get an out of index error. I've tried to look for floor.length > 0 or see if this is null but that doesn't help. below is the code snippet
Sample data: MasterBedroom;1,Den;,GreatRoom;,Bedroom;1,Bedroom;1,Bedroom;B,FullBath;B,FullBath;1,FullBath;1,DiningRoom;
in this example, MaterBedroom is the value, 1 is the position. Notice that Den is the next value, but is missing position. Desire is to put "Main Floor" where no position is provided.
Code:
If Not objRdr("rooms") Is DBNull.Value Then
lblDiningAreas.Text = "<table>"
Dim rooms() As String
Dim floor() As String
rooms = objRdr("rooms").Split(",")
For j As Integer = 0 To rooms.Length - 1
lblDiningAreas.Text &= "<tr><td class='content'><b>"
floor = rooms(j).Split(";")
lblDiningAreas.Text &= floor(0) & "</b></td><td class='content'> "
If floor.Length > 0 Then
Select Case floor(1)
Case "1"
lblDiningAreas.Text &= "Main Level" & "</td></tr>"
Case "2"
lblDiningAreas.Text &= "Upper Level" & "</td></tr>"
Case "3"
lblDiningAreas.Text &= "Upper Level" & "</td></tr>"
Case "4"
lblDiningAreas.Text &= "Upper Level" & "</td></tr>"
Case "5"
lblDiningAreas.Text &= "Upper Level" & "</td></tr>"
Case "6"
lblDiningAreas.Text &= "Upper Level" & "</td></tr>"
Case "7"
lblDiningAreas.Text &= "Upper Level" & "</td></tr>"
Case "8"
lblDiningAreas.Text &= "Upper Level" & "</td></tr>"
Case "9"
lblDiningAreas.Text &= "Upper Level" & "</td></tr>"
Case "B"
lblDiningAreas.Text &= "Basement" & "</td></tr>"
End Select
Else
lblDiningAreas.Text &= "Main Level" & "</td></tr>"
End If
Out put looks like:
MasterBedroom Main Level
etc.. etc...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.