Peter
Peter

Reputation: 55

vbscript Function syntax error

I've lifted the following code from a thread here DateDiff in days, hours and mins

but I'm getting a syntax error on the first line of code and I can't work out why because it looks the same as other function syntax I've written that works fine.

Function TimeSpan(dt1, dt2) 

        seconds = Abs(DateDiff("S",dt1, dt2)) 
        minutes = seconds \ 60 
        hours = minutes \ 60 
        minutes = minutes mod 60 
        seconds = seconds mod 60 

        if len(hours) = 1 then hours = "0" & hours 

        TimeSpan = hours & ":" & _ 
            RIGHT("00" & minutes, 2) & ":" & _ 
            RIGHT("00" & seconds, 2) 

End Function 

dt1 = ActiveRequest.Fields("CreationDate").Value
dt2 = ActiveRequest.Fields("1stcontactdatetime").Value

The error I receive is: "Error in control script at line 1: Syntax error (Microsoft VBScript compilation error): FuntionTimeSpan(dt1, dt2)"

Any advice would be greatly appreciated, especially if it helps me not do it again!

Upvotes: 2

Views: 2666

Answers (1)

Noodles
Noodles

Reputation: 2011

Make it a sub or define a return variable.

Though my vbscript engine doesn't mind your code.

You are probably using the msscript.ocx (MS Script Control), it runs vbscripts in an application. Probably a help file in system32 for it.

Timespan is a class in the .NET framework.

The final thing is if using an edit control box, as notepad is and dialogs do, you get character problems. Paste into wordpad (based on a richtext edit control) so you can check for formatting edit controls ignore.

In the error message VBScript thinks there is no space between function and the function name.

Upvotes: 1

Related Questions