All source code in ASP/ VbScript Ask a ASP/ VbScript Pro Discussion Forum Categories All jobs in ASP/ VbScript
Quick Search for:  in language:    
ASP,Trying,with,blank,Request,variable,will,f
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
ASP/ VbScript Stats

 Code: 281,252. lines
 Jobs: 101. postings

 How to support the site

 
Sponsored by:

 
You are in:
 
Login

NEW! LEARNING CENTER
Special educational offers, white papers, webcasts, podcasts

  NEW! Download Rational Performance Tester V8 (download now)
  NEW! Download Rational Functional Tester V8 (download now)
  NEW! Download Rational Service Tester for SOA Quality V8 (download now)
  NEW! Teleconference: Quality In Action - Using Rational Quality Manager with Functional, Performance and Web Service Testing Products (download now)
  NEW! Introducing IBM Rational AppScan Developer Edition – easing security testing by non-security professionals (download now)

 

 


Latest postings for ASP/ VbScript.
Web Online Examination
By Suhas Manjunath Kashyap on 11/7


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!



 
 
   

Format Request Varibles

Print
Email
 
VB icon
Submitted on: 1/24/2001 4:33:53 PM
By: Chris Shell  
Level: Beginner
User Rating: By 3 Users
Compatibility:ASP (Active Server Pages)

Users have accessed this code 15115 times.
 
author picture
(About the author)
 
     Trying this with a blank Request variable will fail with a data conversion error: {Where Request("id") = ""} x = CLng(Request("id")) This will not fail: x = MakeLong(Request("id")) This code formats the values returned by the Request object. It is not meant to replace validation in your forms but assist in converting balnk strings, null values, etc. to the proper data type for saving. I found myself writing alot of if statements in my ASP pages for dealing with blank Request varibles and this fixes that with one line functions.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    '**************************************
    ' Name: Format Request Varibles
    ' Description:Trying this with a blank R
    '     equest variable will fail with a data co
    '     nversion error:
    {Where Request("id") = ""}
    x = CLng(Request("id"))
    This will Not fail:
    x = MakeLong(Request("id"))
    This code formats the values returned by the Request object. It is Not meant To replace validation In your forms but assist in converting balnk strings, null values, etc. to the proper data Type for saving. I found myself writing alot of if statements in my ASP pages for dealing With blank Request varibles and this fixes that with one line functions.
    ' By: Chris Shell
    '
    ' Inputs:sValue = Value from your Reques
    '     t Variable.
    '
    ' Returns:Properly formatted data depend
    '     ing on function.
    '
    ' Side Effects:None.
    '
    'This code is copyrighted and has    ' limited warranties.Please see http://w
    '     ww.Planet-Source-Code.com/vb/scripts/Sho
    '     wCode.asp?txtCodeId=6464&lngWId=4    'for details.    '**************************************
    
    'These Make Functions Handle data conver
    '     sions smoothly.
    'Request object does not return formatte
    '     d data properly
    'and rather than have alot of if stateme
    '     nts I use these 
    'functions.
    function MakeLong(sValue)
    	
    	MakeLong = 0
    	
    	if sValue <> "" Then
    		if IsNumeric(sValue) Then
    			MakeLong = CLng(sValue)
    		End if 
    	End if
    	
    End function
    function MakeInt(sValue)
    	
    	MakeInt = 0
    	
    	if sValue <> "" Then
    		if IsNumeric(sValue) Then
    			MakeInt = CInt(sValue)
    		End if 
    	End if
    	
    End function
    function MakeBool(sValue)
    	
    	MakeBool = False
    	
    	if sValue <> "" Then
    		if sValue = True Then
    			MakeBool = True
    		ElseIf UCase(sValue) = "TRUE" OR UCase(sValue) = "ON" OR UCase(sValue) = "CHECKED" Then 
    			MakeBool = True
    		ElseIf IsNumeric(sValue) Then
    			if CLng(sValue) <> 0 Then
    				MakeBool = True
    			End if
    		End if
    		
    	End if
    	
    End function
    function MakeDate(sValue)
    	
    	MakeDate = Null
    	
    	if sValue <> "" Then
    		if IsDate(sValue) Then
    			MakeDate = CDate(sValue)
    		End if
    		
    	End if
    	
    End function
    function MakeString(sValue)
    	if IsNull(sValue) Then
    		MakeString = ""
    	Else
    		MakeString = CStr(sValue)
    	End if
    End function
    	


Other 4 submission(s) by this author

 

 
 Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:
 
Your Vote!

What do you think of this code(in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
3/26/2001 10:00:08 AMTodd (BGL)

To quickly convert to a long type without errors, just use:

x = clng(
(If this comment was disrespectful, please report it.)

 
3/26/2001 10:01:02 AMTodd (BGL)

To quickly convert to a long type without errors, just use:

x = clng("0" & trim(request.form("id")))

(If this comment was disrespectful, please report it.)

 
5/18/2006 6:01:41 AMjackson Hoan

very good
(If this comment was disrespectful, please report it.)

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author from the email account you registered on the site, so you can correspond directly.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
To post feedback, first please login.


 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | ASP/ VbScript Home | Site Home | Other Sites | Open Letter from Moderators | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997-2008 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.   Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.