Actually, why couldn't you just dim "objConn" globally and make it equal nothing - setting as an object when required? IsOBject wouldnt fail then.
Main Topics
Browse All TopicsHi,
Im writing a script and i want to check whether a variable has been declared or not. My database connection name is objConn, and so i want to check whether that variable has been declared, if it hasnt the user is on a page that has no database driven content and so i dont want to query the DB...
I use IsObject(objConn) to check whether the variable is an object but because i have option explicit on every page that returns an error...
I could turn on On Error Resume Next before the IsObject statement but i dont like to do this because i will never know if theres an error.
Any ideas or solutions anyone....
Thanks in advance
Al Higgs
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Try define a function like below to check to see if the connection establish or not:
<%
function isDBConnectionOk(dbpath)
on error resume next
set conn=server.CreateObject("
conn.Open "Provider=MICROSOFT.JET.OL
if conn.state = 1 then
isDBConnectionOk = true
else
isDBConnectionOk = false
end if
conn.close
set conn = nothing
end function
%>
then
<%
if isDBConnectionOk("E:\sites
'database connection ok
else
'database connection failed
end if
%>
Here's the answer! the vbscript function 'VarType()' will tell what type the variable is - if it isnt declared it returns as 0.
http://www.devguru.com/tec
higgsy,
You can use TypeName() too to detect what type of the variables.
Eg:
<%
Dim x
x=request("strName")
Response.Write("VarType : " & TypeName(x))
%>
But, i believe after you put "Option Explicit" should alert for any undeclare variables. Then, you can know/fix which variables is still not declare.
Regards
x_com
As you are using Option Explicit, you have to declare the variable objConn if you want to check it's status.
I would rather put a constant in the include file that determines if the connection is opened:
Const blnHasDatabase=True
Then in the files without database connection, I would put:
Const blnHasDatabase=False
Then you simply check the constant for the status:
If blnHasDatabase Then
... do the query
End If
Business Accounts
Answer for Membership
by: justjuicePosted on 2003-10-23 at 02:55:54ID: 9605361
objToFind = "myobj"
objfound = false
For Each Item in Application.Contents
If Item = objToFind Then
objFound = true
Exit For
End If
Next
response.write("Object found?:" & objFound)