472,958 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

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

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
9 2692
Response.Write Function()

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

"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
> 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
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
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
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: steve | last post by:
Hi, In my script (phpnuke), whenever there is access to database, there is this line of code: message_die(GENERAL_ERROR, ’some error msg’, ’’, __LINE__, __FILE__, $sql); Is there a more...
5
by: Aeon Twilight | last post by:
REFERENCE: http://us4.php.net/manual/en/function.include.php Example 16-7. include() through HTTP Example 16-10. include() and the return() statement -------------------- return.php...
2
by: Salad | last post by:
It's been years since I captured printer output, basically I've forgotten how to do it. Can you refresh my brain and let me know how it's done if it can be done in Access? I don't want the...
8
by: Daniel | last post by:
Hi, Does anyone know if it is possible to put an aspx page inside of another? OR run an aspx page and capture the output as a string and then write this out to a page.... So for example say...
5
by: Muffin | last post by:
I am trying to capture the out put of a command line program. Let say ping or maybe better yet nslookup. I would like to launch and then capture all the output , redirect it I guess to a string...
2
by: Brian Simmons | last post by:
Hi, Long story short: I've got a website built, and we moved it over to the production server, which is an SSL-required (https://...) server. A third party component that I'm using makes use of...
2
by: jdbartlett | last post by:
I'm trying to capture output from a command line utility (XMLSec), but only get an empty result. If I call the script from the command line, I see XMLSec's output, but I can't seem to capture it!...
13
by: Jim Langston | last post by:
I had asked this in comp.lang.c++ with out any answers that would actually work, so I'm hoping someone here may know a way. I am calling C library functions that want to output to stdout. I need...
5
by: vasilis | last post by:
I have a list box in a site with which I capture a selected value with the onChange event using the capture_value() function (code listed below). This function passes 2 arguments, i.e., 'str' which...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.