ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 30th, 2004, 12:18 PM
helz helz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 365 helz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 45 m 38 sec
Reputation Power: 10
how to check if a variable exists or isset in asp?

how can i check to see if a variable exists? or whether it has been set in asp?
thanks
__________________

Reply With Quote
  #2  
Old October 31st, 2004, 09:08 PM
SergeWiz's Avatar
SergeWiz SergeWiz is offline
http://www.softdevelop.ru
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 298 SergeWiz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 40 m 53 sec
Reputation Power: 9
Send a message via ICQ to SergeWiz Send a message via MSN to SergeWiz
try to use:

if not variable = null then ....

Reply With Quote
  #3  
Old November 1st, 2004, 02:26 AM
helz helz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 365 helz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 45 m 38 sec
Reputation Power: 10
i tried:

if NOT isnull(variable) then

but it doesnt work

Reply With Quote
  #4  
Old November 1st, 2004, 01:17 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Jun 2003
Posts: 14,235 Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 14 h 27 m 16 sec
Reputation Power: 4445
I don't think there is a similar VBScript function to isset, at least not one that comes to mind. I generally use Option Explicit in asp code so there aren't any undefined variables in code.
__________________
======
Doug G
======
It is a truism of American politics that no man who can win an election deserves to. --Trevanian, from the novel Shibumi

Reply With Quote
  #5  
Old November 1st, 2004, 01:23 PM
bocmaxima's Avatar
bocmaxima bocmaxima is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Aug 2004
Location: Tucson, Sonora
Posts: 1,371 bocmaxima User rank is Sergeant Major (2000 - 5000 Reputation Level)bocmaxima User rank is Sergeant Major (2000 - 5000 Reputation Level)bocmaxima User rank is Sergeant Major (2000 - 5000 Reputation Level)bocmaxima User rank is Sergeant Major (2000 - 5000 Reputation Level)bocmaxima User rank is Sergeant Major (2000 - 5000 Reputation Level)bocmaxima User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 4 Days 51 m 34 sec
Reputation Power: 50
Send a message via AIM to bocmaxima
In ASP, I typically use Len(variable)>2, or any number safe enough to make assumptions on. Typically, if a recordset or form variable is undefined, this will return 0, where in PHP, an error is thrown, thus the need for isset.

Hope that helps.

Reply With Quote
  #6  
Old November 9th, 2004, 03:16 PM
helz helz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 365 helz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 45 m 38 sec
Reputation Power: 10
so try len(var)>0

what ive got working is to find whether a form has been posted
in php i have used:
isset($_POST)
and
$_SERVER['REQUEST_METHOD'] == "post"

but i also use isset alot in php, to check if a variable has been set, if not then either create it or do something

what will Option Explicit do if i used it?
the: NOT isnull(var) option doesnt seem to work as an asp alternative to isset but could this be due to not setting Option Explicit?

Reply With Quote
  #7  
Old November 9th, 2004, 03:57 PM
bocmaxima's Avatar
bocmaxima bocmaxima is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Aug 2004
Location: Tucson, Sonora
Posts: 1,371 bocmaxima User rank is Sergeant Major (2000 - 5000 Reputation Level)bocmaxima User rank is Sergeant Major (2000 - 5000 Reputation Level)bocmaxima User rank is Sergeant Major (2000 - 5000 Reputation Level)bocmaxima User rank is Sergeant Major (2000 - 5000 Reputation Level)bocmaxima User rank is Sergeant Major (2000 - 5000 Reputation Level)bocmaxima User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 4 Days 51 m 34 sec
Reputation Power: 50
Send a message via AIM to bocmaxima
I've had no luck with the isnull function in the past. ASP seems to have strange ideas about the length and type of a variable pulled from a database.

Option Explicit requires that all variables be defined before they are called by using Dim. Normally ASP does not require this, and many lazy coders (me included) don't use it so that they don't have to write out every variable that they're going to use in the page.
Info on Option Explicit

To check whether a form has been posted, you can either do
If Len(Request.Form("fieldName")>1 Then
as long as that fieldName corresponds to a field you are certain will be populated.
Or, add a senseless URL variable to the form's action, like:
<form action="post.asp?submit=1">
Then:
If Request.QueryString("submit")=1 Then

Hope that helps.

Reply With Quote
  #8  
Old November 9th, 2004, 09:17 PM
SergeWiz's Avatar
SergeWiz SergeWiz is offline
http://www.softdevelop.ru
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 298 SergeWiz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 40 m 53 sec
Reputation Power: 9
Send a message via ICQ to SergeWiz Send a message via MSN to SergeWiz
if Request.ServerVariables("REQUEST_METHOD") = "POST" then
if not Request.Form("control_name") = "" then
..........

Reply With Quote
  #9  
Old November 9th, 2004, 10:03 PM
brightlight brightlight is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 371 brightlight User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 32 m 27 sec
Reputation Power: 10
I think ISEMPTY can be used

Cut and paste from the quote in ur ASP page and check what is the result
Quote:
dim vstr
vstr="Hello"

if isempty(vstr) then
Response.write "<br>V is empty <br>"
else
Response.write "<br>V is not empty <br>"
end if

//---vstr1 is not declared and assigned
if isempty(vstr1) then
Response.write "<br>V1 is empty <br>"
else
Response.write "<br>V1 is not empty <br>"
end if



ISEMPTY can be used as follows
Quote:
isEmpty(Request.Form("control_name")) for the existance of a single field

isempty(Request.Form) can be used to check whether the form has been submitted or not
__________________
Regards,
Brightlight

Last edited by brightlight : November 9th, 2004 at 10:34 PM.

Reply With Quote
  #10  
Old December 15th, 2004, 09:34 AM
willithepimp willithepimp is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 1 willithepimp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I'm having the same problem with an Isset or similar function.

Basically I'm trying to access a database, and if the select comes back with nothing then print one thing, otherwise print something else....

So Was there any conclusion to this thread then?

Reply With Quote
  #11  
Old December 15th, 2004, 10:27 AM
bocmaxima's Avatar
bocmaxima bocmaxima is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Aug 2004
Location: Tucson, Sonora
Posts: 1,371 bocmaxima User rank is Sergeant Major (2000 - 5000 Reputation Level)bocmaxima User rank is Sergeant Major (2000 - 5000 Reputation Level)bocmaxima User rank is Sergeant Major (2000 - 5000 Reputation Level)bocmaxima User rank is Sergeant Major (2000 - 5000 Reputation Level)bocmaxima User rank is Sergeant Major (2000 - 5000 Reputation Level)bocmaxima User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 4 Days 51 m 34 sec
Reputation Power: 50
Send a message via AIM to bocmaxima
I usually use this:

If Len(yourRS("yourField"))>1 Then
....DO SOMETHING....
Else
....DO SOMETHING ELSE....
End If

Does that not work?

Reply With Quote
  #12  
Old September 29th, 2010, 09:37 PM
rtorresbr rtorresbr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2010
Posts: 1 rtorresbr New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 26 m 59 sec
Reputation Power: 0
Try this

You can try use this code:

If TypeName(var) <> "Nothing" Then
....DO SOMETHING....
Else
....DO SOMETHING ELSE....
End If
Comments on this post
requinix disagrees: might have been helpful... back in 2004

Reply With Quote
  #13  
Old September 29th, 2010, 11:29 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Jun 2003
Posts: 14,235 Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 14 h 27 m 16 sec
Reputation Power: 4445
Quote:
Originally Posted by rtorresbr
You can try use this code:

If TypeName(var) <> "Nothing" Then
....DO SOMETHING....
Else
....DO SOMETHING ELSE....
End If
Thanks for the reply, but you may not have noticed this is a very old thread Also, I think the Nothing keyword only applies to object variables.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > how to check if a variable exists or isset in asp?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap