Solved

why can I only call the function one time

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Read More links 12 374
2 containers on one webpage 4 259
Coldfusion connection with xampp2 5 240
DW UserID Session from Login 1 113
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…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

739 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