Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a parameter to a subroutine

Status
Not open for further replies.

smcc12

Programmer
Jan 8, 2009
17
US
Hello, I am trying to have an email send if it can't find a file. I have the subroutine to check the file, then if it can't find it I have:

Call emailReport(filename)

(filename being the variable of the file that's missing)

Then in my email subroutine:
Sub emailReport(filename)
...code...
objEmail.Textbody = "File missing: " & filename & ""


When this is run, I get "Microsoft VBScript runtime error: Wrong number of arguments or invalid property assignment: 'emailReport'"

1) is it possible to accomplish what i'm trying to do, and
2) what is wrong with the my code?

Thanks
 
Nothing looks wrong to me right now... which line throws the error? Is "emailReport" being called somewhere else with less than (or more than) one parameter?
 
Here's something that I wrote using blat to send the email. Perhaps this can help you:

On Error Resume Next
emaillist="somebody@somebody.com"

function CheckFile()
On Error Resume Next
set fso=WScript.CreateObject("Scripting.FileSystemObject")
If (fso.FileExists("\\server1\share\t.txt")) Then
CheckFile="yes"
Else
CheckFile="no"
End If
End Function

Sub send_alert(subj,msg)
On Error Resume Next
Set shell = WScript.CreateObject("WScript.Shell")
shell.Run "blat -to " & emaillist & " -subject """ & subj & """ -body """ & msg & "", 1, True
End Sub

Set fso=Wscript.CreateOBject("Scripting.FileSystemObject")
Set net=Wscript.CreateObject("WScript.Network")
Set shell=WScript.CreateObject("WScript.Shell")
If fso.FolderExists("\\server1\share") Then
emailit=CheckFile()
If emailit="yes" Then
subj="Upload Failure"
msg="The file failed to process"
Call send_alert(subj,msg)
End If
Else
WScript.Echo "Folder does not exist"
End If
set fso=nothing
set net=nothing
set shell=nothing
WScript.Quit
 
Hallo,

Have you tried using:
emailReport filename
instead of:
Call emailReport(filename)

I did read somewhere that putting the parameter in brackets causes the value to be evaluated and the result passed to the subroutine. This could be a problem as you are passing the parameter by reference.

However, as you are using Call, maybe this is ok.

- Frink
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top