依照前辈的经验来优化的,http://www.ad.siemens.com.cn/club/bbs/post.aspx?a_id=1322113&b_id=5;
依据查询的城市给天气接口地址分配相应的城市;
以下是城市查询的全局脚本(只写一点点):
查询数据严格依据http://flash.weather.com.cn/wmaps/xml/"&city&".xml"来查询
http://flash.weather.com.cn/wmaps/xml/"&provincename.value&".xml"'天气预来报接口地址
Option Explicit
Function action
Dim city,Province
Set Province = HMIRuntime.Tags("A.Province")
Province.Read
Set city = HMIRuntime.Tags("A.city")
city.Read
If city.value ="嘉定" Or city.value ="宝山" Or city.value ="市中心" Or city.value ="青浦" Or city.value ="松江" Or city.value ="闵行" Or city.value ="浦东新区" Or city.value ="金山" Or city.value ="奉贤" Or city.value ="崇明" Then
Province.Write "shanghai"
Else If city.value ="延庆" Or city.value ="密云" Or city.value ="怀柔" Or city.value ="昌平" Or city.value ="平谷" Or city.value ="顺义" Or city.value ="门头沟" Or city.value ="海定" Or city.value ="朝阳" Or city.value ="石景山"Or city.value ="丰台"Or city.value ="房山"Or city.value ="大兴"Or city.value ="通州" Then
Province.Write "beijing"
Else If city.value ="深圳市" Then
Province.Write "shenzhen"
Else
Province.Write ""
End If
End If
End If
winc 画面;(输入城市名,再点击查询即可)

按钮查询VB脚本
Dim xDoc,xDocRoot,xNode
Dim pFile,i,strW
Dim provincename,pi,city
Set provincename = HMIRuntime.Tags("A.Province")
provincename.Read
Set city= HMIRuntime.Tags("A.city")
city.Read
pFile="http://flash.weather.com.cn/wmaps/xml/"&provincename.value&".xml"'天气预报接口地址
Set xDoc=CreateObject("Microsoft.XMLDOM")
xDoc.async=False
xDoc.load pFile
If xDoc.parseError.errorCode = 0 Then
Set xDocRoot =xDoc.documentElement
i = 0
Do While i<xDocRoot.childNodes.length
Set xNode = xDocRoot.childNodes.item(i)
If xNode.getAttribute("cityname")=city.value Then
strW ="预报城市: " & xNode.getAttribute("cityname") & vbCrlf & _
"天气情况: " & xNode.getAttribute("stateDetailed") & vbCrlf & _
"当前温度: " & xNode.getAttribute("temNow") & vbCrlf & _
"最高温度: " & xNode.getAttribute("tem1") & vbCrlf & _
"最低温度: " & xNode.getAttribute("tem2") & vbCrlf & _
"北纬:" & xNode.getAttribute("cityX") & vbCrlf & _
"东经:" & xNode.getAttribute("cityY") & vbCrlf & _
"风力:" & xNode.getAttribute("windDir") &" "& xNode.getAttribute("windPower") & _
vbCrlf & "风力描述:" & xNode.getAttribute("windState") & vbCrlf & _
vbCrlf & "湿度: " & xNode.getAttribute("humidity") & vbCrlf & _
vbCrlf & "预报时间: " & xNode.getAttribute("time")
Exit Do
Else
i = i + 1
End If
Loop
Else
Msgbox"xml文件加载失败!"
Msgbox"错误:"& char(13)& xDoc.parseError.reason
End If
Msgbox strW
Set xNode=Nothing
Set xDocRoot=Nothing
Set xDoc=Nothing
