I’m new to vbscript. I get the error
Declaration expected at get_html
At the bottom part of my code. I am actually trying to declare a value (which is a url) for the variable get_html. How can I resolve this?
Module Module1
Sub Main()
End Sub
Sub get_html(ByVal up_http, ByVal down_http)
Dim xmlhttp : xmlhttp = CreateObject("msxml2.xmlhttp.3.0")
xmlhttp.open("get", up_http, False)
xmlhttp.send()
Dim fso : fso = CreateObject("scripting.filesystemobject")
Dim newfile : newfile = fso.createtextfile(down_http, True)
newfile.write(xmlhttp.responseText)
newfile.close()
newfile = Nothing
xmlhttp = Nothing
End Sub
get_html _"http://www.somwwebsite.com", _"c:\downloads\website.html"
End Module
There are some syntax mistakes.
underscoreon page)xmlhttp.openis a sub, does not return anything). You have two main alternatives to calling a sub routine.sub_proc param1, param2orCall sub_proc(param1, param2)=‘ is not enough for the objects. You shoulduse Set statement. It assigns object references to the
variables.
The response may be return as utf-8 encoded. But however FSO is not at peace with utf-8. Another option is to write the response as unicode (passing
Trueas third parameter to CreateTextFile)but the output size will be larger than it should be. Therefore I would prefer to use Stream object.
I’ve revised your code. Please consider.