Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - cannot use parenthesis when calling sub

Reply
 
Old 05-06-2009   #1 (permalink)
techstress


 
 

cannot use parenthesis when calling sub

throws an error

cannot use parenthesis when calling a sub

i'm calling a function, what can I do to fix this?


Code:
file1 = "http://www.devguru.com/technologies/wsh/17413.asp"

downloadfile(file1, "c:\file.html")



function downloadfile(strFileURL, strHDLocation)

'http://blog.netnerds.net/2007/01/vbscript-download-and-save-a-binary-
file/

' Fetch the file
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")

objXMLHTTP.open "GET", strFileURL, false
objXMLHTTP.send()

If objXMLHTTP.Status = 200 Then
Set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open
objADOStream.Type = 1 'adTypeBinary

objADOStream.Write objXMLHTTP.ResponseBody
objADOStream.Position = 0 'Set the stream position to the
start

Set objFSO = Createobject("Scripting.FileSystemObject")
If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile
strHDLocation
Set objFSO = Nothing

objADOStream.SaveToFile strHDLocation
objADOStream.Close
Set objADOStream = Nothing
End if

Set objXMLHTTP = Nothing

end function

My System SpecsSystem Spec
Old 05-06-2009   #2 (permalink)
Al Dunbar


 
 

Re: cannot use parenthesis when calling sub


"techstress" <foscsamuels@xxxxxx> wrote in message
news:2d55042a-594b-4980-8d2f-c5386fd9aa20@xxxxxx
Quote:

> throws an error
>
> cannot use parenthesis when calling a sub
>
> i'm calling a function, what can I do to fix this?
functions are (almost exactly) the same as subs, and can be "invoked" in
much the same way:

Either use "call":

call downloadfile(file1, "c:\file.html")

don't use parentheses:

downloadfile file1, "c:\file.html"

or assign the return value to a variable:

temp = downloadfile(file1, "c:\file.html") ' this one is for
functions only

But I am wondering why you coded this as a function when it returns no
result.

/Al
Quote:

>
>
> Code:
> file1 = "http://www.devguru.com/technologies/wsh/17413.asp"
>
> downloadfile(file1, "c:\file.html")
>
>
>
> function downloadfile(strFileURL, strHDLocation)
>
> 'http://blog.netnerds.net/2007/01/vbscript-download-and-save-a-binary-
> file/
>
> ' Fetch the file
> Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
>
> objXMLHTTP.open "GET", strFileURL, false
> objXMLHTTP.send()
>
> If objXMLHTTP.Status = 200 Then
> Set objADOStream = CreateObject("ADODB.Stream")
> objADOStream.Open
> objADOStream.Type = 1 'adTypeBinary
>
> objADOStream.Write objXMLHTTP.ResponseBody
> objADOStream.Position = 0 'Set the stream position to the
> start
>
> Set objFSO = Createobject("Scripting.FileSystemObject")
> If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile
> strHDLocation
> Set objFSO = Nothing
>
> objADOStream.SaveToFile strHDLocation
> objADOStream.Close
> Set objADOStream = Nothing
> End if
>
> Set objXMLHTTP = Nothing
>
> end function

My System SpecsSystem Spec
Old 05-07-2009   #3 (permalink)
Bob Barrows


 
 

Re: cannot use parenthesis when calling sub

techstress wrote:
Quote:

> throws an error
>
> cannot use parenthesis when calling a sub
>
> i'm calling a function, what can I do to fix this?
>
>
Just to add to Al's reply:
http://blogs.msdn.com/ericlippert/ar.../15/52996.aspx

--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
comparing a string that contains a parenthesis PowerShell
Calling ID Vista mail
Search for files with parenthesis in name Vista file management
How do you search for files containing parenthesis? Vista file management
Searching for names with parenthesis in them Vista file management


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46