View Full Version : vbscript Function inside another function

Squall Leonhart
12-04-2003, 11:56 PM
Hi, guys.
I just want to ask you in vbscript if the function can be inside other functions.
Please take a look.

Function third

cn="DRIVER={Microsoft Access Driver (*.mdb)};"
cn=cn & "DBQ=" & server.mappath(accessdb)
Set rs = Server.CreateObject("ADODB.Recordset")
sql = "select * from tblFAQ"
rs.Open sql, cn
With Response
.Buffer = true
.Expires = 0
End With

'these functions come from http://codelib.aspemporium.com/
Function GetFreeFile(byval dir, byval dotextension)
Dim filename, f

filename = PathCombinePath(dir, GetRndFileName(dotextension))
set f = createobject("scripting.filesystemobject")
do while f.fileexists(filename)
filename = PathCombinePath(dir, GetRndFileName(dotextension))
set f = nothing

GetFreeFile = filename
End Function

function GetRndFileName(byval dotextension)
GetRndFileName = "Pricelist" & clng(todaysDate) & clng(timer) & dotextension
end function
end function

When I call Function third, it seems script recognize it as same as other functions so it crashes.

I want to make function structure like below.
Function third
Function GetFreeFile
End Function
Function GetRndFileName
End Function
End Function

Roy Sinclair
12-05-2003, 12:17 AM
Functions should have parameters, your function has none. That's probably why you're getting errors.