webForumDet fria alternativet

Inkompatibla typer i vbs..

ASP

3 svar · 204 visningar · startad av trexter.com

Medlem sedan apr. 20021 203 inlägg
Frågan#1

Jag har en bit kod (jag har inte själv skrivit den) som ska plocka ner symbolen för vilket slags väder det är för tillfället. Den är en del av en bit kod och ser ut så här:

Function Symbol
dim icons
icons =

array("","B","B","D","D","A","B","A","B","B","B","B","B","A","A","A","A","D","B","","","","","","","","S","","R","","R","","Q","","R","D","I","

E","E","","A","A","A","R")

icon = GetHTMLValue("http://image.weather.com/web/common/wxicons/52/",".gif", "")

Symbol = icons(icon)

End Function

Vad är det som gör att jag får "inkompatibla typer". Istället för att symbolen visas på datorns skrivbord (det är det som är meningen) genom programmet Samrize (proggat i delphi) så visas bara ett tecken, t.ex: R

How come?

Medlem sedan dec. 200012 464 inlägg
#2

På vilken rad får du felmeddelandet?

vad är GetHTMLValue?

Medlem sedan apr. 20021 203 inlägg
#3

Iom att det inte är mitt script så vet jag inte riktigt men här är det iaf i sin helhet:

' ExtendedWeather, (C) By Ronnie 2002
' This script is a modification of various other weather scripts,
' as usual I took it to new heights!
' I dont know if the weather symbol font is copyrighted or not!!! use with care!

City    = "malmo, sweden" ' Set this to your city, dont forget the format "city, country".
Celcius = true ' If you want the degrees in celcius or farenheit.
MPH     = false ' If you want the wind speed in miles or kilometer per hour.

Function Location
	Location = GetHTMLValue("Forecast for ","</B>", "")
End Function

Function Symbol
dim icons
icons = array("","B","B","D","D","A","B","A","B","B","B","B","B","A","A","A","A","D","B","","","","","","","","S","","R","","R","","Q","","R","D","I","E","E","","A","A","A","R")

	icon = GetHTMLValue("http://image.weather.com/web/common/wxicons/52/",".gif", "")
	
	Symbol = icons(icon)
End Function

Function Temperature
	Temperature = GetHTMLValue("<!-- insert current tempature --> <B>","&deg;F</B>", "")
	if celcius then Temperature = round((5/9)*(temperature -32))
	if celcius then Temperature = Temperature & "°C" else Temperature = Temperature & "°F"
End Function

Function FeelsLikeTemp
	FeelsLikeTemp = GetHTMLValue("<!-- insert feels like temp -->","&deg;F</B>", "")

	If FeelsLikeTemp <> "N/A" Then
	 If celcius then FeelsLikeTemp = round((5/9)*(FeelsLikeTemp -32))
	 If celcius then FeelsLikeTemp = FeelsLikeTemp & "°C" else FeelsLikeTemp = FeelsLikeTemp & "°F"
	End If
End Function

Function Condition
	Condition = GetHTMLValue("<!-- insert forecast -->","</B></TD>", "")
End Function

Function Wind
	Wind = GetHTMLValue("<!-- insert wind --> ","</TD>", "")
	if mph = false then
		  spos = instrrev(Wind, "at ")+3
		  chrs = instrrev(Wind, " ") - spos
		 speed = Mid(wind, spos, chrs)
		nspeed = round(speed * 1.609344)
		  Wind = replace(wind, speed, nspeed)
		  Wind = replace(wind, "mph", "km/h")
	end if
End Function

Function Humidity
	Humidity = GetHTMLValue("<!-- insert humidity -->","</TD>", "")
End Function

Function Visibility
	Visibility = GetHTMLValue("<!-- insert visibility -->","</TD>", "")
End Function

Function Barometer
	Barometer = GetHTMLValue("<!-- insert pressure -->","</TD>", "")
End Function

Function DewPoint
	DewPoint = GetHTMLValue("<!-- insert dew point -->", "&deg;F</TD>", "")

	If celcius then DewPoint = round((5/9)*(DewPoint -32))
	If celcius then DewPoint = DewPoint & "°C" else DewPoint = DewPoint & "°F"
End Function

Function UV
	UV = GetHTMLValue("<!-- insert UV index -->", "</TD>", "")
End Function

Function writefile()
 GetURL = "http://www.weather.com/search/search?where=" + City

 Dim Http
	
 Set Http = CreateObject("Microsoft.XMLhttp")
 Http.Open "GET",GetURL,False
 Http.Send
 HtmlResult = Http.ResponseText

 Set Http = Nothing

 set fs=CreateObject("Scripting.FileSystemObject")
 set f=fs.CreateTextFile("weather.tmp",true)
 f.write(htmlresult)
 f.close
 set f=nothing
 set fs=nothing
 writefile = "Tempfile written"
End Function

Function GetHTMLValue(LeftBound,RightBound, htmlresult)

tp = "weather.tmp"

Set file_obj = CreateObject ("Scripting.FileSystemObject")
If (file_obj.FileExists(tp)) Then
 Set file_path = file_obj.GetFile(tp) ' Creates the connection to the file
 set file = file_path.OpenAsTextStream (1, -2) ' Opens the file for reading

 htmlresult = file.readall
 
 File.Close ' Closes the file
Set file_path = nothing ' Resets variable
Set file_obj = nothing ' Resets variable

 HtmlStart = InStr(HtmlResult, LeftBound) + Len(LeftBound)
 HtmlEnd = InStr(HtmlStart, HtmlResult, RightBound)

 If HtmlStart > 0 AND HtmlEnd > 0 Then
  GetHTMLValue = Replace(Mid(HtmlResult, HtmlStart, HtmlEnd - HtmlStart ), "&nbsp;", " ")
 Else
  GetHTMLValue = "N/A"
 End If
Else
 GetHTMLValue = "N/A"
End If
End Function
Medlem sedan dec. 200012 464 inlägg
#4

Det beror på vilket värde du får tillbaka från funktionen GetHTMLValue. Om det är en sträng som kan konverteras till ett heltal så skall det fungera, däremot om den returnerar "N/A" t.ex, så borde du få det felet som du får nu.

Du kan lägga till en testutskrift

icon = GetHTMLValue("http://image.weather.com/web/common/wxicons/52/",".gif", "")
response.write "Debug: Icon = " & icon & "<br>"		
Symbol = icons(icon)

Funktionen GetHTMLValue returnerar N/A om filen weather.tmp inte finns eller om den inte hittar strängen i filen.

Du borde lägga till lite felhantering i så att du undviker problemet

icon = GetHTMLValue("http://image.weather.com/web/common/wxicons/52/",".gif", "")
'response.write "Debug: Icon = " & icon & "<br>"		
if isNumeric(icon) then Symbol = icons(icon) else symbol = ""
267 ms totalt · 4 externa anrop · v20260731065814-full.a51de22e
128 ms — deklarationer (db)
0 ms — hämta statistik (cache)
136 ms — hämta tråd, inlägg och bilagor (db)
128 ms — ändringar (db)