473,414 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

closing objects after returning value in function ??

Hi,

I am maintaining some code and I see in some functions..

Function myFunction

set someobj = Server.CreateObject("MYOBJ")
.....
....
set myFunction = "somedataToReturn"
set someobj = nothing

End Function

Sep 12 '05 #1
7 1564
sorry, my question is, is it valid to close an object after the return
statement and would it work?

"dotnettester" wrote:
Hi,

I am maintaining some code and I see in some functions..

Function myFunction

set someobj = Server.CreateObject("MYOBJ")
....
...
set myFunction = "somedataToReturn"
set someobj = nothing

End Function

Sep 12 '05 #2
I believe both Dave and I answered the question. Nothing after the End
statement is executed.

dotnettester wrote:
sorry, my question is, is it valid to close an object after the return
statement and would it work?

"dotnettester" wrote:
Hi,

I am maintaining some code and I see in some functions..

Function myFunction

set someobj = Server.CreateObject("MYOBJ")
....
...
set myFunction = "somedataToReturn"
set someobj = nothing

End Function


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Sep 12 '05 #3
Oops. Ignore my previous. I thought we were still on the Response.End
statement.

There is no "return" statement in vbscript. All statements in a procedure
will be executed until the statement that ends the procedure is executed,
unless an Exit <function|sub> statement is encountered.

So in this example "set someobj = nothing" will be executed. It's easy
enough to test this:

<%
dim globalvar
globalvar="initial value"
function changevar()
changevar = "I ran"
globalvar="new value"
end function
response.write changevar()
response.write "<BR>" & globalvar
%>

dotnettester wrote:
sorry, my question is, is it valid to close an object after the return
statement and would it work?

"dotnettester" wrote:
Hi,

I am maintaining some code and I see in some functions..

Function myFunction

set someobj = Server.CreateObject("MYOBJ")
....
...
set myFunction = "somedataToReturn"
set someobj = nothing

End Function


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Sep 12 '05 #4
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:%2*****************@TK2MSFTNGP12.phx.gbl...
I believe both Dave and I answered the question. Nothing after the End
statement is executed.

dotnettester wrote:
sorry, my question is, is it valid to close an object after the return
statement and would it work?

"dotnettester" wrote:
Hi,

I am maintaining some code and I see in some functions..

Function myFunction

set someobj = Server.CreateObject("MYOBJ")
....
...
set myFunction = "somedataToReturn"
set someobj = nothing

End Function


Actually, this question is slightly different from the Response.End
question. In this case, dotnettester is asking whether the statements after
a function return value assignment are processed. Specifically, does
"someobj" get deallocated in the above example? The answer is yes. Here's a
proof of concept demonstrating the behavior:

<%
Option Explicit
Function Foo(bar)
Foo = 1
Response.Write "Hello World!"
End Function
Response.Write "<br>Foo(0):" & Foo(0)
%>
Sep 12 '05 #5
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:O9***************@tk2msftngp13.phx.gbl...
Oops. Ignore my previous. I thought we were still on the Response.End
statement.

There is no "return" statement in vbscript. All statements in a procedure
will be executed until the statement that ends the procedure is executed,
unless an Exit <function|sub> statement is encountered.

So in this example "set someobj = nothing" will be executed. It's easy
enough to test this:

[snip]

To add to what Bob said, while there is no return statement in VBScript,
there is in JScript. It is also worth noting that the return statement in
JScript behaves as you would expect. That is, it exits the function
immediately. Therefore, the JScript counterpart to these examples would NOT
execute the statements following the return value assignment. The template
for JScript would look like this:

function foo(bar){
var retVal;
var myobj;
myobj = new ActiveXObject("My.Object");
retval = myobj.property;
myobj = null;
return retVal;
}
Sep 12 '05 #6
dotnettester wrote:
Function myFunction

set someobj = Server.CreateObject("MYOBJ")
....
...
set myFunction = "somedataToReturn"
set someobj = nothing

End Function


sorry, my question is, is it valid to close an object
after the return statement and would it work?


As noted elsewhere, there is no return statement in VBScript. I would also
add that the Set Statement is reserved for assigning object references, not
for assigning values.

--
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.
Sep 13 '05 #7
Thanks all.

"dotnettester" wrote:
sorry, my question is, is it valid to close an object after the return
statement and would it work?

"dotnettester" wrote:
Hi,

I am maintaining some code and I see in some functions..

Function myFunction

set someobj = Server.CreateObject("MYOBJ")
....
...
set myFunction = "somedataToReturn"
set someobj = nothing

End Function

Sep 13 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

49
by: Steven Bethard | last post by:
I promised I'd put together a PEP for a 'generic object' data type for Python 2.5 that allows one to replace __getitem__ style access with dotted-attribute style access (without declaring another...
20
by: svend | last post by:
I'm messing with some code here... Lets say I have this array: a1 = ; And I apply slice(0) on it, to create a copy: a2 = a1.slice(0); But this isn't a true copy. If I go a1 = 42, and then...
5
by: Gent | last post by:
I have two questions which are very similar: Is it possible to return an object in C++. Below is part of my code for reference however I am more concerned about the concept. It seems like the...
6
by: Martin | last post by:
I am having trouble trying to more closely relate objects (as functions) in javascript with HTML elements. For example, I have an object 'class' MyImage: function MyImage(file) { var img =...
3
by: tinman | last post by:
Hi.... Assume Function A in an application calls Function GetSomeData in another assembly..... which then is the prefered method to return the SqlDatareader object back to Function A (and why...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
8
by: Myron Marston | last post by:
For a WebService I am developing, I return a DataSet that contains a table listing Field Names and Field Values. The FieldValue column is given the type object becuase it can potentially contain...
3
by: Divick | last post by:
I was reading this section in Bruce Eckel's book which talks about passing and returning large objects ( Chapter 11: References & the Copy-Constructor ), where he explains that how to return big...
19
by: Daniel Pitts | last post by:
I have std::vector<Base *bases; I'd like to do something like: std::for_each(bases.begin(), bases.end(), operator delete); Is it possible without writing an adapter? Is there a better way? Is...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.