Solved

why can I only call the function one time

Posted on 2006-11-28
1
119 Views
Last Modified: 2010-04-25
I'm using ASP VBScript and I'm trying to create an upload page where I put the file name into a function and then display the function in a text field. There are two parts of the code, one which displays the name  and one which puts the code into the initial value of the text field. For some reason if I use the function in the "response.write" it will no longer display in the text field, if I erase the response.write part then the initial value displays correctly. Why will the function value not display in both places? Can I only use the function once? What am I not understanding? Below is the code, the functin name is "SaveFileName". Please let me know if you need more information. thanks.

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<  Set Function  >>>>>>>>>>>>>>>>>>
function SaveFileName
    Dim Upload, fileName, ks, i, fileKey

    Set Upload = New FreeASPUpload
    Upload.Save(uploadsDirVar)

      ' If something fails inside the script, but the exception is handled
      If Err.Number<>0 then Exit function

    SaveFileName = ""
    ks = Upload.UploadedFiles.keys
    if (UBound(ks) <> -1) then
        SaveFileName = ""
        for each fileKey in Upload.UploadedFiles.keys
            SaveFileName = SaveFileName & Upload.UploadedFiles(fileKey).FileName  
        next
    else
    end if
end function

<<<<<<<<<<<<<<<<<<<< display save file in text  "response.write">>>>>>>>>>>>>>>>>>>>>>>>
<%
Dim diagnostics
if Request.ServerVariables("REQUEST_METHOD") <> "POST" then
    diagnostics = TestEnvironment()
    if diagnostics<>"" then
        response.write "<div style=""margin-left:20; margin-top:30; margin-right:30; margin-bottom:30;"">"
        response.write diagnostics
        response.write "<p>After you correct this problem, reload the page."
        response.write "</div>"
    else
        response.write "<div style=""margin-left:150"">"
        OutputForm()
            OutputForm()
        response.write "</div>"
    end if
else
    response.write "<div style=""margin-left:150"">"
    OutputForm()
      response.write SaveFileName()
    response.write "<br><br></div>"
end if

%>

<<<<<<<<<<<<<<<<<<<<<<<< put function in text field >>>>>>>>>>>>>>>>>>>>>>>>

<form action="<%=MM_editAction%>" method="POST" name="datainput" id="datainput">
  <label>
  <input name="picture" type="text" id="picture" value="<%=SaveFileName()%>">
  </label>
  <label>
  <input type="submit" name="Submit" value="Submit">
</label>
  <input type="hidden" name="MM_insert" value="datainput">
</form>
0
Comment
Question by:elliottbenzle
1 Comment
 
LVL 25

Accepted Solution

by:
Rouchie earned 500 total points
Comment Utility
A function in most programming languages has to return a value after it has done the processing.  

So in your code you are saying that you want the value of <INPUT ID = "PICTURE" ...> to be the output from the <%=SaveFileName()%> function.

The SaveFileName() code processes some instructions, but it doesn't actually return a value after it has done this work.  This means that when the page reads the line

 <input name="picture" type="text" id="picture" value="<%=SaveFileName()%>">

the SaveFileName() code is executed.

What we need to do is to add an extra line of code into the function that returns the filenames that have been uploaded, rather than just read them all in and then do nothing.

function SaveFileName
    Dim Upload, fileName, ks, i, fileKey
    Set Upload = New FreeASPUpload
    Upload.Save(uploadsDirVar)
     ' If something fails inside the script, but the exception is handled
     If Err.Number<>0 then Exit function
    SaveFileName = ""
    ks = Upload.UploadedFiles.keys
    if (UBound(ks) <> -1) then
        SaveFileName = ""
        for each fileKey in Upload.UploadedFiles.keys
            SaveFileName = SaveFileName & Upload.UploadedFiles(fileKey).FileName  
        next
       Return SaveFileName ' <<---- ADDED THIS LINE TO RETURN SaveFileName variable's value back to calling area of the page
    end if
end function
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …
Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now