"Type Mismatch" 下载图片时

"Type Mismatch" when downloading image

我正在创建一个程序来帮助我从天气网站下载图像,这样我就可以获得雷达图像。它创建一个名为 "radar" 的文件,然后是时间。例如,如果它是 5:00 PM,它将被命名为 Radar500.png.

下载没问题,但是提示某行出错:

Const adSaveCreateOverWrite = 2
Const adTypeBinary = 1
if hour(time) > 12 then
  a=hour(time)-12
else        
  if hour(time) = 0 then
    a="12"
  else
    a=hour(time)
    b=minute(time)
  end if
end if
b=minute(time)
strSource = ""
strDest = "C:\Users\Gabriel\Desktop\Overnight weather\radar"+a+"s"+b+".jpg"
WScript.Echo "path: "+strDest
'*****************************************************************
'** Download the image
strResult = GetImage(strSource, strDest)
If strResult = "OK" Then
  wscript.quit(0)
Else
  wscript.quit(1)
End If

Function GetImage(strPath, strDest)
  Dim objXMLHTTP, nF, arr, objFSO, objFile
  Dim objRec, objStream

  'create XMLHTTP component
  Set objXMLHTTP = CreateObject("Microsoft.XMLHTTP")

  'get the image specified by strPath
  objXMLHTTP.Open "GET", strPath, False
  objXMLHTTP.Send

  'check if retrieval was successful
  If objXMLHTTP.statusText = "OK" Then
    'create binary stream to write image output
    Set objStream = CreateObject("ADODB.Stream")
    objStream.Type = adTypeBinary
    objStream.Open
    objStream.Write objXMLHTTP.ResponseBody
    objStream.SavetoFile strDest, adSaveCreateOverwrite
    objStream.Close
    GetImage = "OK"
  Else
    GetImage = objXMLHTTP.statusText
  End If
End Function

他们说错误在第 29 行字符 1。

使用strDest = "C:\Users\...\radar" & a & "s" & b & ".jpg"。根据 MSDN: Addition Operator (+) (VBScript)

Although you can also use the + operator to concatenate two character strings, you should use the & operator for concatenation to eliminate ambiguity. When you use the + operator, you may not be able to determine whether addition or string concatenation will occur.

The type of the expressions determines the behavior of the + operator in the following way:

If                                                   Then
Both expressions are numeric                         Add
Both expressions are strings                         Concatenate
One expression is numeric and the other is a string  Error: type mismatch

...

您的脚本应该适用于接下来的更改:

  • 分配一个有效的 strSource 值,例如strSource = "http://www.goes.noaa.gov/FULLDISK/GMIR.JPG"
  • objXMLHTTP.Open "GET", strSource, False。注意 strSource 而不是你的 strDest