Weather forecast VBA (1 Viewer)

gwynn76

Registered User.
Local time
Today, 11:58
Joined
Mar 15, 2019
Messages
16
Ok... attached is a sample. I was able to get this to work on 1 day but once I started trying to get in a 6 day I started running into all kinds of walls. :banghead:

I changed the labels back to the same as the 1 day to stop the errors but obviously that just populates the same day over and over again.

XML is used to pull the data - XML files are included as well though the data is pulled from a live XML feed. Obviously the image location isn't available so will probably throw errors. I'm wondering if anyone is able to help me get the VBA correct on the 6 day forecast? I scrapped the broken coding and paired the 6 day down to the bare bones of the 1 day so no one gets led down the rabbit hole.

Thank you all in advance for any assistance!
:)
 

Attachments

  • Sample.zip
    1.6 MB · Views: 233

Mark_

Longboard on the internet
Local time
Today, 09:58
Joined
Sep 12, 2017
Messages
2,111
Before rooting around in an unknown database that is all but assured to have problems, can you please be very clear in what you are trying to do, how you are trying to do it, and specify the error or issue you are encountering?

This could be as simple as
"I go into FrmMyProblemForm and click on the "MyProblemName" field. Instead of it turning mauve and making a beeping sound, it is acting like a normal entry field. Please see below sample of code that is supposed to make it mauve and beep at me".
 

gwynn76

Registered User.
Local time
Today, 11:58
Joined
Mar 15, 2019
Messages
16
I am trying to do exactly what it said: pull the 6 day forecast from the XML file to populate the fields. It’s only 2 forms. The first form already populates correctly. That form is the one day forecast. Included to show it works. The second form is the 6 day forecast. I can only get it to populate the the first “window” of the six day forecast and when I was coding in for the other “windows” (for the other 5 days) I couldn’t get the coding right to continue. Another words... it works for 1 day on the 6 day forecast (like the one day forecast form) but since I couldn’t get the other fields to populate from the xml file, I changed the fields back to match the first “window” on the 6 day forecast form and scrapped the coding. I just need help figuring out how to move foreword because obviously I’m stuck. The existing code isn’t complicated and the only errors this should throw is location for the images and backup xml weather files because, well, I can’t upload my windows system lol. Since it populates from xml you’ll need the proper xml reference for the VBA or nothing will work.

Again, my thanks and appreciation for all assistance!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:58
Joined
Oct 29, 2018
Messages
21,358
Hi. From taking a quick look at your code, it doesn't seem like you're looping through the child nodes to grab the other weather info from the XML file.
 

essaytee

Need a good one-liner.
Local time
Tomorrow, 03:58
Joined
Oct 20, 2008
Messages
512
Just to add my little bit, all your server paths are hardcoded, so nobody is going to straight out of the box run the db and have the single day forecast work correctly as you suggest it does. This could put some off from further looking into things.

I'm not an XML person so I'm taking this opportunity to see how things are done but I'm having to set breakpoints and find where I have to change paths before even looking at addressing the issue at hand.

As I said, I'm not an XML person but is there not a way to pass a date argument using the single day code and use that to populate your six-day forecast. That is, you call it six times.
 

Mark_

Longboard on the internet
Local time
Today, 09:58
Joined
Sep 12, 2017
Messages
2,111
I've not had to work with XML before, but from the references I've found you would be using .SelectNodes to return all that match to <dayf> rather than your single which is using .SelectSingleNode grabbing from <cc>.


.SelectNodes will return all segments, so you will then need to work through each element to do what you are looking for. As I don't see what you had previously tried I can't really give better advice than that at this time.
 

gwynn76

Registered User.
Local time
Today, 11:58
Joined
Mar 15, 2019
Messages
16
Figured it out. Using selectSingleNode on dayf you cannot loop because there are spaces in the naming convention of the XML. Can't loop it using selectNode either. If you want to populate all "days" under dayf you have to specify precisely what day you want bypassing the spaces (WeatherDay.selectSingleNode("day[@d='2']/part[@p='d']/). In this case, since I wanted the days and the day/night parts, I had to break down each day under dayf and each specified part under that day. Took a lot of banging my head against the wall but I can now populate 1 day, 5 day, and 10 day forecasts. Since it's all hard coded I'm guessing it won't help anyone to see an example in case they might be interested in doing something similar. But I am attaching images to show the possibilities :)
 

Attachments

  • MWSnap012.jpg
    MWSnap012.jpg
    99.6 KB · Views: 141
  • MWSnap013.jpg
    MWSnap013.jpg
    108.5 KB · Views: 137

theDBguy

I’m here to help
Staff member
Local time
Today, 09:58
Joined
Oct 29, 2018
Messages
21,358
Figured it out. Using selectSingleNode on dayf you cannot loop because there are spaces in the naming convention of the XML. Can't loop it using selectNode either. If you want to populate all "days" under dayf you have to specify precisely what day you want bypassing the spaces (WeatherDay.selectSingleNode("day[@d='2']/part[@p='d']/). In this case, since I wanted the days and the day/night parts, I had to break down each day under dayf and each specified part under that day. Took a lot of banging my head against the wall but I can now populate 1 day, 5 day, and 10 day forecasts. Since it's all hard coded I'm guessing it won't help anyone to see an example in case they might be interested in doing something similar. But I am attaching images to show the possibilities :)
Hi. Congratulations! Glad to hear you got it sorted out. Good luck with your project.
 

Gasman

Enthusiastic Amateur
Local time
Today, 16:58
Joined
Sep 21, 2011
Messages
14,044
Since it's all hard coded I'm guessing it won't help anyone to see an example in case they might be interested in doing something similar. But I am attaching images to show the possibilities :)

It wouldn't hurt to upload it anyway? You would need to upload it zipped due to your number of posts, but you never know, someone might want to see if it could be changed to using parameter?

I've not touched XML either, but would like to see the finished version.?

TIA
 

gwynn76

Registered User.
Local time
Today, 11:58
Joined
Mar 15, 2019
Messages
16
Sure. Can do so tomorrow. Will zip all together and add directions for where the code will need to be changed so it works. If you want to show all images for each area (day/part like the 6 day) you will need multiple image paths (will also break that out). Was part of what I ran into. For some reason if you needed a duplicate of the same image in the form for a different day, it wouldn’t pull it twice from the same folder location (Example: partly sunny icon for day 1 and day 3 image 34 - would say can’t find the image and break all the other icons). Very annoying. But they’re small and take up only a little space so multiples was fine. You could also parse the xml into tables but I felt that was unnecessary bloat and it pulls the data quick enough from the live xml feed. Same with the icon images I suppose but, again, unnecessary DB bloat. Simple request: if anyone finds a better way or other workarounds or additions, please let me know. Always interested in doing something better :)
 

gwynn76

Registered User.
Local time
Today, 11:58
Joined
Mar 15, 2019
Messages
16
Well, all ready to go but keep getting a security token error when I try to upload the zip file. Sent a message to the admin. Sorry :-( hopefully will be ironed out soon!
 

gwynn76

Registered User.
Local time
Today, 11:58
Joined
Mar 15, 2019
Messages
16
OK - I have attached images separate from the weather database sample. The zipped file with all exceeds the 2mb limit. You'll need to unzip the "Day" and then create a folder called "weather_icons" in the location you want the coding to point to. In "weather_icons" folder, you'll need to create folders day1 to day10 and copy/paste the "Day" icons to each. Keep the "Day" folder as it is as you'll need it. Unzip the "moon_icons" folder to the same location as the "Day" and "weather_icons" folders. Unzip the XML files to the same folder location as the other image folders. Unzip the database file to that location as well and change the hard coded image and XML locations in the VBA for each form (Instructions form in DB). Sorry to piecemeal but was the only way I could upload the needed files. If anyone figures out how to pull all images from 1 location without breaking the other images please let me know. Was the only way I could get them all to populate.
 

Attachments

  • day.zip
    1.2 MB · Views: 159
  • moon_icons.zip
    238.3 KB · Views: 116
  • XML.zip
    2.8 KB · Views: 104
  • DatabaseExe.zip
    1.8 MB · Views: 150

Gasman

Enthusiastic Amateur
Local time
Today, 16:58
Joined
Sep 21, 2011
Messages
14,044
Thanks for this.
I have a question though.? How does one find out their location code.? I've tried removing each part of the url in turn, but do not get to a place where I can get my location.?

FWIW it is SA4 4HG in the UK.?

TIA

Also get function not found
Code:
Private Sub Form_Open(Cancel As Integer)
[COLOR="Red"]chf_OnOpen[/COLOR] Me
Call FetchWeather("USTX1643")
End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 16:58
Joined
Sep 21, 2011
Messages
14,044
Got it working on your zip code and a friends at 71047 after commenting out that line in each form.
Impressive I must say.

Due to all the changes I decided to amend a few lines.?

Code:
Private Const gstrLocation As String = "USTX1643"
Private Const URL_WEATHER As String = "http://wxdata.weather.com/wxdata/weather/local/" & gstrLocation & "?unit=f&dayf=10&cc"
Private Const XML_NOERROR As Integer = 0
Private Const gstrBasePath As String = "C:\Temp\Weather\"

    '// assign icon resource path
    '// we use the current project path and the provided folder
    strLocalImagePath = gstrBasePath & "weather_icons\"
    strDayImagePath = gstrBasePath & "day\"
    strLocalXMLPath = gstrBasePath & "Weather2.xml"
    strMoonImagePath = gstrBasePath & "moon_icons\"
    strDay1ImagePath = gstrBasePath & "weather_icons\Day1\"
    strDay2ImagePath = gstrBasePath & "weather_icons\Day2\"
    strDay3ImagePath = gstrBasePath & "weather_icons\Day3\"
    strDay4ImagePath = gstrBasePath & "weather_icons\Day4\"
    strDay5ImagePath = gstrBasePath & "weather_icons\Day5\"
    strDay6ImagePath = gstrBasePath & "weather_icons\Day6\"
    strDay7ImagePath = gstrBasePath & "weather_icons\Day7\"
    strDay8ImagePath = gstrBasePath & "weather_icons\Day8\"
    strDay9ImagePath = gstrBasePath & "weather_icons\Day9\"
    strDay10ImagePath = gstrBasePath & "weather_icons\Day10\"
just to make it easier to follow your instructions.

Thanks very much for this.:cool:

Edit: Not getting any of the weather icons though?
Could you please post a pic of one of your forms with those showing?
 
Last edited:

gwynn76

Registered User.
Local time
Today, 11:58
Joined
Mar 15, 2019
Messages
16
Just use Google and search for weather location codes and choose your location. Your zip code can work as well just make sure you change the location code in all areas where it pulls the weather xml data for location.

Attached images of current weather showing working images. Make sure you change the image locations.

chf_OnOpen is not needed. You can remove it. That is for user form color changes. The coding for that was not included. Sorry!
 

Attachments

  • MWSnap001.jpg
    MWSnap001.jpg
    101.4 KB · Views: 92
  • MWSnap002.jpg
    MWSnap002.jpg
    96.4 KB · Views: 84
  • MWSnap003.jpg
    MWSnap003.jpg
    91 KB · Views: 79
  • MWSnap004.jpg
    MWSnap004.jpg
    31.2 KB · Views: 85

Gasman

Enthusiastic Amateur
Local time
Today, 16:58
Joined
Sep 21, 2011
Messages
14,044
Hi gwynn76,
I've got the images working now.

Not sure why you think you need all those day folders.?

I have the weather icons in the weathericons folder

Code:
    '// we use the current project path and the provided folder
    strLocalImagePath = cstrBasePath & "weather_icons\"
    strDayImagePath = cstrBasePath & "day\"
    strLocalXMLPath = cstrBasePath & "Weather2.xml"
    strMoonImagePath = cstrBasePath & "moon_icons\"
    strDay1ImagePath = strLocalImagePath
    strDay2ImagePath = strDay1ImagePath
    strDay3ImagePath = strDay1ImagePath
    strDay4ImagePath = strDay1ImagePath
    strDay5ImagePath = strDay1ImagePath
    strDay6ImagePath = strDay1ImagePath
    strDay7ImagePath = strDay1ImagePath
    strDay8ImagePath = strDay1ImagePath
    strDay9ImagePath = strDay1ImagePath
    strDay10ImagePath = strDay1ImagePath

and that appears to work just as it did when I placed all the icons into the folder.

The other zip code works fine just changing it on the form. If I try my postcode I get a With Block error.

Excellent program :D I should be able to learn a fair bit from this. Thank you.
 

gwynn76

Registered User.
Local time
Today, 11:58
Joined
Mar 15, 2019
Messages
16
Another image with changes location so you can see that the images are changing.
 

Attachments

  • MWSnap005.jpg
    MWSnap005.jpg
    97.2 KB · Views: 80

gwynn76

Registered User.
Local time
Today, 11:58
Joined
Mar 15, 2019
Messages
16
I can try it again. But every time I tried to pull all images for 5 day or 10 day from the same local image path, it would break all of the images. That was one of those beat my head against the wall moments as theoretically, it should have worked just fine.
 

Gasman

Enthusiastic Amateur
Local time
Today, 16:58
Joined
Sep 21, 2011
Messages
14,044
I *think* I might have discovered at least one reason why the pics do not show.
For my post code I get nothing in the <icon></icon> for day 0.
If that does not return a filename then the image sources are not set?

Code:
            '// the image path(s) ---- Day 0
            
            strLocalImagePath = strLocalImagePath & WeatherConditions.selectSingleNode("icon").Text & ".png"
.
.
.
.
            '// test if icon exist and display the appropriate image
            If Not Dir(strLocalImagePath, vbNormal) = "" Then

HTH
 

gwynn76

Registered User.
Local time
Today, 11:58
Joined
Mar 15, 2019
Messages
16
For day 0 (Current on 5 day and 10 day) the weather changes throughout the day. So instead of using an icon "path" in the direct XML, it pulls from: .imgWeatherIcon.ControlTipText = "Updated " & WeatherConditions.selectSingleNode("lsup").Text - LSUP under day 0. If the icon path is not set correctly (strLocalImagePath = strLocalImagePath & WeatherConditions.selectSingleNode("icon").Text & ".png") at the beginning, it is not able to find the image path later in the code.
'// assign icon resource path
'// we use the current project path and the provided folder
strLocalImagePath = "\\BIDMAGIC-SERVER\Microsoft SQL Server\Tracker DB BE\Front End\weather_icons"

So, short, no. Double check your image paths and make sure you have the correct permissions for the folders. Obviously, my path is different than yours :p
 

Attachments

  • MWSnap015.jpg
    MWSnap015.jpg
    18.5 KB · Views: 82

Users who are viewing this thread

Top Bottom