By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,805 Members | 1,056 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,805 IT Pros & Developers. It's quick & easy.

is it possible to capture the output of a function in asp?

P: n/a
I have a function that is a few thousand lines of code (I didn't write
it) and I want to capture the output and save it as a variable. This
is very easy to do in php. It would look something like this.
<?php
function myFunc(){
echo "something else"
}

//sent immediately to browser
echo "something"

//start capturing the output
ob_start();

myFunc()

$out = ob_get_clean();
//$out now contains 'something else'
//and 'something else' is never sent to the browser.

?>

Is this possible in ASP? I've searched the net and haven't been able
to find anything.
Jul 22 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Response.Write Function()

--
'dlbjr
'Pleading sagacious indoctrination!
Jul 22 '05 #2

P: n/a

"Jay Donnell" <ja********@gmail.com> wrote in message
news:9c*************************@posting.google.co m...
I have a function that is a few thousand lines of code (I didn't write
it) and I want to capture the output and save it as a variable. This
is very easy to do in php. It would look something like this.
<?php
function myFunc(){
echo "something else"
}

//sent immediately to browser
echo "something"

//start capturing the output
ob_start();

myFunc()

$out = ob_get_clean();
//$out now contains 'something else'
//and 'something else' is never sent to the browser.

?>

Is this possible in ASP? I've searched the net and haven't been able
to find anything.


your php function "myFunc()" would be considered a sub in vb because it does
not return a value.

here's a sample vb function:

Private Function SquareTheArg( x as Double) as Double
Return ( x * x)
End Function

***then to use the function***
dblAnswer = SquareTheArg( someVariable)
HTH
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.788 / Virus Database: 533 - Release Date: 11/1/2004
Jul 22 '05 #3

P: n/a
> here's a sample vb function:

Private Function SquareTheArg( x as Double) as Double
Return ( x * x)
End Function

***then to use the function***
dblAnswer = SquareTheArg( someVariable)


OOPS - that was dot-net junk
---retry---

function SquareTheArg( x)
SquareTheArg = x * x
End Function
*****
then to use the function -
resultVar = SquareTheArg( someVariable)
****Or to show the result directly**
<%= SquareTheVar( someVariable) %>

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.788 / Virus Database: 533 - Release Date: 11/1/2004
Jul 22 '05 #4

P: n/a
1. include the file in a separate ASP page that calls the function. get the
new page using xmlhttp (http://www.aspfaq.com/show.asp?id=2173).

2. rewrite the function to return a string containing the output instead of
writing it out directly. The difficulty of this will depend on how the
function is currently written but this would be the "better" approach.

--
Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com
"Jay Donnell" <ja********@gmail.com> wrote in message
news:9c*************************@posting.google.co m...
I have a function that is a few thousand lines of code (I didn't write
it) and I want to capture the output and save it as a variable. This
is very easy to do in php. It would look something like this.
<?php
function myFunc(){
echo "something else"
}

//sent immediately to browser
echo "something"

//start capturing the output
ob_start();

myFunc()

$out = ob_get_clean();
//$out now contains 'something else'
//and 'something else' is never sent to the browser.

?>

Is this possible in ASP? I've searched the net and haven't been able
to find anything.

Jul 22 '05 #5

P: n/a
Ok, I don't think I explained this very well. In php I can have a
function that uses echo(response.write) to send data to the browser.
However, I can tell php to buffer it and not send it to the browser.
Then I can grab the data that is in the buffer and put it in a
variable. In my example below the line in myFunc, echo "soemthing
else"; never gets sent to the browser and I put the contents of the
buffer in the variable $out. Basically, I have some asp code with a
very big function. I want to take all the data sent with
Response.Write and the plain html and capture it before it is sent to
the browser. I know that I can do something like

sub mySub
content = content & "some html here
....
end sub

I don't want to do this because the sub is thousands of lines of code
and I don't want to change it all. In asp you can do something like
Response.buffer = true and it will put all the output in a buffer and
send it all at once rather than piecemeal. I want to be able to get at
the data in the buffer before it is sent and stop it from beind sent.
ja********@gmail.com (Jay Donnell) wrote in message news:<9c*************************@posting.google.c om>...
I have a function that is a few thousand lines of code (I didn't write
it) and I want to capture the output and save it as a variable. This
is very easy to do in php. It would look something like this.
<?php
function myFunc(){
echo "something else"
}

//sent immediately to browser
echo "something"

//start capturing the output
ob_start();

myFunc()

$out = ob_get_clean();
//$out now contains 'something else'
//and 'something else' is never sent to the browser.

?>

Is this possible in ASP? I've searched the net and haven't been able
to find anything.

Jul 22 '05 #6

P: n/a
Jay Donnell wrote:
...I want to take all the data sent with Response.Write
and the plain html and capture it before it is sent to
the browser...

...I want to be able to get at the data in the buffer
before it is sent and stop it from beind sent...


Which one? Do you want to stop it or capture it?

I'm not sure you can accomplish what you want without modifying the
function. By all is not lost -- you can probably construct a suitable
search/replace for Response.Write() in your function.

For example, if the ASP scripting language is JScript, you could add this to
the beginning of your function...

var out = { value:"", add:function(x){this.value+=x} }

....then search for "Response.Write(" and replace with "output.add(". At the
end, Response.Write(out.value), conditionally of course.

It's trickier if VBScript, since the parentheses are optional with
Response.Write(), and it may be inconsistently coded.
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Jul 22 '05 #7

P: n/a
With response.buffer=true you can buffer the data and you can discard it if
you don't want to send it. However, you cannot access data in the buffer any
way that I know of.

--
Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com
"Jay Donnell" <ja********@gmail.com> wrote in message
news:9c**************************@posting.google.c om...
Ok, I don't think I explained this very well. In php I can have a
function that uses echo(response.write) to send data to the browser.
However, I can tell php to buffer it and not send it to the browser.
Then I can grab the data that is in the buffer and put it in a
variable. In my example below the line in myFunc, echo "soemthing
else"; never gets sent to the browser and I put the contents of the
buffer in the variable $out. Basically, I have some asp code with a
very big function. I want to take all the data sent with
Response.Write and the plain html and capture it before it is sent to
the browser. I know that I can do something like

sub mySub
content = content & "some html here
...
end sub

I don't want to do this because the sub is thousands of lines of code
and I don't want to change it all. In asp you can do something like
Response.buffer = true and it will put all the output in a buffer and
send it all at once rather than piecemeal. I want to be able to get at
the data in the buffer before it is sent and stop it from beind sent.
ja********@gmail.com (Jay Donnell) wrote in message

news:<9c*************************@posting.google.c om>...
I have a function that is a few thousand lines of code (I didn't write
it) and I want to capture the output and save it as a variable. This
is very easy to do in php. It would look something like this.
<?php
function myFunc(){
echo "something else"
}

//sent immediately to browser
echo "something"

//start capturing the output
ob_start();

myFunc()

$out = ob_get_clean();
//$out now contains 'something else'
//and 'something else' is never sent to the browser.

?>

Is this possible in ASP? I've searched the net and haven't been able
to find anything.

Jul 22 '05 #8

P: n/a
"Mark Schupp" <no****@nospam.com> wrote in message news:<eG**************@TK2MSFTNGP15.phx.gbl>...
1. include the file in a separate ASP page that calls the function. get the
new page using xmlhttp (http://www.aspfaq.com/show.asp?id=2173).
Thanks for the link. This seems like it might work well.
2. rewrite the function to return a string containing the output instead of
writing it out directly. The difficulty of this will depend on how the
function is currently written but this would be the "better" approach.


The reason I don't want to do this is that the function is literally
3000+ lines of code with html mixed in with the asp. Hopefully the
xmlhttp will work.
Jul 22 '05 #9

P: n/a
xmlhttp worked great. It isn't as flexible as the php buffer functions
like ob_start but it worked well for what I needed. Thanks
1. include the file in a separate ASP page that calls the function. get the
new page using xmlhttp (http://www.aspfaq.com/show.asp?id=2173).

Jul 22 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.