Solved

why can I only call the function one time

Posted on 2006-11-28
1
127 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 25

Accepted Solution

by:
Rouchie earned 500 total points
ID: 18034719
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

696 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