Solved

why can I only call the function one time

Posted on 2006-11-28
1
120 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

For those who don't know, Adobe Dreamweaver is a popular commercial web editor that enables you to design, build and manage complex websites. The editor is a WYSIWYG (What You See Is What You Get) web editor, which means that you can create your web…
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

910 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

22 Experts available now in Live!

Get 1:1 Help Now