473,387 Members | 1,483 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,387 software developers and data experts.

How can I test to see whether a particular object variable is defined?

Hi Gang,
I want to test and find out whether or not a particular variable object has
been defined. I need to know whether or not a recordset has already been
defined in the current script. However, my script crashes even though I've
disabled error handling, which doesn't make a whole lot of sense to me, but
anyways :). Here's my code:
---------------------------------------------------
on Error Resume Next

If objRS.Fields.GetCount > 1 Then
RestartRecordSet()
Else
OpenConnection()
End If

On Error Goto 0
-----------------------------------------------------
Is there some command like If isdef(objRS) then... or something to that
effect? Also is .GetCount the correct command? I think it is, but MSDN
help has a special way of giving too much information.

Thanks in advance,
Christian Blackburn

Jul 19 '05 #1
1 1520
Well, there is the IsObject function, but that's not completely reliable.
If you create an object and then destroy it, IsObject will still return a
true if you test if the variable is an object. So, you could use an On
Error Resume Next in conjunction with trying to access a property
(preferably the default property) of your object.

Example:

<%
Dim oADO
Response.Write IsObject(oADO) & " - should be false<br>"
Set oADO = CreateObject("ADODB.Connection")
Response.Write IsObject(oADO) & " - should be true<br>"
Set oADO = Nothing
Response.Write IsObject(oADO) & " - you'd think it'd be false, but it's
true.<br>"

On Error Resume Next
sTemp = oADO.ConnectionString
Response.Write "Is really an object that still exists in memory? " &
(Err.Number = 0)
On Error Goto 0
%>

Ray at work



"Christian Blackburn" <Ch*****************@Damn.Spam@Hotmail.com> wrote in
message news:u6**************@TK2MSFTNGP11.phx.gbl...
Hi Gang,
I want to test and find out whether or not a particular variable object
has
been defined. I need to know whether or not a recordset has already been
defined in the current script. However, my script crashes even though
I've
disabled error handling, which doesn't make a whole lot of sense to me,
but
anyways :). Here's my code:
---------------------------------------------------
on Error Resume Next

If objRS.Fields.GetCount > 1 Then
RestartRecordSet()
Else
OpenConnection()
End If

On Error Goto 0
-----------------------------------------------------
Is there some command like If isdef(objRS) then... or something to that
effect? Also is .GetCount the correct command? I think it is, but MSDN
help has a special way of giving too much information.

Thanks in advance,
Christian Blackburn


Jul 19 '05 #2

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

Similar topics

11
by: Squid Seven | last post by:
I create a pointer to an item: CardSession *cardSession; Then, later, I use new to create an instance of the item and assign it to that pointer: cardSession = new CardSession(); In...
9
by: Steve Sargent | last post by:
Hi: I'm trying to debug the following code, and it keeps looping on the if statement: public static bool operator == (OnlineMemberNode first, OnlineMemberNode second) { if(first == null) {
2
by: Jeff User | last post by:
Greetings I am writing code in a C# web service solution. I want to create an instance of an object (that I created) in a Session variable. I need to check to see if the Session variable has...
13
by: joenuts | last post by:
Is it possible for a function to test one of it's passed in variables (reference to object) for validity? I would like the displayString( string &obString) function to verify that obString 1)...
27
by: Josh | last post by:
We have a program written in VB6 (over 100,000 lines of code and 230 UI screens) that we want to get out of VB and into a better language. The program is over 10 years old and has already been...
14
by: ThazKool | last post by:
I want to see if this code works the way it should on a Big-Endian system. Also if anyone has any ideas on how determine this at compile-time so that I use the right decoding or encoding...
176
by: nw | last post by:
Hi, I previously asked for suggestions on teaching testing in C++. Based on some of the replies I received I decided that best way to proceed would be to teach the students how they might write...
60
by: marss | last post by:
Maybe anyone know good free online JavaScript knowledge test? This not exactly a system for testing online required - it may be simply list of questions with variants of answers (I have to prepare...
2
by: hcaptech | last post by:
This is my Test.can you help me ? 1.Which of the following statement about C# varialble is incorrect ? A.A variable is a computer memory location identified by a unique name B.A variable's name...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.