'Scriptversion:1

'============================
'  LOCATION SEARCH FUNCTIONS
'============================
Function LocationSearch(strg)
	setStatus("search")			
	searchURL = "http://api.wunderground.com/auto/wui/geo/GeoLookupXML/index.xml?query=" & strg
	searchResults = System.SendRequest(searchURL, "POST", True)	
End Function

Function ListMatches(info)
	locCount = countStr(info,"</location>")
	locCount = locCount - 1
	locdata = info
	locCurrent = -1
	ReDim loList(locCount)
	For x = 0 To locCount		' Loop for each match	
		locName = xmlstripper("<name>", locdata)
		If locName <> "N/A" And locName <> ""  And Instr(locName,",") Then
			locCurrent = locCurrent + 1
			loList(locCurrent) = locName
		End If			
		locdata = Right(locdata, Len(locdata) - InStr(locdata, "</location>"))
	Next	
	Call DisplayMatches(loList)
End Function

Function ListStations(info)
	Call CacheStations(info)
	t = -1	
	locdata = xmlstripper("<pws>", info)
	locCount = countStr(info,"</station>") : locCount = locCount - 1
	cTagEnd = "]" & "]" & ">"
	cTagStart = "<" & "!" & "[" & "CDATA" & "["	
	ReDim locList(-1)
	ReDim locID(-1)
	ReDim locDistKM(-1)
	ReDim locDistMI(-1)	
	For x = 0 To locCount		' Loop for each match	
		'neighborhood
		locName = xmlstripper("<neighborhood>", locdata)
		locName = Replace(locName, cTagStart, "")
		locName = Replace(locName, cTagEnd, "")
		If Instr(locName, "   ") Then
			lNparts = split(locName,"   ")
			locName = lNparts(0)
		End If
		locName = Trim(locName)
		If locName <> "N/A" And locName <> "" And strCheck(locName) = "t" Then
			ReDim Preserve locList(UBound(locList)+1)
			ReDim Preserve locID(UBound(locID)+1)
			ReDim Preserve locDistKM(UBound(locDistKM)+1)
			ReDim Preserve locDistMI(UBound(locDistMI)+1)	
			locList(UBound(locList)) = locName			
		End If	
		'station id
		locIDs = xmlstripper("<id>", locdata)
		locIDs = Replace(locIDs, cTagStart, "")
		locIDs = Replace(locIDs, cTagEnd, "")
		locIDs = Trim(locIDs)
		If locIDs <> "N/A" And locIDs <> "" And strCheck(locName) = "t" Then	locID(UBound(locID)) = locIDs
		'distance kilometer
		locKM = xmlstripper("<distance_km>", locdata)
		locKM = Replace(locKM, cTagStart, "")
		locKM = Replace(locKM, cTagEnd, "")
		locKM = Trim(locKM)
		If locKM <> "N/A" And locKM <> "" And strCheck(locName) = "t" Then	locDistKM(UBound(locDistKM)) = locKM
		'distance miles
		locMI = xmlstripper("<distance_mi>", locdata)
		locMI = Replace(locMI, cTagStart, "")
		locMI = Replace(locMI, cTagEnd, "")
		locMI = Trim(locMI)
		If locMI <> "N/A" And locMI <> "" And strCheck(locName) = "t" Then	locDistMI(UBound(locDistMI)) = locMI		
		locdata = Right(locdata, Len(locdata) - InStr(locdata, "</station>"))
	Next
	Call OutputStations
End Function

Function ListAirports(info)
	portdata = xmlstripper("<airport>", info)
	portcount = countStr(portdata, "</station>") : portcount = portcount - 1
	ReDim PortCodes(portcount)
	ReDim PortCity(portcount)
	ReDim PortStates(portcount)
	ReDim PortCountry(portcount)
	For x = 0 To portcount
		PortCodes(x) = xmlstripper("<icao>",portdata)
		PortCity(x) = xmlstripper("<city>",portdata)
		PortStates(x) = xmlstripper("<state>",portdata)
		PortCountry(x) = xmlstripper("<country>",portdata)
		portdata = Right(portdata, Len(portdata) - InStr(portdata, "</station>"))
	Next
	Call OutputAirports
End Function

Function ListWebcams(info)
	cTagEnd = "]" & "]" & ">"
	cTagStart = "<" & "!" & "[" & "CDATA" & "["	
	wcdata = xmlstripper("<webcams>",info)
	camcount = countStr(wcdata, "</cam>") : camcount = camcount - 1
	ReDim CamNeighborhood(camcount)
	ReDim CamAddress(camcount)
	ReDim CamZip(camcount)
	ReDim CamCity(camcount)
	ReDim CamState(camcount)
	ReDim CamCountry(camcount)
	ReDim CamUpdated(camcount)
	ReDim CamImage(camcount)
	ReDim CamURL(camcount)
	For x = 0 To camcount
		CamNeighborhood(x) = xmlstripper("<neighborhood>",wcdata)
		CamAddress(x) = xmlstripper("<address>",wcdata)
		CamZip(x) = xmlstripper("<zip>",wcdata)
		CamCity(x) = xmlstripper("<city>",wcdata)
		CamState(x) = xmlstripper("<state>",wcdata)
		CamCountry(x) = xmlstripper("<country>",wcdata)
		CamUpdated(x) = xmlstripper("<updated>",wcdata)
		CamImage(x) = xmlstripper("<CURRENTIMAGEURL>",wcdata)
		CamURL(x) = xmlstripper("<CAMURL>",wcdata)
		wcdata = Right(wcdata, Len(wcdata) - InStr(wcdata, "</cam>"))
	Next
	radardata = xmlstripper("<radar>",info)
	RadarImage = xmlstripper("<image_url>",radardata) : RadarImage = Replace(RadarImage, cTagEnd, "") : RadarImage = Replace(RadarImage, cTagStart,"")
	RadarURL = xmlstripper("<url>",radardata) : RadarURL = Replace(RadarURL, cTagEnd, "") : RadarURL = Replace(RadarURL, cTagStart, "")
	
	Call OutputWebcams
End Function

'=============================
'    GET WEATHER FUNCTIONS
'=============================

Function GetCurrent(strg)
	setStatus("current")
	searchURL = "http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=" & strg
	searchResults = System.SendRequest(searchURL, "POST", True)	
End Function

Function GetCurrentPWS(strg)
	setStatus("current")
	searchURL = "http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=" & strg
	searchResults = System.SendRequest(searchURL, "POST", True)	
End Function

Function GetForecast(strg)
	setStatus("forecast")			
	searchURL = "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=" & strg
	searchResults = System.SendRequest(searchURL, "POST", True)	
End Function

Function GetAlerts(strg)
	setStatus("alert")			
	searchURL = "http://api.wunderground.com/auto/wui/geo/AlertsXML/index.xml?query=" & strg
	searchResults = System.SendRequest(searchURL, "POST", True)	
End Function

'=============================
'   URL REQUEST FINISH
'=============================

Sub System_OnRequestFinish(url, pagecontent)
	'--Search Page Results---
	If instr(url,"GeoLookupXML") > 0 Then
		If Instr(pagecontent, "<locations>") Then
			ListMatches(pagecontent)
			setStatus("ready")
		ElseIf Instr(pagecontent,"<pws>") Then
			'Reset webcam if new location
			If checkRefreshMode = "new" Then
				saveWebcam("")
				changeMode("default")
				changeRefreshMode("refresh")
			End If
			ListAirports(pagecontent)
			ListWebcams(pagecontent)
			spURL = split(url,"=")
			'Save locations
			Object.PersistStorage("location") = spURL(1)
			Object.PersistStorage("forecast") = spURL(1)
			ListStations(pagecontent)
			'Get weather
			GetForecast(Object.PersistStorage("forecast"))
			setStatus("ready")
		ElseIf Instr(pagecontent, "<wui_error>") Then
			errMsg = xmlstripper("<title>",pagecontent)
			msgbox errMsg
			setStatus("ready")		
		Else
			setStatus("serror")
		End If
	'--Forecast Page Results---
	ElseIf instr(url, "ForecastXML") > 0 Then
		If Instr(pagecontent, "<simpleforecast>") Then
			spURL = split(url,"=")
			'Save locations
			Object.PersistStorage("forecast") = spURL(1)
			ParseForecast(pagecontent)
			setStatus("ready")
		Else
			setStatus("serror")
		End If
		'Get Current (default or pws)
		If checkMode = "default" Then
			GetCurrent(Object.PersistStorage("location"))
		ElseIf Object.Comments = "pws" Then
			GetCurrentPWS(Object.PersistStorage("pws"))
		End If
	'---Current General Results---
	ElseIf instr(url, "WXCurrentObXML/index.xml") > 0 Then
		If Instr(pagecontent, "<icon>") Then
			ParseCurrent(pagecontent)
			setStatus("ready")
		ElseIf Instr(pagecontent, "<wui_error>") Then
			errMsg = xmlstripper("<title>",pagecontent)
			msgbox errMsg
			setStatus("ready")
		Else
			setStatus("serror")
		End If
	'---Current Personal Weather Station Results---
	ElseIf instr(url, "weatherstation") > 0 Then
		If Instr(pagecontent, "<current_observation>") Then
			spURL = split(url,"=")
			Object.PersistStorage("pws") = spURL(1)
			ParseCurrentPWS(pagecontent)
			setStatus("ready")
		ElseIf Instr(pagecontent, "<wui_error>") Then
			errMsg = xmlstripper("<title>",pagecontent)
			msgbox errMsg
			setStatus("ready")
		Else
			setStatus("serror")
		End If
	'---Alert Results--
	ElseIf instr(url, "AlertsXML") > 0 Then
		If Instr(pagecontent,"<alerts>") Then
			ParseAlerts(pagecontent)
			setStatus("ready")
		End If
	End If
End Sub

'==========================
' PARSE WEATHER FUNCTIONS 
'==========================

Function ClearCurrentVars
	Clear dispLoc
	Clear dispFull
	Clear dispCity 
	Clear dispState 
	Clear dispSName 
	Clear dispCountry 
	Clear dispZip 
	Clear dispLat 
	Clear dispLong 
	Clear dispElv 
	Clear obsLoc 
	Clear obsFull 
	Clear obsCity 
	Clear obsState 
	Clear obsCountry 
	Clear obsLat 
	Clear obsLong 
	Clear obsElv 
	Clear statID 
	Clear obsTimeGMT 
	Clear localTime 
	Clear curWeather 
	Clear curTempF 
	Clear curTempC 
	Clear curHumidity 
	Clear curPressureMB 
	Clear curPressureIN 
	Clear curDewpointF 
	Clear curDewpointC 
	Clear curHeatindexF 
	Clear curHeatindexC 
	Clear curWindchillF 
	Clear curWindchillC 
	Clear curVisibleMI 
	Clear curVisibleKM 
	Clear curIconbase 
	Clear curIconExtension 
	Clear curIcon 
	Clear curForecastURL 
	Clear curHistoryURL 
	Clear curObservationURL 
	Clear credText 
	Clear credURL 
	Clear credLogo 
	Clear curWind 
	Clear curWindDir 
	Clear curWindDeg 
	Clear curWindMPH 
	Clear curWindGust 
	Clear dispNhood 
	Clear curSolarRadiation 
	Clear curUV 
	Clear curPrecipIN 
	Clear curPrecipMetric 
	Clear curPrecipTodayIN 
	Clear curPrecipTodayMetric 	
End Function

Function ParseCurrent(info)
	Call CacheCCWeather(info)
	'Display Location
	dispLoc = xmlstripper("<display_location>", info)
	dispFull = xmlstripper("<full>", dispLoc)
	dispCity = xmlstripper("<city>", dispLoc)
	dispState = xmlstripper("<state>", dispLoc)
	dispSName = xmlstripper("<state_name>", dispLoc)
	dispCountry = xmlstripper("<country>", dispLoc)
	dispZip = xmlstripper("<zip>", dispLoc)
	dispLat = xmlstripper("<latitude>", dispLoc)
	dispLong = xmlstripper("<longitude>", dispLoc)
	dispElv = xmlstripper("<elevation>", dispLoc)
	'Observation Location
	obsLoc = xmlstripper("<observation_location>", info)
	obsFull = xmlstripper("<full>", obsLoc)
	obsCity = xmlstripper("<city>", obsLoc)
	obsState = xmlstripper("<state>", obsLoc)
	obsCountry = xmlstripper("<country>", obsLoc)
	obsLat = xmlstripper("<latitude>", obsLoc)
	obsLong = xmlstripper("<longitude>", obsLoc)
	obsElv = xmlstripper("<elevation>", obsLoc)
	'Conditions
	statID = xmlstripper("<station_id>", info) 'station/airport id
	obsTimeGMT = xmlstripper("<observation_time_rfc822>", info) 'observation time
	localTime = xmlstripper("<local_time>", info) 'local time
	curWeather = xmlstripper("<weather>", info) 'current conditions
	curTempF = xmlstripper("<temp_f>", info) 'farenheit
	curTempC = xmlstripper("<temp_c>", info) 'celsius
	curHumidity = xmlstripper("<relative_humidity>", info) 'humidity
	curWind = xmlstripper("<wind_string>", info) 'wind strength
	curWindDir = xmlstripper("<wind_dir>", info) 'wind direction
	curWindDeg = xmlstripper("<wind_degrees>", info) 'degrees
	curWindMPH = xmlstripper("<wind_mph>", info) 'speed mph
	curWindGust = xmlstripper("<wind_gust_mph>", info) 'gust speed
	curPressureMB = xmlstripper("<pressure_mb>", info) 'pressure mb
	curPressureIN = xmlstripper("<pressure_in>", info) 'pressure in
	curDewpointF = xmlstripper("<dewpoint_f>", info) 'farenheit
	curDewpointC = xmlstripper("<dewpoint_c>", info) 'celsius
	curHeatindexF = xmlstripper("<heat_index_f>", info) 'farenheit
	curHeatindexC = xmlstripper("<heat_index_c>", info) 'celsius
	curWindchillF = xmlstripper("<windchill_f>", info) 'farenheit
	curWindchillC = xmlstripper("<windchill_c>", info) 'celsius
	curVisibleMI = xmlstripper("<visibility_mi>", info) 'visibility mi
	curVisibleKM = xmlstripper("<visibility_km>", info) 'visibility km
	'Icon
	curIconbase = xmlstripper("<icon_url_base>", info) 'icon url base
	curIconExtension = xmlstripper("<icon_url_name>", info) 'icon extension
	curIcon = xmlstripper("<icon>", info) 'icon name
	'URLs
	curForecastURL = xmlstripper("<forecast_url>", info)
	curHistoryURL = xmlstripper("<history_url>", info)
	curObservationURL = xmlstripper("<ob_url>", info)
	'Credit
	credText = xmlstripper("<credit>", info)
	credURL = xmlstripper("<credit_URL>", info)
	credLogo = xmlstripper("<url>", info)
	'Save Data
	Object.PersistStorage("pws") = ""
	Object.PersistStorage("location") = dispFull
	'Output Data
	Call OutputCurrent("default")
	'Get Alerts
	Call GetAlerts(dispFull)
End Function


Function ParseCurrentPWS(info)
	Call CacheCCWeather(info)
	'Display Location
	dispLoc = xmlstripper("<location>", info)
	dispFull = xmlstripper("<full>", dispLoc)
	dispNhood = xmlstripper("<neighborhood>", dispLoc)
	dispCity = xmlstripper("<city>", dispLoc)
	dispState = xmlstripper("<state>", dispLoc)
	dispCountry = xmlstripper("<country>", dispLoc)
	dispZip = xmlstripper("<zip>", dispLoc)
	dispLat = xmlstripper("<latitude>", dispLoc)
	dispLong = xmlstripper("<longitude>", dispLoc)
	dispElv = xmlstripper("<elevation>", dispLoc)
	'Conditions
	statID = xmlstripper("<station_id>", info) 'station/airport id
	obsTimeGMT = xmlstripper("<observation_time_rfc822>", info) 'observation time
	localTime = xmlstripper("<local_time>", info) 'local time
	curWeather = xmlstripper("<weather>", info) 'current conditions
	curTempF = xmlstripper("<temp_f>", info) 'farenheit
	curTempC = xmlstripper("<temp_c>", info) 'celsius
	curHumidity = xmlstripper("<relative_humidity>", info) 'humidity
	curWind = xmlstripper("<wind_string>", info) 'wind strength
	curWindDir = xmlstripper("<wind_dir>", info) 'wind direction
	curWindDeg = xmlstripper("<wind_degrees>", info) 'degrees
	curWindMPH = xmlstripper("<wind_mph>", info) 'speed mph
	curWindGust = xmlstripper("<wind_gust_mph>", info) 'gust speed
	curPressureMB = xmlstripper("<pressure_mb>", info) 'pressure mb
	curPressureIN = xmlstripper("<pressure_in>", info) 'pressure in
	curDewpointF = xmlstripper("<dewpoint_f>", info) 'farenheit
	curDewpointC = xmlstripper("<dewpoint_c>", info) 'celsius
	curHeatindexF = xmlstripper("<heat_index_f>", info) 'farenheit
	curHeatindexC = xmlstripper("<heat_index_c>", info) 'celsius
	curWindchillF = xmlstripper("<windchill_f>", info) 'farenheit
	curWindchillC = xmlstripper("<windchill_c>", info) 'celsius
	curVisibleMI = xmlstripper("<visibility_mi>", info) 'visibility mi
	curVisibleKM = xmlstripper("<visibility_km>", info) 'visibility km
	curSolarRadiation = xmlstripper("<solar_radiation>", info)
	curUV = xmlstripper("<UV>", info)
	curPrecipIN = xmlstripper("<precip_1hr_in>", info)
	curPrecipMetric = xmlstripper("<precip_1hr_metric>", info)
	curPrecipTodayIN = xmlstripper("<precip_today_in>", info)
	curPrecipTodayMetric = xmlstripper("<precip_today_metric>", info)
	'URLs
	curHistoryURL = xmlstripper("<history_url>", info)
	curObservationURL = xmlstripper("<ob_url>", info)
	'Credit
	credText = xmlstripper("<credit>", info)
	credURL = xmlstripper("<credit_URL>", info)
	credLogo = xmlstripper("<url>", info)	
	'Output Data
	Call OutputCurrent("pws")
	'Get Alerts
	Call GetAlerts(Object.PersistStorage("forecast"))
End Function

Function ParseForecast(info)
	Call CacheWeather(info)
	' Day part forecast
	forecastdata = xmlstripper("<txt_forecast>", info)
	For x = 0 To 1
		DaypartIcon(x) = xmlstripper("<icon>", forecastdata)
		DaypartTitle(x) = xmlstripper("<title>", forecastdata)
		DaypartWeather(x) = xmlstripper("<fcttext>", forecastdata)
		forecastdata = Right(forecastdata, Len(forecastdata) - InStr(forecastdata, "</forecastday>"))
	Next
	' 6-Day Forecast
	forecastdata = xmlstripper("<simpleforecast>", info)
	For x = 0 To 5		' Loop for each day	
		'Date	
		ForecastDate(x) = xmlstripper("<day>", forecastdata)
		ForecastMonth(x) = xmlstripper("<monthname>", forecastdata)
		ForecastWeekday(x) = xmlstripper("<weekday>", forecastdata)
		'High temps
		hightemp = xmlstripper("<high>", forecastdata)
		ForecastHighF(x) = xmlstripper("<fahrenheit>", hightemp) &Chr(176)
		ForecastHighC(x) = xmlstripper("<celsius>", hightemp) &Chr(176)
		'Low temps
		lowtemp = xmlstripper("<low>", forecastdata)
		ForecastLowF(x) = xmlstripper("<fahrenheit>", lowtemp) &Chr(176)
		ForecastLowC(x) = xmlstripper("<celsius>", lowtemp) &Chr(176)
		'Conditions
		ForecastConditions(x) = xmlstripper("<conditions>", forecastdata)
		ForecastIcon(x) = xmlstripper("<icon>", forecastdata)
		ForecastSkyIcon(x) = xmlstripper("<skyicon>", forecastdata)
		
		forecastdata = Right(forecastdata, Len(forecastdata) - InStr(forecastdata, "</forecastday>"))
	Next
	'Sun and Moon data
	moondata = xmlstripper("<moon_phase>", info)
	ForecastMoonIlluminated = xmlstripper("<percentIlluminated>", moondata)
	ForecastMoonAge = xmlstripper("<ageOfMoon>", moondata)
	sunset = xmlstripper("<sunset>", moondata)
	ForecastSunset = xmlstripper("<hour>", sunset) & ":" & xmlstripper("<minute>", sunset)
	sunrise = xmlstripper("<sunrise>", moondata)
	ForecastSunrise = xmlstripper("<hour>", sunrise) & ":" & xmlstripper("<minute>", sunrise)
	fcurrenttime = xmlstripper("<current_time>", moondata)
	ForecastCurrentTime = xmlstripper("<hour>", fcurrenttime) & ":" & xmlstripper("<minute>", fcurrenttime)
	'Output Data
	Call OutputForecast
End Function

Function ParseAlerts(info)
	Call CacheAlerts(info)
	forecastdata = xmlstripper("<alerts>", info)
	alertcount = countStr(forecastdata, "</AlertItem>") - 1
	ReDim AlertDescription(alertcount)
	ReDim AlertMessage(alertcount)
	For x = 0 To alertcount
		AlertDescription(x) = xmlstripper("<description>", forecastdata)
		AlertMessage(x) = xmlstripper("<message>", forecastdata)
		forecastdata = Right(forecastdata, Len(forecastdata) - InStr(forecastdata, "</AlertItem>"))
	Next
	Call OutputAlerts
End Function

'==========================
'     CACHE WEATHER
'==========================

'Write 5-day cache
Function CacheWeather(info)
	Call writeFile(info,cacheFile)
End Function

'Write current conditions cache
Function CacheCCWeather(info)
	Call writeFile(info,cacheCCFile)
End Function

'Write stations cache
Function CacheStations(info)
	Call writeFile(info,cacheSFile)
End Function

'Write alerts cache
Function CacheAlerts(info)
	Call writeFile(info,cacheAFile)
End Function

'Read 5-day cache
Function GetCacheWeather
	Set fso = CreateObject("Scripting.FileSystemObject")
	If fso.fileexists(cacheFile) Then
		t = readFile(cacheFile)
		Call ParseForecast(t)
	End If
End Function

'Read current conditions cache
Function GetCacheCCWeather
	Set fso = CreateObject("Scripting.FileSystemObject")
	If fso.fileexists(cacheCCFile) Then
		t = readFile(cacheCCFile)
		If Instr(t,"display_location") Then Call ParseCurrent(t) Else Call ParseCurrentPWS(t)
	End If
End Function

'Read stations cache
Function GetCacheStations
	Set fso = CreateObject("Scripting.FileSystemObject")
	If fso.fileexists(cacheSFile) Then
		t = readFile(cacheSFile)
		Call ListStations(t)
		Call ListAirports(t)
		Call ListWebcams(t)
	End If
End Function

'Read alerts cache
Function GetCacheAlerts
	Set fso = CreateObject("Scripting.FileSystemObject")
	If fso.fileexists(cacheAFile) Then
		t = readFile(cacheAFile)
		Call ParseAlerts(t)
	End If
End Function

'=================================================
'            MULTI-USE FUNCTIONS
'=================================================

'------Basic function to strip XML tags--------
Function xmlstripper(param, string)
	If Instr(string, param) Then
		datastart = InStr(string, param) + Len(param)
		datalength = Instr(string, "</" & Right(param, Len(param) - 1)) - datastart
		dataresult = Mid(string, datastart, datalength)
		If dataresult = "" Or dataresult = "NA" Or strCheck(dataresult) = "f" Then xmlstripper = "N/A" Else xmlstripper = dataresult
	Else
		xmlstripper = "N/A"
	End If
End Function

'----Basic function to count instances of a string---
Function countStr(info,strg)
	spaceStr = 1
	wCount = 0		
	While iend < len(info)
			x = Instr(spaceStr, info , strg)
			If x > 0 Then 
				wCount = wCount + 1
				spaceStr = x+1
				y = x
			Else
				y = len(info)
			End If
			iend = y
	Wend
	countStr = wCount
End Function

'--- Read a file----
Function readFile(textfile)
	Set fso = CreateObject("Scripting.FileSystemObject")
	'Check if file exists
	If fso.FileExists(textfile) Then
		Set f = fso.OpenTextFile(textfile, 1)
		fileinfo = f.readall
		f.Close
	End If
	readFile = fileinfo
	Set fso = nothing
End Function

'--- Write to file----
Function writeFile(info, textfile)
	Set fso = CreateObject("Scripting.FileSystemObject")
	Set f = fso.OpenTextFile(textfile, 2, True)
	f.Write info
	f.Close
	Set fso = nothing
End Function