C1 Community
ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

Problem with vbscript in a report

rated by 0 users
This post has 1 Reply | 0 Followers

Top 75 Contributor
Posts 71
domsinclair Posted: Sat, May 17 2008 12:06 PM

Can anyone enlighten me as to why the following script throws the error

 Invalid Assignment: '=' expected near 'ceiling' at line4, column 16 in the vbscript editor of the report designer.

 

I have tested the script in vbsedit and other compilers substittuting a real value for the one it might derive from the repoty and it works perfectly, so why does the report designer not like the function?

 

 

Field4.Value = Ceiling (Field3.value)

 

Function Ceiling(byval n)

Dim iTmp, bErr, f

on error resume next

n = cdbl(n)

if err then bErr = true

on error goto 0

if bErr then Err.Raise 5000, "Ceiling Function", _

"Input must be convertible to a sub-type of double"

f = Floor(n)

if f = n then

Ceiling = n

Exit Function

End If

Ceiling = cInt(f + 1)

End Function

Function Floor(byval n)

Dim iTmp, bErr

on error resume next

n = cdbl(n)

if err then bErr = true

on error goto 0

if bErr then Err.Raise 5000, "Floor Function", _

"Input must be convertible to a sub-type of double"

'Round() rounds up

iTmp = Round(n)

'test rounded value against the non rounded value

'if greater, subtract 1

if iTmp > n then iTmp = iTmp - 1

Floor = cInt(iTmp)

End Function

Top 75 Contributor
Posts 71

Well in answer to my own question and possibly to save anyone else wasting a heap of time on something like this it turns out that the C1 Reports vbscrit editor doesn't like functions, sub routines,arrays or case staements.

If anyone from C! reads this perhaps they could see if a large and prominennt note to that effect gets put into the help documentation.  It would I suspect save several people hours of time.

 

Just in case anyone out there see's the code I posted in the first post and thinks to themselves that a ceiling or floor function would be realluy useful in their reports then you can achieve the same with the following:

Ceiling function

-Int(-dividend/divider)

Floor Function

Int(dividend/divider)

 

Hope this helps someone and saves them a few hours.

Dom

Page 1 of 1 (2 items) | RSS
Contact ComponentOne: 1.800.858.2739 ©1987-2010 ComponentOne LLC All Rights Reserved.