Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2003
    Location
    Canada
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts

    vbscript Function inside another function

    Hi, guys.
    I just want to ask you in vbscript if the function can be inside other functions.
    Please take a look.

    Code:
    Function third
    
    accessdb="tech_re" 
    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
    rs.MoveFirst
    With Response
    	.Buffer = true
    	.Expires = 0
    	.Clear
    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))
    	loop
    	set f = nothing
    
    	GetFreeFile = filename
    End Function
    
    function GetRndFileName(byval dotextension)
    	randomize
    	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

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Functions should have parameters, your function has none. That's probably why you're getting errors.
    Check out the Forum Search. It's the short path to getting great results from this forum.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •