Weather forecast VBA (1 Viewer)

Gasman

Enthusiastic Amateur
Local time
Today, 21:47
Joined
Sep 21, 2011
Messages
14,310
I have correct paths.
That resolves to C:\Temp\Weather\weather_icons\.png

Then the DIR for strLocalImagePath fails and the sources never get set.
If I change back to your zip code, there is data in the xml file which does not allow this, and so the icons are shown.?
 

gwynn76

Registered User.
Local time
Today, 15:47
Joined
Mar 15, 2019
Messages
16
C:\Temp\Weather\weather_icons\.png - Why are you using the .png in your path? To grab the images from the folder, you should have nothing after the backslash (\). That allows the code to find the right image in the specified folder.

"\\BIDMAGIC-SERVER\Microsoft SQL Server\Tracker DB BE\Front End\weather_icons" <--- my path ENDS after the backslash and is closed. Try removing the .png and close the path after the backslash. The ONLY place you should have .png is at the end of the days when you are assigning the path to the XML:

'===============END DAYS==============================

'// the image path(s) ---- Day 0

strLocalImagePath = strLocalImagePath & WeatherConditions.selectSingleNode("icon").Text & ".png"

See if that works.
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:47
Joined
Sep 21, 2011
Messages
14,310
Here is my weather2.xml file if you want to try a non US address.?

I had to add a txt extension to upload it.
 

Attachments

  • Weather2.xml.txt
    4.4 KB · Views: 72

Gasman

Enthusiastic Amateur
Local time
Today, 21:47
Joined
Sep 21, 2011
Messages
14,310
No you misunderstand.

That is what I get at that line of code. I have an initial correct path ending in a \
As there is nothing in the icon.text property just .png gets appended.

C:\Temp\Weather\weather_icons\.png - Why are you using the .png in your path? To grab the images from the folder, you should have nothing after the backslash (\). That allows the code to find the right image in the specified folder.

"\\BIDMAGIC-SERVER\Microsoft SQL Server\Tracker DB BE\Front End\weather_icons" <--- my path ENDS after the backslash and is closed. Try removing the .png and close the path after the backslash. The ONLY place you should have .png is at the end of the days when you are assigning the path to the XML:

'===============END DAYS==============================

'// the image path(s) ---- Day 0

strLocalImagePath = strLocalImagePath & WeatherConditions.selectSingleNode("icon").Text & ".png"

See if that works.
 

gwynn76

Registered User.
Local time
Today, 15:47
Joined
Mar 15, 2019
Messages
16
When I plug in your location data, it populates correctly on my end (see images). So, I'm not sure why it wouldn't populate on yours unless the image paths were off somewhere or you changed the day0 from the lsup. The only reason it would have for not adding an image otherwise would be if there wasn't an icon in the XML line for "Day0" (as it shows in your XML file). After a certain point, "future" weather (under Day0) is no longer future - it is current - which is why it's better to use the icon for day 0 as the icon under <cc> for <lsup>. That is ever revolving as the day progresses. The other days icons will progress to lsup as the "future" weather becomes the current weather. Does that make sense? Day0 is "today".

'==WEATHER DAYS: Day 0=======
.labelLocation.caption = WeatherLocation.selectSingleNode("dnam").Text

.imgWeatherIcon.ControlTipText = "Updated " & WeatherConditions.selectSingleNode("lsup").Text
.LabelSunr.caption = WeatherDay.selectSingleNode("day[@d='1']/sunr").Text
 

Attachments

  • MWSnap017.jpg
    MWSnap017.jpg
    96.9 KB · Views: 73
  • MWSnap018.jpg
    MWSnap018.jpg
    102.6 KB · Views: 63

gwynn76

Registered User.
Local time
Today, 15:47
Joined
Mar 15, 2019
Messages
16
Your online XML feed attached...
There are a few missing elements in this XML feed. Your problem might simply be the missing data. A DB is only as good as the data put into it and this file is sketchy. It's entirely possible you might need to wait a day or two and then try looking at the live XML feed to see if the data is available for parsing into the DB. Until you get your kinks worked out, I'd suggest using the location ID supplied to test your paths.
 

Attachments

  • MWSnap019.jpg
    MWSnap019.jpg
    42.9 KB · Views: 79

Gasman

Enthusiastic Amateur
Local time
Today, 21:47
Joined
Sep 21, 2011
Messages
14,310
OK, I'll check more. There is a lot to take in after all.

However I was going on this part of the code in the form

Code:
? WeatherConditions.selectSingleNode("icon").Text & ".png"
.png

with the xml file
Code:
	<cc>
		<lsup>5/06/19 5:00 PM BST</lsup>
		<obst>Mumbles Head, SWA, UK</obst>
		<tmp>50</tmp>
		<flik>43</flik>
		<t></t>
		<icon></icon>
		<bar>
			<r>30.03</r>
			<d>falling rapidly</d>
		</bar>
		<wind>
			<s>22</s>
			<gust>N/A</gust>
			<d>240</d>
			<t>WSW</t>
		</wind>
		<hmid>69</hmid>
		<vis></vis>
		<uv>
			<i>2</i>
			<t>Low</t>
		</uv>
		<dewp>40</dewp>
		<moon>
			<icon>1</icon>
			<t>Waxing Crescent</t>
		</moon>
	</cc>
	<dayf>
		<lsup>5/06/19 7:00 AM BST</lsup>
		<day d="0" t="Monday" dt="May 6">
			<hi>50</hi>
			<low>42</low>
			<sunr>5:39 AM</sunr>
			<suns>8:47 PM</suns>
			<part p="d">
				<icon></icon>
				<t></t>
				<wind>
					<s>calm</s>
					<gust>N/A</gust>
					<d>0</d>
					<t>CALM</t>
				</wind>
				<bt></bt>
				<ppcp>0</ppcp>
				<hmid>0</hmid>
			</part>
			<part p="n">
				<icon>26</icon>
				<t>Cloudy</t>
				<wind>
					<s>calm</s>
					<gust>N/A</gust>
					<d>0</d>
					<t>CALM</t>
				</wind>
				<bt>Cloudy</bt>
				<ppcp>10</ppcp>
				<hmid>76</hmid>
			</part>
		</day><day d="1" t="Tuesday" dt="May 7">

I'll need to step through it all.
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:47
Joined
Sep 21, 2011
Messages
14,310
That was my thoughts.
I'm not trying to blame your program :D, just that another situation *might* need to be catered for.?

I put that down to putting your location back in, populated those icon entries, where as mine did not?

Your online XML feed attached...
There are a few missing elements in this XML feed. Your problem might simply be the missing data. A DB is only as good as the data put into it and this file is sketchy. It's entirely possible you might need to wait a day or two and then try looking at the live XML feed to see if the data is available for parsing into the DB. Until you get your kinks worked out, I'd suggest using the location ID supplied to test your paths.
 

gwynn76

Registered User.
Local time
Today, 15:47
Joined
Mar 15, 2019
Messages
16
From your excerpt:
<flik>43</flik>
<t></t>
<icon></icon>
<bar>

Yes, there isn't an "icon" specified in the XML file - nor a title for the weather condition. That's not your fault. Or the programs fault. That's the services fault lol. For some reason the location specified isn't adding that information to the live XML feed. Without it, you are unable to populate those fields. I'm not sure how you'd go about that except for maybe building in a "if null" and telling it to go to next? Not sure. But if everything is working with the supplied location data, then you have everything set up correctly and it's just the live data that's messing with you. Gotta love broken data.

I've never had fields come across as empty so I might have to play around with your location and see if I can figure out the "if null" part.
 

gwynn76

Registered User.
Local time
Today, 15:47
Joined
Mar 15, 2019
Messages
16
Hey June! Thanks. That was actually one of the many posts I visited when creating this :) Everything works but when the live XML doesn't include information, I need to figure out how to make it skip that line and continue on to the next. Gasman's XML feed is missing data :-(
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:47
Joined
Sep 21, 2011
Messages
14,310
FWIW I have checked the file using the Dir function and if it comes up empty have used the na.png icon as a default.?
 

gwynn76

Registered User.
Local time
Today, 15:47
Joined
Mar 15, 2019
Messages
16
How did you code that (as in did you go through each icon element since there are several)? OR did you blanket code for the elements? And does it work?
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:47
Joined
Sep 21, 2011
Messages
14,310
Just a simple test before the image paths.
So far it has only been the first two lines in this code
Just a hack to see if I could understand what was going on and then only on one form.?

Code:
           '// the image path(s) ---- Day
            strLocalImagePath = strDayImagePath & WeatherConditions.selectSingleNode("icon").Text & ".png"
            strDayImagePath = strDayImagePath & WeatherDay.selectSingleNode("day/part/icon").Text & ".png"
            strMoonImagePath = strMoonImagePath & WeatherConditions.selectSingleNode("moon/icon").Text & ".png"
            strDay1ImagePath = strDay1ImagePath & WeatherDay.selectSingleNode("day[@d='1']/part[@p='d']/icon").Text & ".png"
            strDay2ImagePath = strDay2ImagePath & WeatherDay.selectSingleNode("day[@d='2']/part[@p='d']/icon").Text & ".png"
            strDay3ImagePath = strDay3ImagePath & WeatherDay.selectSingleNode("day[@d='3']/part[@p='d']/icon").Text & ".png"
            strDay4ImagePath = strDay4ImagePath & WeatherDay.selectSingleNode("day[@d='4']/part[@p='d']/icon").Text & ".png"
            strDay5ImagePath = strDay5ImagePath & WeatherDay.selectSingleNode("day[@d='5']/part[@p='d']/icon").Text & ".png"
            strDay6ImagePath = strDay6ImagePath & WeatherDay.selectSingleNode("day[@d='6']/part[@p='d']/icon").Text & ".png"
            strDay7ImagePath = strDay7ImagePath & WeatherDay.selectSingleNode("day[@d='7']/part[@p='d']/icon").Text & ".png"
            strDay8ImagePath = strDay8ImagePath & WeatherDay.selectSingleNode("day[@d='8']/part[@p='d']/icon").Text & ".png"
            strDay9ImagePath = strDay9ImagePath & WeatherDay.selectSingleNode("day[@d='9']/part[@p='d']/icon").Text & ".png"
            
            '// test if icon exist and display the appropriate image
            If Dir(strLocalImagePath, vbNormal) = "" Then
                strLocalImagePath = cstrBasePath & "weather_icons\na.png"
            End If
            If Dir(strDayImagePath, vbNormal) = "" Then
                strDayImagePath = cstrBasePath & "weather_icons\na.png"
            End If
           
            If Not Dir(strLocalImagePath, vbNormal) = "" Then
                .imgWeatherIcon.Picture = strLocalImagePath
                .imgWeatherIcon2.Picture = strMoonImagePath
                .imgWeatherIcon3.Picture = strDayImagePath
                .imgWeatherIcon4.Picture = strDay1ImagePath
                .imgWeatherIcon6.Picture = strDay2ImagePath
                .imgWeatherIcon8.Picture = strDay3ImagePath
                .imgWeatherIcon10.Picture = strDay4ImagePath
                .imgWeatherIcon12.Picture = strDay5ImagePath
                .imgWeatherIcon13.Picture = strDay6ImagePath
                .imgWeatherIcon14.Picture = strDay7ImagePath
                .imgWeatherIcon15.Picture = strDay8ImagePath
                .imgWeatherIcon16.Picture = strDay9ImagePath

            End If
 

Users who are viewing this thread

Top Bottom