Setting picture based on InnerText only works sometimes

Blake81

Well-known member
Joined
Feb 23, 2006
Messages
304
Location
Georgia, USA
Programming Experience
1-3
I'm trying to set the images for several PictureBoxes based on the value of certain XML InnerText, and the image on the first tab works, but the images for each of the four days in the forecast do not get set. I've step-debugged, and the values for the variables are what I want them to be, but the pictures don't get set. I've also noticed that the data for the forecast tab doesn't get put in either. I'm not sure where the problem is in this case. I'll post the code for the GetForecast() subroutine and also include a link to the XML weather so you can see its structure. This program is about 650 lines of code, which is the longest I've done so far, so it's hard for me to track this problem down. Thanks.
VB.NET:
[SIZE=2][COLOR=#0000ff]    Public Sub GetForecast()
        Wlocation2.Text = Wlocation.Text
        ZIP.Text = ""
        Dim Fnodes As System.Xml.XmlNodeList
        Dim Fnode As System.Xml.XmlNode
        Fnode = xmldocument.SelectSingleNode("/weather/dayf") 'I moved this a level up so that you can access all the days, rather than just the first
        Fnodes = Fnode.ChildNodes
        'Day1Label.Text = Fnode.SelectSingleNode("day").Attributes("dt").InnerText 'Instead of going through a for loop, just request the attribute directly
        Dim FNext As System.Xml.XmlNode
        Dim x As Integer = 1
        For Each FNext In Fnodes
            If FNext.Name = "day" Then
                x = FNext.Attributes("d").InnerText '+ 1 if you want to x to be 1 when the day is today.
                Select Case x
                    Case 1
                        Day1Label.Text = FNext.Attributes("dt").InnerText
                    Case 2
                        Day2Label.Text = FNext.Attributes("dt").InnerText
                    Case 3
                        Day3Label.Text = FNext.Attributes("dt").InnerText
                    Case 4
                        Day4Label.Text = FNext.Attributes("dt").InnerText
                End Select
                Fnode = FNext.SelectSingleNode("hi")
                Select Case x 'Changed the if statments to a select
                    Case 1
                        Day1HighTemp.Text = Fnode.InnerText
                    Case 2
                        Day2HighTemp.Text = Fnode.InnerText
                    Case 3
                        Day3HighTemp.Text = Fnode.InnerText
                    Case 4
                        Day4HighTemp.Text = Fnode.InnerText
                End Select
                Fnode = FNext.SelectSingleNode("low")
                Select Case x
                    Case 1
                        Day1LowTemp.Text = Fnode.InnerText
                    Case 2
                        Day2LowTemp.Text = Fnode.InnerText
                    Case 3
                        Day3LowTemp.Text = Fnode.InnerText
                    Case 4
                        Day4LowTemp.Text = Fnode.InnerText
                End Select
                Select Case x
                    Case 1
                        Dim Day1Icon As String = "a" & xmldocument.SelectSingleNode("/weather/dayf/day[@d='1']/part[@p='d']/icon").InnerText
                        Day1Pic.ImageLocation = My.Resources.ResourceManager.GetObject(Day1Icon)
                    Case 2
                        Dim Day2Icon As String = "a" & xmldocument.SelectSingleNode("/weather/dayf/day[@d='2']/part[@p='d']/icon").InnerText
                        Day2Pic.ImageLocation = My.Resources.ResourceManager.GetObject(Day2Icon)
                    Case 3
                        Dim Day3Icon As String = "a" & xmldocument.SelectSingleNode("/weather/dayf/day[@d='3']/part[@p='d']/icon").InnerText
                        Day3Pic.ImageLocation = My.Resources.ResourceManager.GetObject(Day3Icon)
                    Case 4
                        Dim Day4Icon As String = "a" & xmldocument.SelectSingleNode("/weather/dayf/day[@d='4']/part[@p='d']/icon").InnerText
                        Day4Pic.ImageLocation = My.Resources.ResourceManager.GetObject(Day4Icon)
                End Select
            End If
        Next FNext
        HiddenZip.Text = ""
    End Sub[/COLOR][/SIZE]
http://xoap.weather.com/weather/local/30117?cc=*&dayf=5
 
Last edited by a moderator:
Back
Top