<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Hot Scripts Blog &#187; ASP &amp; ASP.NET</title>
	<atom:link href="http://www.hotscripts.com/blog/category/tutorials/asp-aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hotscripts.com/blog</link>
	<description></description>
	<lastBuildDate>Thu, 17 May 2012 12:18:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Active Server Pages</title>
		<link>http://www.hotscripts.com/blog/active-server-pages/</link>
		<comments>http://www.hotscripts.com/blog/active-server-pages/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 03:00:52 +0000</pubDate>
		<dc:creator>DEVpapers</dc:creator>
				<category><![CDATA[ASP & ASP.NET]]></category>

		<guid isPermaLink="false">http://www.hotscripts.com/blog/?p=740</guid>
		<description><![CDATA[Many new to web application development will choose to use ASP because it is relatively quick to learn and easy to use. Here is an overview of the technology; how it works along with a brief introduction to the ASP objects.<p>Post from: <a href="http://www.hotscripts.com/blog">Hot Scripts Blog</a><br/><br/><a href="http://www.hotscripts.com/blog/active-server-pages/">Active Server Pages</a></p>

Related posts:<ol>
<li><a href='http://www.hotscripts.com/blog/automatically-hyperlink-urls-and-e-mail-addresses-in-asp-net/' rel='bookmark' title='Automatically Hyperlink URLs and E-Mail Addresses in ASP.NET Pages with C#'>Automatically Hyperlink URLs and E-Mail Addresses in ASP.NET Pages with C#</a></li>
<li><a href='http://www.hotscripts.com/blog/counting-users-online/' rel='bookmark' title='Counting how many users you have online'>Counting how many users you have online</a></li>
<li><a href='http://www.hotscripts.com/blog/building-printer-friendly-pages/' rel='bookmark' title='Building Printer Friendly Pages'>Building Printer Friendly Pages</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><span><span style="font-family: Verdana; ">If you are new to the whole scripting scene and don&#8217;t have any kind of programming experience behind you, then Active Server Pages (ASP) is probably one of the easiest ways to start in the world of web application development. This article provides a quick overview to help you get an idea of how the technology works and if it is for you.</span></span></p>
<p><span style="font-family: Verdana; ">Active Server Pages was a technology introduced by Microsoft in Internet Information Server 2.0. Code named Denali, the technology uses a small Internet Server Programming Application Interface filter (ISAPI Filter) that loads any required scripting language interpreters when a user first requests an ASP page. Because the filter is in memory for as long as the server is running, there is no additional overhead of starting new processes and so it is thought to be much kinder on server resources than the traditional CGI applications.</span></p>
<p><span style="font-family: Verdana; "><strong><span style="color: #ff0000;">How ASP works</span></strong><br />
When an ASP page is requested, the ASP ISAPI filter executes any server side code it finds in the page before sending back a more browser friendly response. Normally this is HTML, but can be HTML with embedded scripts, images or any other file type so long as the correct headers are sent along with the response.<br />
The response an ASP page gives to a request can be manipulated by the use of ASP objects, each have their own properties and methods that can be manipulated by any scripting language that has been configured to run with the server (typically VBScript).</span></p>
<p><span style="font-family: Verdana; "><strong><span style="color: #ff0000;">ASP Objects</span></strong></span></p>
<p><span style="font-family: Verdana; "><strong> </strong> </span></p>
<ul><span style="font-family: Verdana; "></p>
<li>Application</li>
<li>ObjectContext</li>
<li>Response</li>
<li>Request</li>
<li>Server</li>
<li>Session</li>
<p></span></ul>
<p><span style="font-family: Verdana; ">The ASP objects listed above are of little use on their own, you will need to be familiar with at least one scripting language before you can start to build your own pages that use these objects. VBScript is the common choice, not only is it the default scripting language that is assumed for ASP pages, but it is the scripting language that is most like English.</span></p>
<p><span style="font-family: Verdana; "> </span><span style="font-family: Verdana; "><br />
<strong><span style="color: #ff0000;">Application</span></strong><br />
The Application object is one that represents the whole domain space, without it ASP will not work. Before ASP can work, you have to create the application; this tells the server to load the ASP ISAPI filter for the files in that particular space. The application object will then run in the background on the server until it is stopped or restarted.<br />
Any variables that you store in the application will be available to all your ASP pages, and so this is an easy way to pass data from one script to another. However it does use system resources (such as memory) and so the use of application level variables is not very efficient and can in some cases slow down your site.</span></p>
<p><span style="font-family: Verdana; "><span style="color: #ff0000;"><strong>ObjectContext</strong></span><br />
The objectcontext object allows you to create and run transactions. The best way to describe a transaction is a piece of code that can be undone should there be problems.</span></p>
<p><span style="font-family: Verdana; "><strong><span style="color: #ff0000;">Response</span></strong><br />
The response object will send the results of any server side scripts back to the user&#8217;s browser. It has methods to add headers telling the browser when to expire the page, what character set to use and can even detect if the connection originally used to request the page has been closed. This can be a handy feature as it can stop scripts when there is no one there to see the page, thus saving data transfer and server resources.<br />
Not only does the response object control what gets sent back to the browser, but also how it gets sent back. It is possible to buffer the response and send it back when the whole script is finished, or you could send the data back in chunks to let your visitors know that it is still working.</span></p>
<p><span style="font-family: Verdana; "><strong><span style="color: #ff0000;">Request<br />
</span></strong>The request object holds all the information that has been sent from the user that can be used in your scripts. This includes any page headers, cookies, form or URL data. Fortunately, all this data has been parsed to some degree and so you don&#8217;t need to worry about breaking it all down and putting it back together again; just remember to make sure that it is safe to use!</span></p>
<p><span style="font-family: Verdana; "><strong><span style="color: #ff0000;">Server</span></strong><br />
The server object is mainly used as a utility object; helping create new instances of add-in ASP objects, find the real path of a file and converting output to make it more browser friendly. It can also be used to set the server time out response, which is handy for scripts that need a longer time to execute without sending any output to the browser.</span></p>
<p><span style="font-family: Verdana; "><strong><span style="color: #ff0000;">Session</span></strong><br />
The session object works a little like the application object, but is specific to the user and the browser they are using. It can make a viable alternative to cookies used to store and move data between scripts, but as sessions tend to expire very quickly (usually 20 minutes after last activity) they can only store data temporarily.</span></p>
<p><span style="font-family: Verdana; "><span style="color: #ff0000;"><strong>Expanding ASP Capabilities</strong></span><br />
There are other objects that are additional to the built in objects listed above that can be used to provide additional functionality.</span></p>
<ul><span style="font-family: Verdana; "></p>
<li><strong>FileSystemObject </strong>- allows ASP pages to interact directly with files stored anywhere on the host server (which is why a few hosts have this disabled). This is a useful object; Web Site Owner relies on it to create the pages.</li>
<li><strong>CDONTS</strong> (Collaboration Data Objects for Windows NT Server) &#8211; used to send and receive messages, this object is Microsoft&#8217;s offering of adding mail capabilities to a site. As the name suggests, it is a little dated now and most of the hosts I&#8217;ve asked tend to prefer other 3rd party objects to do the same job; JMail and ASPEmail being two prefererred replacements.</li>
<li><strong>ADO</strong> (ActiveX Data Objects) &#8211; used to interact with databases (either physical or those created in working memory).</li>
<p></span></ul>
<p><span style="font-family: Verdana; "><span style="color: #ff0000;"><strong>Conclusion</strong></span><br />
ASP may not be as fast as some of the scripting languages available today, but it is the easiest for a beginner to learn and with a little imagination and a logical mind it can do a wide variety of things.</span></p>
<div class="hotlist"><strong>Author:  Rosemarie Wise</strong><br />
The author, Rosemarie Wise, is a self proclaimed &#8220;web enthusiast&#8221; who set up her site, <a href="http://www.websiteowner.info">Web Site Owner</a> to share her experiences of being a site owner.</div>
<p>Post from: <a href="http://www.hotscripts.com/blog">Hot Scripts Blog</a><br/><br/><a href="http://www.hotscripts.com/blog/active-server-pages/">Active Server Pages</a></p>
<p>Related posts:<ol>
<li><a href='http://www.hotscripts.com/blog/automatically-hyperlink-urls-and-e-mail-addresses-in-asp-net/' rel='bookmark' title='Automatically Hyperlink URLs and E-Mail Addresses in ASP.NET Pages with C#'>Automatically Hyperlink URLs and E-Mail Addresses in ASP.NET Pages with C#</a></li>
<li><a href='http://www.hotscripts.com/blog/counting-users-online/' rel='bookmark' title='Counting how many users you have online'>Counting how many users you have online</a></li>
<li><a href='http://www.hotscripts.com/blog/building-printer-friendly-pages/' rel='bookmark' title='Building Printer Friendly Pages'>Building Printer Friendly Pages</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.hotscripts.com/blog/active-server-pages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using built-in functions in ASP</title>
		<link>http://www.hotscripts.com/blog/built-in-functions-in-asp/</link>
		<comments>http://www.hotscripts.com/blog/built-in-functions-in-asp/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 03:00:52 +0000</pubDate>
		<dc:creator>DEVpapers</dc:creator>
				<category><![CDATA[ASP & ASP.NET]]></category>

		<guid isPermaLink="false">http://www.hotscripts.com/blog/?p=745</guid>
		<description><![CDATA[There are a lot of functions in ASP. Some are for type checking, typecasting, formatting, math, date and string manipulation. One of the greatest thing I love about vbscript, is they are easy to learn and use.<p>Post from: <a href="http://www.hotscripts.com/blog">Hot Scripts Blog</a><br/><br/><a href="http://www.hotscripts.com/blog/built-in-functions-in-asp/">Using built-in functions in ASP</a></p>

Related posts:<ol>
<li><a href='http://www.hotscripts.com/blog/using-built-in-asp-components/' rel='bookmark' title='Using Built-In ASP Components'>Using Built-In ASP Components</a></li>
<li><a href='http://www.hotscripts.com/blog/using-the-asp-querystring/' rel='bookmark' title='Using the ASP QueryString'>Using the ASP QueryString</a></li>
<li><a href='http://www.hotscripts.com/blog/including-a-file-in-a-asp-page/' rel='bookmark' title='Including a file in a ASP page'>Including a file in a ASP page</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><span style="font-family: Verdana; "><strong>Type Checking</strong></span></p>
<p><span style="font-family: Verdana; ">These functions allow you to figure out data types.</span></p>
<p><span style="font-family: Verdana;"> </span></p>
<p><span style="font-family: Verdana;"><span style=""><span style="font-family: Courier New; color: #ff4500;">TypeName()</span><br />
</span></span><span style="font-family: Verdana; ">Returns the data type rather than the code.</span></p>
<p><span style="font-family: Verdana;"> </span></p>
<p><span style="font-family: Verdana;"><span style=""><span style="font-family: Courier New; color: #ff4500;">IsNumeric()</span><br />
</span></span><span style="font-family: Verdana; ">Returns a boolean value of true if the data type is that of a number and false if otherwise.</span></p>
<p><span style=""><span style="font-family: Verdana;"><span style="color: #ff4500;"><span style="font-family: Courier New;">IsArray()</span><br />
</span></span><span style="font-family: Verdana;">Returns a boolean value of true if the data type is that of an array and false if otherwise.</span></span></p>
<p><span style=""><span style="font-family: Courier New; color: #ff4500;">IsDate()<br />
</span><span style="font-family: Verdana;">Returns a boolean value of true if the data type is that of a date and false if otherwise.</span></span></p>
<p><span style=""><span style="font-family: Verdana;"><span style="font-family: Courier New; color: #ff4500;">IsEmpty()</span><br />
</span><span style="font-family: Verdana;">Returns a boolean value of true if the data type is a empty value and false if otherwise.</span></span></p>
<p><span style="font-family: Verdana; "><span style="color: #ff4500;"><span style="font-family: Courier New;">IsNull()</span><br />
</span></span><span style="font-family: Verdana; ">Returns a boolean value of true if the data type contains no valid data and false if otherwise.<br />
</span><span style="font-family: Verdana;"><br />
<span style=""><span style="font-family: Courier New; color: #ff4500;">IsObject()</span><br />
</span></span><span style="font-family: Verdana; ">Returns a boolean value of true if the data type is that of an object and false if otherwise.</span></p>
<p><span style="font-family: Verdana; "><strong>Typecasting</strong></span></p>
<p><span style="font-family: Verdana; ">What&#8217;s typecasting? Typecasting converts between data types. For instance, if you have data you obtained from a form, it&#8217;s considered text. However, with typecasting, you can convert that variable into a date value.</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Dim idate<br />
&#8216;Get the DOB from the form<br />
idate = Request.Form(&#8220;DOB&#8221;)<br />
&#8216;Convert it to a date<br />
idate = cdate(idate)</span></p>
<p><span style="font-family: Verdana; ">With the CBool() function, you can get a boolean value. If the number is 0, you get a boolean value of false, otherwise you get a boolean value of true. The following code will return true.</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Dim inumber<br />
inumber = 12<br />
If CBool(inumber) = True Then<br />
Response.Write &#8220;True&#8221;<br />
Else<br />
Response.Write &#8220;False&#8221;<br />
End If</span></p>
<p><span style="font-family: Verdana; "><strong>Formatting Functions</strong></span></p>
<p><span style="font-family: Verdana; ">Formatting functions are useful when you need to display data the way you want it. For results, you will end up with a string. The code below will return 4/6/2004</p>
<p><span style="font-family: Courier New; color: #ff4500;">Response.Write FormatDatetime(date, vbshortdate)</span> </span></p>
<p><span style="font-family: Verdana; ">You can also display the date like this: Tuesday, April 06, 2004, using the following code:</p>
<p><span style="font-family: Courier New; color: #ff4500;">Response.Write FormatDatetime(date, vblongdate)</span> </span></p>
<p><span style="font-family: Verdana; ">The same applies to time:</p>
<p><span style="font-family: Courier New; color: #ff4500;">Response.Write FormatDatetime(time, vblongtime)</span> </span></p>
<p><span style="font-family: Verdana; "><strong>Math functions</strong></span></p>
<p><span style="font-family: Verdana; ">Vbscript has lot&#8217;s of math functions, however, you won&#8217;t use them very often, so I will only list a couple.</span></p>
<p><span style="font-family: Verdana; ">Rnd(), when used with randomize, will generate an random number (random enough) less the one and greater than or equal to zero. Try out the following code:</p>
<p><span style="font-family: Courier New; color: #ff4500;">randomize<br />
Response.Write rnd</span> </span></p>
<p><span style="font-family: Verdana; ">What does randomize do? Randomize uses the system timer to start the random number generator.</span></p>
<p><span style="font-family: Verdana; ">Another vbscript math function you might run into is the Round() function. And as you would guess, it rounds numbers.</p>
<p><span style="font-family: Courier New; color: #ff4500;">Round(9.99)</span> </span></p>
<p><span style="font-family: Verdana; ">The code above returns 10.</span></p>
<p><span style="font-family: Verdana; "><strong>Date Functions</strong></span></p>
<p><span style="font-family: Verdana; ">When working in vbscript, you will come across dates and their values. Luckily, vbscript as a ton of built-in functions just for this. </span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">&#8216;add a month<br />
Response.Write DateAdd(&#8220;m&#8221;, 1, #12-09-1981#)<br />
&#8216;add a year<br />
Response.Write DateAdd(&#8220;yyyy&#8221;, 1, #12-09-1981#)<br />
&#8216;add a day<br />
Response.Write DateAdd(&#8220;d&#8221;, 1, #12-09-1981#)</span></p>
<p><span style="font-family: Verdana; ">As you can see, one month, year and day is added to the dates. Remember to add the # character at the beginning and the end of a date. This tells vbscript to treat the following string as a date and not as a math problem: 12/09/1981 = 12 divided by 09 divided by 1981</span></p>
<p><span style="font-family: Verdana; ">If you want to figure out the number of days, month or years between to dates, you can use the DateDiff() function.</p>
<p><span style="font-family: Courier New; color: #ff4500;">DateDiff(&#8220;yyyy&#8221;, #12-09-1981#, #12-09-1982#, )</span> </span></p>
<p><span style="font-family: Verdana; ">The code above returns 1, since there&#8217;s one year between 12-09-1981 and 12-09-1982. </span></p>
<p><span style="font-family: Verdana; ">If you need to obtain a value from a variable and place it into an existing date, you can use the DateSerial() function. </span></p>
<p><span style="font-family: Verdana; "><span style="font-family: Courier New; color: #ff4500;">Dim iday<br />
iday = 12<br />
Response.Write DateSerial(year(date), month(date), iday)</span> </span></p>
<p><span style="font-family: Verdana; ">The following code takes the variable iday and places it into the present month and year to create a date. As you can see from above, date returns the present date. </span></p>
<p><span style="font-family: Verdana; ">To get the year of the present date, use the following code:</p>
<p><span style="font-family: Courier New; color: #ff4500;">Response.Write year(date)</span> </span></p>
<p><span style="font-family: Verdana; ">There&#8217;s also the TimeSerial() function, which is just like the DateSerial() function, except it uses times not dates. </span></p>
<p><span style="font-family: Verdana; ">Now what if you want to only get a certain part of a date? You can use the function DatePart().</p>
<p><span style="font-family: Courier New; color: #ff4500;">DatePart(&#8220;m&#8221;, #12-09-1981#)</span> </span></p>
<p><span style="font-family: Verdana; ">The code above will return 12 as you assumed. </span></p>
<p><span style="font-family: Verdana; ">If you want to get the month name instead of a number, you can call the MonthName() function.</p>
<p><span style="font-family: Courier New; color: #ff4500;">Response.Write monthname(12)</span> </span></p>
<p><span style="font-family: Verdana; ">The code above returns December. To abbreviate this, use the argument abbrev.</p>
<p><span style="font-family: Courier New; color: #ff4500;">Response.Write monthname(12, true)</span> </span></p>
<p><span style="font-family: Verdana; ">To get the name of the present month, do the following:</p>
<p><span style="font-family: Courier New; color: #ff4500;">Response.Write monthname(month(date), true)</span> </span></p>
<p><span style="font-family: Verdana; "><strong>String Functions</strong></span></p>
<p><span style="font-family: Verdana; ">Probably the most useful functions in vbscript would be the string functions. And there&#8217;s a lot of them.</span></p>
<p><span style="font-family: Verdana; ">If you need text in all upper/lower case characters, use the UCase() or LCase() functions:</p>
<p><span style="font-family: Courier New; color: #ff4500;">Response.Write UCase(&#8220;codehungry&#8221;)<br />
Response.Write LCase(&#8220;CODEHUNGRY&#8221;)</span> </span></p>
<p><span style="font-family: Verdana; ">LTrim() and RTrim() remove blank spaces from the left and right of a string.</p>
<p><span style="font-family: Courier New; color: #ff4500;">Response.Write LTrim(mytext)<br />
Response.Write RTrim(mytext)</span> </span></p>
<p><span style="font-family: Verdana; ">And of course, Trim() removes spaces from both sides.</span></p>
<p><span style="font-family: Verdana; ">Space() will give you any number of spaces you specify:</p>
<p><span style="font-family: Courier New; color: #ff4500;">Response.Write Space(12) &amp; &#8220;Start my text here!!!&#8221;</span> </span></p>
<p><span style="font-family: Verdana; ">String() will give you any number of characters you specify:</p>
<p><span style="font-family: Courier New; color: #ff4500;">Response.Write String(12, &#8220;$&#8221;)</span> </span></p>
<p><span style="font-family: Verdana; ">Len() returns the number of characters in a word</p>
<p><span style="font-family: Courier New; color: #ff4500;">Response.Write Len(myvariable)</span> </span></p>
<p><span style="font-family: Verdana; ">The StrComp() function is used to compare to strings:</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Dim mytext1, mytext2<br />
mytext1 = &#8220;Andrew&#8221;<br />
mytext2 = &#8220;Jennifer&#8221;<br />
Response.Write StrComp(mytext1, mytext2, 1)</span></p>
<p><span style="font-family: Verdana; ">The following code would return -1 because mytext1 is less than mytext2. If you were to reverse the two strings, you would get a value of 1 because mytext1 would be greater than mytext2. If the strings where the same, you would get a result of 0. </span></p>
<p><span style="font-family: Verdana; ">The last argument is the comparetype argument. If this argument is 1, then the two strings are compared texturally. If the comparetype argument is set to 0, then the two strings are compared binaurally. For instance, Apple and apple would be considered the same word if they were compared texturally. If they where compared binaurally, the would be considered different. </span></p>
<p><span style="font-family: Verdana; ">The Right() and Left() functions will return the number of characters from a string that you specify starting in that direction.</p>
<p><span style="font-family: Courier New; color: #ff4500;">Response.Write Left(&#8220;Andrew Schools&#8221;, 6)</span><br />
</span><span style="font-family: Verdana; ">Returns Andrew</span></p>
<p><span style="font-family: Verdana; "><span style="font-family: Courier New; color: #ff4500;">Response.Write Right(&#8220;Andrew Schools&#8221;, <img src='http://www.hotscripts.com/blog/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> </span><br />
</span><span style="font-family: Verdana; ">Returns Schools</span></p>
<p><span style="font-family: Verdana; ">The Mid() function works almost like the Right() and Left() function. For an example:<br />
</span><span style="font-family: Verdana; "><br />
<span style="font-family: Courier New; color: #ff4500;">Response.Write Mid(&#8220;Andrew Schools&#8221;, 1, 6)</span><br />
</span><span style="font-family: Verdana; ">Returns Andrew<br />
</span><span style="font-family: Verdana; "><br />
<span style="font-family: Courier New; color: #ff4500;">Response.Write Mid(&#8220;Andrew Schools&#8221;, 8, 15)</span><br />
</span><span style="font-family: Verdana; ">Returns Schools</span></p>
<p><span style="font-family: Verdana; ">The Instr() function is a very useful and powerful function. It is used to check where string1 is within string2 and gives you a numeric value.</p>
<p><span style="font-family: Courier New; color: #ff4500;">Instr(start, string1, string2, compartype)</span> </span></p>
<p><span style="font-family: Verdana; ">As you can see from above, the start argument lets you specify where in string1 you want to start. And remember comparetype is used to compare the text texturally or binaurally. The code below will find the letter a.</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Dim mytext<br />
mytext = &#8220;ActiveServerPages&#8221;<br />
Response.Write Instr(1, mytext, &#8220;a&#8221;, 1)</span></p>
<p><span style="font-family: Verdana; ">The code above would return 1</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Dim mytext<br />
mytext = &#8220;ActiveServerPages&#8221;<br />
Response.Write Instr(2, mytext, &#8220;a&#8221;, 1)</span></p>
<p><span style="font-family: Verdana; ">The code above returns 14</span></p>
<p><span style="font-family: Verdana; ">And than there&#8217;s the InstrRev() function which works just like the Instr() function except it starts looking for the match starting from right to left.</span></p>
<p><span style="font-family: Verdana; ">The Replace() function is also a very useful and powerful function. It allows you to search for a string within a string and replace it with whatever your heart my desire. The Replace() function takes the following arguments. They are self explanatory.</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Replace(string1, find, replace, start, count, comparetype)</span></p>
<p><span style="font-family: Verdana; ">To use the Replace() function, try the code below.</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Dim mytext<br />
mytext = &#8220;Try to find the dog&#8221;<br />
mytext = Replace(mytext, &#8220;dog&#8221;, &#8220;cat&#8221;, 1, -1, 1)</span></p>
<p><span style="font-family: Verdana; ">The code above will find word dog and replace it with the word cat.</span></p>
<p><span style="font-family: Verdana; ">The filter() function searches an array. It includes the following arguments:</p>
<p><span style="font-family: Courier New; color: #ff4500;">Filter(array, searchfor, include, comparetype)</span> </span></p>
<p><span style="font-family: Verdana; ">The include argument is boolean value. If it&#8217;s set to true, it will find all strings containing the character from searchfor. If it&#8217;s set to false, then filter() will return all strings not containing the character searchfor.</p>
<p><span style="font-family: Courier New; color: #ff4500;">Dim myarray, arr<br />
myarray = array(&#8220;Andrew&#8221;, &#8220;Jennifer&#8221;, &#8220;Jessie&#8221;)<br />
myarray = Filter(myarray, &#8220;j&#8221;, True, 1)<br />
For Each arr in myarray<br />
Response.Write arr &amp; &#8220;&lt;BR&gt;&#8221;<br />
Next </span></span></p>
<p><span style="font-family: Verdana; ">The code above searches the array myarray for words that have the letter j in it. There is a little more to this code than just that. You must use a For&#8230;Next loop to retrieve the values from the array. </span></p>
<p><span style="font-family: Verdana; ">Split() will take a string and split it up into an array. The Split() function takes the following arguments:</p>
<p><span style="font-family: Courier New; color: #ff4500;">Split(expression, delimiter, count, comparetype)</span> </span></p>
<p><span style="font-family: Verdana; ">Expression is the string you want to split up. Delimiter is what you want to separate the new strings. The code below takes a string and makes it an array:</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Dim mytext<br />
mytext = &#8220;Andrew;Schools;Code;Hungry&#8221;<br />
mytext = Split(string1, &#8220;;&#8221;, -1, 1)</span></p>
<p><span style="font-family: Verdana; ">And if you wanted to retrieve those strings from that array, you need a For&#8230;Each loop.</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Dim mytext<br />
mytext = &#8220;Andrew;Schools;Code;Hungry&#8221;<br />
mytext = Split(mytext, &#8220;;&#8221;, -1, 1)<br />
For Each arr in mytext<br />
Response.Write arr &amp; &#8220;&lt;BR&gt;&#8221;<br />
Next</span></p>
<p><span style="font-family: Verdana; ">Join() is the opposite if Split(). It takes an array and makes one string:</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Dim myarray, string1<br />
myarray = Array(&#8220;Andrew&#8221;, &#8220;Schools&#8221;, &#8220;Code&#8221;, &#8220;Hungry&#8221;)<br />
string1 = Join(myarray, &#8220;;&#8221;)<br />
Response.Write string1</span></p>
<p><span style="font-family: Verdana; ">Returns &#8220;Andrew;Schools;Code;Hungry&#8221;</span></p>
<p><span style="font-family: Verdana; ">Since we are on the subject of arrays, the functions LBound() and UBound() come in handy. If you want all the strings in an array, you can do the following:</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Dim myarray, iloop<br />
myarray = Array(&#8220;Andrew&#8221;, &#8220;Schools&#8221;, &#8220;Code&#8221;, &#8220;Hungry&#8221;)<br />
For iloop = LBound(myarray) to UBound(myarray)<br />
Response.Write myarray(iloop) &amp; &#8220;&lt;BR&gt;&#8221;<br />
Next</span></p>
<p><span style="font-family: Verdana; ">As you can see, LBound() returns the smallest index (usually zero) while UBound() returns the largest index.</span></p>
<p><span style="font-family: Verdana; ">When you use the keyboard, the computer sees numbers while you see letters. For instance, the letter A is really 65 and a is 97. Using the ASC() function, you can figure out what any letter converts to:</p>
<p><span style="font-family: Courier New; color: #ff4500;">ASC(&#8220;A&#8221;)</span> </span></p>
<p><span style="font-family: Verdana; ">Which returns 65</span></p>
<p><span style="font-family: Verdana; ">Or you can use the CHR() function to convert the number back to the character is represents:</p>
<p><span style="font-family: Courier New; color: #ff4500;">CHR(&#8220;65&#8243;)</span> </span></p>
<p><span style="font-family: Verdana; ">Which returns A</span></p>
<p><span style="font-family: Verdana; ">To list the entire alphabet, you can use a For&#8230;Next loop with the ASC() and CHR() functions:</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">For iloop = ASC(&#8220;A&#8221;) to ASC(&#8220;Z&#8221;)<br />
Response.Write CHR(iloop) &amp;vbcrlf<br />
Next</span></p>
<p><span style="font-family: Verdana; ">Which will return A B C D E F G H I J K L M N O P Q R S T U V W X Y Z</span></p>
<div class="hotlist"><strong>Author: </strong>Andrew Schools</div>
<p>Post from: <a href="http://www.hotscripts.com/blog">Hot Scripts Blog</a><br/><br/><a href="http://www.hotscripts.com/blog/built-in-functions-in-asp/">Using built-in functions in ASP</a></p>
<p>Related posts:<ol>
<li><a href='http://www.hotscripts.com/blog/using-built-in-asp-components/' rel='bookmark' title='Using Built-In ASP Components'>Using Built-In ASP Components</a></li>
<li><a href='http://www.hotscripts.com/blog/using-the-asp-querystring/' rel='bookmark' title='Using the ASP QueryString'>Using the ASP QueryString</a></li>
<li><a href='http://www.hotscripts.com/blog/including-a-file-in-a-asp-page/' rel='bookmark' title='Including a file in a ASP page'>Including a file in a ASP page</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.hotscripts.com/blog/built-in-functions-in-asp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Counting how many users you have online</title>
		<link>http://www.hotscripts.com/blog/counting-users-online/</link>
		<comments>http://www.hotscripts.com/blog/counting-users-online/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 03:00:52 +0000</pubDate>
		<dc:creator>DEVpapers</dc:creator>
				<category><![CDATA[ASP & ASP.NET]]></category>

		<guid isPermaLink="false">http://www.hotscripts.com/blog/?p=747</guid>
		<description><![CDATA[Counting how many users you currently have viewing your website is a neat thing to add to your site and it's simple. In order to create this script, you must learn about session, application objects and the global.asa file.<p>Post from: <a href="http://www.hotscripts.com/blog">Hot Scripts Blog</a><br/><br/><a href="http://www.hotscripts.com/blog/counting-users-online/">Counting how many users you have online</a></p>

Related posts:<ol>
<li><a href='http://www.hotscripts.com/blog/active-server-pages/' rel='bookmark' title='Active Server Pages'>Active Server Pages</a></li>
<li><a href='http://www.hotscripts.com/blog/online-screen-recording-services/' rel='bookmark' title='Online Screen Recording Services Reviewed'>Online Screen Recording Services Reviewed</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><span style="font-family: Verdana; "><strong>Session Object</strong></span></p>
<p><span style="font-family: Verdana; ">The session object, a built-in ASP object, refers to a new client accessing your webpage. For instance, when a user enters your site, the server adds a special cookie to the visitors browser, which is called the ASPSessionID cookie. This ASPSessionID cookie can be very useful when you need to identify a particular user.</span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">Randomize</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Session(&#8220;user&#8221;) = rnd()</span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">The code above will give the session variable user the value of a random number. This will identify this user throughout their journey until they leave our site or close their browser.</span></p>
<p><span style="font-family: Verdana; "><strong>The Application Object</strong></span></p>
<p><span style="font-family: Verdana; ">The application object is another built-in ASP Object that works almost like the session object except it refers to all users. For instance, if you create a application variable named id and give it the value of 21, all users viewing your site would have a application variable named id with the value of 21.</span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span><span style="font-family: Courier New; color: #ff4500;">application(&#8220;id&#8221;) = 21</span> </span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; "><strong>The Global.asa File</strong></span></p>
<p><span style="font-family: Verdana; ">So what&#8217;s the Global.asa file? The Global.asa file executes event handlers when a user first comes to our site. What are event handlers? Event handlers describe what needs to happen at a certain event. There are two events the session and application objects support. The On_Start and On_End event. When a user first enters our site, the On_Start handler is triggered and any code inside the On_Start handler is executed. And as you would guess, when a user leaves our site or closes their browser, the On_End handler is triggered and any code inside the On_End handler is executed. </span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">&lt;Script Language=VBScript RUNAT=Server&gt;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Sub Session_OnStart()</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Randomize</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Session(&#8220;user&#8221;) = Rnd()</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">End Sub</span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">The first line of code is a script tag which specifies that VBScript is the language we are using and it will run on the server. We then create a subroutine which is triggered when a user enters our website and takes the session variable user and gives it the value of a random number.</span></p>
<p><span style="font-family: Verdana; "><strong>Creating the Code</strong></span></p>
<p><span style="font-family: Verdana; ">Now, in order to create a script that counts how many users a currently viewing our site, we must use both the application and session objects with both On_Start and On_End event handlers.</span></p>
<p><span style="font-family: Verdana; color: #191970; "><em><strong>global.asa</strong></em></span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">&lt;SCRIPT LANGUAGE=&#8221;VBScript&#8221; RUNAT=&#8221;Server&#8221;&gt; </span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Sub Session_OnStart<br />
application.lock()<br />
application(&#8220;activeusers&#8221;) = application(&#8220;activeusers&#8221;) + 1<br />
application.unlock()<br />
End Sub </span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Sub Session_OnEnd<br />
application.lock()<br />
application(&#8220;activeusers&#8221;) = application(&#8220;activeusers&#8221;) &#8211; 1<br />
application.unlock()<br />
End Sub</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">&lt;/SCRIPT&gt;</span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">The code above will count how many users are currently viewing our site. If you are a little confused, don&#8217;t worry. We will dissect the code line by line.</span></p>
<p><span style="font-family: Verdana; ">The first line of code as I said above specifies that VBScript is the language we are using and it will run on the server.</span></p>
<p><span style="font-family: Verdana; ">The third line of code creates a subroutine which is called when a user enters our site. </span></p>
<p><span style="font-family: Verdana; ">Now the next line of code is new. We haven&#8217;t discussed it in this tutorial. The application object has the lock() and unlock() methods. When you lock the application object, you ensure that no one else can edit it while it&#8217;s being edited. And the unlock() method unlocks the application object so it can be edited once again. </span></p>
<p><span style="font-family: Verdana; ">After we lock the application object, we edit the application variable activeusers and add it by 1 since a new user has entered our site. Now to some people, this is confusing at first. Why do we use a application variable instead of a session variable? The reason for this is because, the session object is used to only refer to one user while the application object refers to all users. If we used a session object instead of a application object, all of our users would have a session variable named activeusers equal to 1 which would be no good to us. In order for use to track how many users are viewing our site, we must first track each user that enters our site by using the Session On_Start event and then add the application variable activeusers by 1, which refers to all users who have entered our site.</span></p>
<p><span style="font-family: Verdana; ">Now we can unlock the application object so the next user can use it.</span></p>
<p><span style="font-family: Verdana; ">The next chunk of code is just the same as the code above, except it is triggered when a user either leaves the site or closes their browser. When this happens, the application variable activeusers is subtracted by 1 since a user has left our site.</span></p>
<p><span style="font-family: Verdana; ">The last line of code is our closing script tag.</span></p>
<p><span style="font-family: Verdana; ">So how do you display the number of active users currently viewing your site? You place the following line of code in one of your asp pages:</span></p>
<p><span style="font-family: Verdana; "><strong><em><span style="color: #191970;">index.asp</span></em></strong></span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">Response.Write Application(&#8220;activeusers&#8221;) </span></td>
</tr>
</tbody>
</table>
<div class="hotlist"><strong>Author: </strong>Andrew Schools</div>
<p>Post from: <a href="http://www.hotscripts.com/blog">Hot Scripts Blog</a><br/><br/><a href="http://www.hotscripts.com/blog/counting-users-online/">Counting how many users you have online</a></p>
<p>Related posts:<ol>
<li><a href='http://www.hotscripts.com/blog/active-server-pages/' rel='bookmark' title='Active Server Pages'>Active Server Pages</a></li>
<li><a href='http://www.hotscripts.com/blog/online-screen-recording-services/' rel='bookmark' title='Online Screen Recording Services Reviewed'>Online Screen Recording Services Reviewed</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.hotscripts.com/blog/counting-users-online/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatically Hyperlink URLs and E-Mail Addresses in ASP.NET Pages with C#</title>
		<link>http://www.hotscripts.com/blog/automatically-hyperlink-urls-and-e-mail-addresses-in-asp-net/</link>
		<comments>http://www.hotscripts.com/blog/automatically-hyperlink-urls-and-e-mail-addresses-in-asp-net/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 03:00:51 +0000</pubDate>
		<dc:creator>DEVpapers</dc:creator>
				<category><![CDATA[ASP & ASP.NET]]></category>

		<guid isPermaLink="false">http://www.hotscripts.com/blog/?p=759</guid>
		<description><![CDATA[This article introduces how to hyperlink URLs and e-mail addresses in ASP.NET pages with C#, When you design a forum or other Web site, the code is very useful.<p>Post from: <a href="http://www.hotscripts.com/blog">Hot Scripts Blog</a><br/><br/><a href="http://www.hotscripts.com/blog/automatically-hyperlink-urls-and-e-mail-addresses-in-asp-net/">Automatically Hyperlink URLs and E-Mail Addresses in ASP.NET Pages with C#</a></p>

Related posts:<ol>
<li><a href='http://www.hotscripts.com/blog/including-a-file-in-a-asp-page/' rel='bookmark' title='Including a file in a ASP page'>Including a file in a ASP page</a></li>
<li><a href='http://www.hotscripts.com/blog/using-built-in-asp-components/' rel='bookmark' title='Using Built-In ASP Components'>Using Built-In ASP Components</a></li>
<li><a href='http://www.hotscripts.com/blog/using-the-asp-querystring/' rel='bookmark' title='Using the ASP QueryString'>Using the ASP QueryString</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div><span><span style="font-family: Verdana; ">After I designed a web site, </span><span style="font-family: Verdana; ">I found that many users post URL and e-mail information, but these URLs and e-mails just display as text. If you want to visit these URLs or e-mail addressess, you have to copy them and then paste them to your browser or e-mail client. I searched articles about automatically hyperlinking URLs, but only found VB source code. So, I decided do it myself.</span><span style="font-family: Verdana; "><strong>Using the Code</strong></span></p>
<p><span style="font-family: Verdana; ">The first step is how to detect URLs and e-mail addresses. Of course, the best way is with regular expressions. By using regular expressions, you can automatically detect hyperlink-sensitive text and automatically wrap it into elements pointing to the same URL. Here&#8217;s how to proceed. The idea is to preprocess any displayable text using ad hoc regular expressions to identify portions of text that are e-mail addresses or Web site URLs. You create a RegEx object and initialize it with the regular expression. Next, you call IsMatch on the input string to see whether at least one match is found. Next, you call the Replace method. Replace takes the input as its first argument.</span></p>
<p><span style="font-family: Verdana; ">First, when you use regular expressions, you must include System.Text.RegularExpressions:</span></p>
<p><span style="font-family: Verdana; ">using System.Text.RegularExpressions;<br />
The second step is to detect a URL:</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Regex urlregex = new Regex(@&#8221;(http:\/\/([\w.]+\/?)\S*)&#8221;,<br />
RegexOptions.IgnoreCase|RegexOptions.Compiled);</span></p>
<p><span style="font-family: Verdana; ">Here is how to detect an e-mail address:</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Regex emailregex = new Regex(@&#8221;([a-zA-Z_0-9.-]+\@[a-zA-Z_0-9.-]+\.\w+)&#8221;,<br />
RegexOptions.IgnoreCase|RegexOptions.Compiled);</span></p>
<p><span style="font-family: Verdana; ">When you detect a URL or e-mail address, you need to replace it with &lt;a href=&#8230;&gt;&lt;/a&gt;. I put all these into a function.</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">private void Button1_Click(object sender, System.EventArgs e)<br />
{<br />
string strContent = InputTextBox.Text;<br />
Regex urlregex = new Regex(@&#8221;(http:\/\/([\w.]+\/?)\S*)&#8221;,<br />
RegexOptions.IgnoreCase| RegexOptions.Compiled);<br />
strContent = urlregex.Replace(strContent,<br />
&#8220;&lt;a href=\&#8221;\&#8221; target=\&#8221;_blank\&#8221;&gt;&lt;/a&gt;&#8221;);<br />
Regex emailregex = new Regex(@&#8221;([a-zA-Z_0-9.-]+\@[a-zA-Z_0-9.-]+\.\w+)&#8221;,<br />
RegexOptions.IgnoreCase| RegexOptions.Compiled);<br />
strContent = emailregex.Replace(strContent, &#8220;&lt;a href=mailto:&gt;&lt;/a&gt;&#8221;);<br />
lbContent.Text += &#8220;&lt;br&gt;&#8221;+strContent;<br />
}</span></p>
<p><span style="font-family: Verdana; ">Here you go. Build this control library, add references to your project, and enjoy validating.</span></p>
<p></span></div>
<div class="hotlist"><strong>Author: </strong>Roland Luo<br />
Roland Luo is a computer developer &amp; designer working with computers and the Internet since 2001. Started out doing Classic ASP, and moved on from there. My skillset now encompasses ASP, ASP.NET / C#, C++, VC++, MFC, SQL Server.</div>
<p>Post from: <a href="http://www.hotscripts.com/blog">Hot Scripts Blog</a><br/><br/><a href="http://www.hotscripts.com/blog/automatically-hyperlink-urls-and-e-mail-addresses-in-asp-net/">Automatically Hyperlink URLs and E-Mail Addresses in ASP.NET Pages with C#</a></p>
<p>Related posts:<ol>
<li><a href='http://www.hotscripts.com/blog/including-a-file-in-a-asp-page/' rel='bookmark' title='Including a file in a ASP page'>Including a file in a ASP page</a></li>
<li><a href='http://www.hotscripts.com/blog/using-built-in-asp-components/' rel='bookmark' title='Using Built-In ASP Components'>Using Built-In ASP Components</a></li>
<li><a href='http://www.hotscripts.com/blog/using-the-asp-querystring/' rel='bookmark' title='Using the ASP QueryString'>Using the ASP QueryString</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.hotscripts.com/blog/automatically-hyperlink-urls-and-e-mail-addresses-in-asp-net/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Retrieving Values from a CheckBox</title>
		<link>http://www.hotscripts.com/blog/retrieving-values-from-a-checkbox/</link>
		<comments>http://www.hotscripts.com/blog/retrieving-values-from-a-checkbox/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 03:00:51 +0000</pubDate>
		<dc:creator>DEVpapers</dc:creator>
				<category><![CDATA[ASP & ASP.NET]]></category>

		<guid isPermaLink="false">http://www.hotscripts.com/blog/?p=749</guid>
		<description><![CDATA[When you need to retrieve values from a checkbox that come in a array. This tutorials demonstrates how to retrieve those values as individual values.<p>Post from: <a href="http://www.hotscripts.com/blog">Hot Scripts Blog</a><br/><br/><a href="http://www.hotscripts.com/blog/retrieving-values-from-a-checkbox/">Retrieving Values from a CheckBox</a></p>

Related posts:<ol>
<li><a href='http://www.hotscripts.com/blog/hot-scripts-forum-digest-nov-8th-2009/' rel='bookmark' title='Hot Scripts Forum Digest &#8211; Nov 8th, 2009'>Hot Scripts Forum Digest &#8211; Nov 8th, 2009</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div><span><span style="font-family: Verdana; "><strong>Why use checkboxes</strong></span></p>
<p><span style="font-family: Verdana; ">Checkboxes come in useful when you have several choices that can be selected. For instance, if you had a form that asked a user what kind of <a id="KonaLink0" style="text-decoration: underline ! important; position: static;" href="http://www.devpapers.com/#" target="undefined"><span style="color: blue ! important; font-weight: 400; font-size: 13px; position: static;"><span style="color: blue ! important; font-family: Verdana; font-weight: 400; font-size: 13px; position: static;">computer</span></span></a> they owned, they could select more than one computer.</span></p>
<p><span style="font-family: Verdana; "><strong>How to use checkboxes</strong></span></p>
<p><span style="font-family: Verdana; ">Using checkboxes are simple. The one thing you got to remember is checkboxes are a group, which means they all must have the same name, however, different values.</span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">&lt;form action=&#8221;myform_pro.asp&#8221; name=&#8221;myform&#8221; action=&#8221;post&#8221;&gt;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">What type of computer do you have?&lt;br&gt;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Dell&lt;input type=&#8221;checkbox&#8221; name=&#8221;computer&#8221; value=&#8221;dell&#8221;&gt;&lt;BR&gt;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">GateWay&lt;input type=&#8221;checkbox&#8221; name=&#8221;computer&#8221; value=&#8221;GateWay&#8221;&gt;&lt;BR&gt;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Apple&lt;input type=&#8221;checkbox&#8221; name=&#8221;computer&#8221; value=&#8221;apple&#8221;&gt;&lt;BR&gt;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">&lt;input type=&#8221;submit&#8221;&gt;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">&lt;/form&gt;</span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">The first line of code starts our form and gives it the value of myform. The action property is set at post so no information is past through the browser address bar (querystring). The action property tells our browser where to take the information once the form is submitted so the information can be processed. </span></p>
<p><span style="font-family: Verdana; ">We then create a checkbox using the input tag. As you can see, every checkbox has the same name but a different value. Why? We give the checkboxes the same name so we know they are from the same group. </span></p>
<p><span style="font-family: Verdana; ">Our last lines of code submits and closes our form.</span></p>
<p><span style="font-family: Verdana; ">So what happens once the form is submitted? It goes to myform_pro.asp. Now, in order to retrieve what checkboxes where clicked, you can use the following code:</span></p>
<p><span style="font-family: Verdana; "><strong>myform_pro.asp</strong></span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">Response.Write Request.Form(&#8220;computer&#8221;) </span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">The code above will retrieve for you what checkboxes were clicked. If all checkboxes were clicked, you would see the following:</span></p>
<p align="center"><span style="font-family: Verdana; "><strong>dell, gateway, apple</strong> </span></p>
<p><span style="font-family: Verdana; ">Now you know what checkboxes where clicked, however, it&#8217;s one string. This could be a problem if you wanted to store each option separately for polling reasons. With ASP, there&#8217;s a solution. It&#8217;s the VBScript Split() function.</span></p>
<p><span style="font-family: Verdana; "><strong>myform_pro.asp</strong></span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">choices = Request.Form(&#8220;computer&#8221;)</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">choices = Split(choices, &#8220;,&#8221;)</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">For Each member in choices</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Response.Write member &amp; &#8220;&lt;BR&gt;&#8221;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Next</span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">At first this might seem a little overwhelming, but let me assure you it&#8217;s nothing special. Let me explain each line of code to you.</span></p>
<p><span style="font-family: Verdana; ">The first line of code retrieves the values from the form.</span></p>
<p><span style="font-family: Verdana; ">The second line of code uses the VBScript Split() function to split the values from our comma-delimted string. For instance, when the Split() function finds a comma, it stops, makes the following word it&#8217;s own string and then starts again until it finds another comma and so on&#8230;</span></p>
<p><span style="font-family: Verdana; ">So what happens to all of our new string of words? Well they are actually an array of strings and in order to retrieve those values from an array, we must use a For&#8230;Next Loop. This brings us to our last lines of code.</span></p>
<p><span style="font-family: Verdana; ">A For&#8230;Next Loop is used to iterate through each member of a group and that&#8217;s what we use to retrieve our values. </span></p>
<p><span style="font-family: Verdana; ">Now since you have those values from our form, you can store them in a database or redirect the user to a page that sells Dell computers, etc.</span></p>
<p></span></div>
<div class="hotlist"><strong>Author: </strong>Andrew Schools</div>
<p>Post from: <a href="http://www.hotscripts.com/blog">Hot Scripts Blog</a><br/><br/><a href="http://www.hotscripts.com/blog/retrieving-values-from-a-checkbox/">Retrieving Values from a CheckBox</a></p>
<p>Related posts:<ol>
<li><a href='http://www.hotscripts.com/blog/hot-scripts-forum-digest-nov-8th-2009/' rel='bookmark' title='Hot Scripts Forum Digest &#8211; Nov 8th, 2009'>Hot Scripts Forum Digest &#8211; Nov 8th, 2009</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.hotscripts.com/blog/retrieving-values-from-a-checkbox/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simple ASP database techniques</title>
		<link>http://www.hotscripts.com/blog/simple-asp-database-techniques/</link>
		<comments>http://www.hotscripts.com/blog/simple-asp-database-techniques/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 03:00:51 +0000</pubDate>
		<dc:creator>DEVpapers</dc:creator>
				<category><![CDATA[ASP & ASP.NET]]></category>

		<guid isPermaLink="false">http://www.hotscripts.com/blog/?p=753</guid>
		<description><![CDATA[When you start using ASP, you will begin working with databases. Interacting with databases can be very important. In this tutorial, we will be using a Microsoft Access Database along with technologies like ADO and the Connection and Recordset objects.<p>Post from: <a href="http://www.hotscripts.com/blog">Hot Scripts Blog</a><br/><br/><a href="http://www.hotscripts.com/blog/simple-asp-database-techniques/">Simple ASP database techniques</a></p>

Related posts:<ol>
<li><a href='http://www.hotscripts.com/blog/using-the-asp-querystring/' rel='bookmark' title='Using the ASP QueryString'>Using the ASP QueryString</a></li>
<li><a href='http://www.hotscripts.com/blog/using-built-in-asp-components/' rel='bookmark' title='Using Built-In ASP Components'>Using Built-In ASP Components</a></li>
<li><a href='http://www.hotscripts.com/blog/automatically-hyperlink-urls-and-e-mail-addresses-in-asp-net/' rel='bookmark' title='Automatically Hyperlink URLs and E-Mail Addresses in ASP.NET Pages with C#'>Automatically Hyperlink URLs and E-Mail Addresses in ASP.NET Pages with C#</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><span><strong><span style="font-family: Verdana; ">What&#8217;s ADO?</span></strong><span style="font-family: Verdana; ">ADO (ActiveX Data Objects) is a collection of objects created by Microsoft that interact with databases. There&#8217;s the Connection Object, which connects us to our databases and the Recordset Object which allows us to retrieve data from our databases.</span></span></p>
<p><strong><span style="font-family: Verdana; ">Creating a Database</span></strong></p>
<p><span style="font-family: Verdana; ">Before we can do anything with a database, we must first create one. This sample uses Microsoft Access 2002.</span></p>
<p><span style="font-family: Verdana; ">1. Open Microsoft Access</span></p>
<p><span style="font-family: Verdana; ">2. On the right side of the screen, click on Blank Database</span></p>
<p align="left"><span style="font-family: Verdana; ">3. Save your database to your wroot folder of your personal web server.</span></p>
<p align="left"><span style="font-family: Verdana; ">4. You will be able to select from 3 different options: <em>Create table in design view</em>, <em>create table by using wizard</em> and <em>create table by entering data</em>. Select <em>create table in design view</em>.</span></p>
<p align="left"><span style="font-family: Verdana; ">5. Now once you have opened our newly created table, you will have the options to add data to it, so lets!</span></p>
<p align="left"><span style="font-family: Verdana; ">6. In <em>Field Name</em>, enter Name and in <em>Data Type</em>, select Memo. Memo allows us to enter text along with the text option, however the memo allows us to add a large number of characters unlike the text option.</span></p>
<p align="left"><span style="font-family: Verdana; ">7. Now close the table. Once you do this, it will ask you if you want to save changes to our table? Click <em>Yes</em>. You then will be prompted to enter a name for our new table with the default name being <em>table1</em>. Click <em>OK</em> to save our new table as <em>table1</em>. After this, you will be prompted one more time to see if you would like a <em>primary key</em> for our database. A <em>primary key</em> numbers each row of fields which can be very useful. The numbers will never be the same which strictly identifies each row. In this case, we don&#8217;t need one, so click <em>No</em>. We now have our very own table.</span></p>
<p align="left"><span style="font-family: Verdana; ">8. We can now close our database by exiting Microsoft Access.</span></p>
<p><strong><span style="font-family: Verdana; ">The Connection Object</span></strong></p>
<p><span style="font-family: Verdana; ">One of the most common task you will need to accomplish when working with databases is retrieving data from your database. In order to do this, we must first make a connection using the Connection Object and the following methods and properties: Mode, Provider, ConnectionString and Open.</span></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%" bgcolor="#dcdcdc" bordercolor="#000000">
<tbody>
<tr>
<td><span style="font-family: Courier New; ">&lt;!&#8211;#include virtual=&#8221;adovbs.inc&#8221; &#8211;&gt;</span></p>
<p><span style="font-family: Courier New; ">&lt;%</span></p>
<p><span style="font-family: Courier New; ">Dim DB, RS</span><br />
<span style="font-family: Courier New; ">Set DB = Server.CreateObject(&#8220;adoDB.connection&#8221;)</span><br />
<span style="font-family: Courier New; ">DB.Mode = adModeReadWrite</span><br />
<span style="font-family: Courier New; ">DB.Provider = &#8220;MICROSOFT.JET.OLEDB.4.0&#8243;</span><br />
<span style="font-family: Courier New; ">DB.ConnectionString = Server.MapPath(&#8220;db1.mdb&#8221;)</span><br />
<span style="font-family: Courier New; ">DB.Open</span></p>
<p><span style="font-family: Courier New; ">%&gt;</span></td>
</tr>
</tbody>
</table>
<p><span><span style="font-family: Verdana; "><span style="text-decoration: underline;"><strong>When using any of the examples below, remember to add the code above first!</strong></span></span></span></p>
<p><span style="font-family: Verdana; ">Now, the first line of code uses a </span><a href="http://www.codehungry.com/asptut/include.asp"><span style="font-family: Verdana; ">include file</span></a><span style="font-family: Verdana; "> named <em>adovbs.inc</em>. What&#8217;s this? The adovbs.inc is a large file of constants, which are variables except their values can&#8217;t be changed. This is used to make our jobs as an ASP programmer easier. For instance, in the <em>adovbs.inc</em> file, the constant adOpenKeyset = 1. So when we use adOpenKeyset in our cursor parameter, we are actually using 1 in our cursor parameter. Why is this? Because that&#8217;s the real value of our cursor parameter. Microsoft just made it easier for us, so instead of having to remember numbers, we just need to remember those constants. You will see this in action in our next example.</span></p>
<p><span style="font-family: Verdana; ">Don&#8217;t have the <em>adovbs.inc</em> file, </span><a href="http://www.codehungry.com/asptut/adovbs.zip"><span style="font-family: Verdana; ">download it here! </span></a><span style="font-family: Verdana; ">Remember to save this file in the root directory of your personal web server.</span></p>
<p><span style="font-family: Verdana; ">The 3rd line of code creates a instance of the Connection Object and names it <em>DB</em>. So now we have a variable named <em>DB </em>which is a copy of the Connection Object.</span></p>
<p><span style="font-family: Verdana; ">The 4th line of code uses the property mode of the Connection Object and sets it to read/write which not only allows us to read from the database, but the change or add to the database.</span></p>
<p><span style="font-family: Verdana; ">The 5th line of code uses the connectionstring property of the Connection Object which locates our database.</span></p>
<p><span style="font-family: Verdana; ">The final line of code uses the Open() method of the Connection Object to open the database.</span></p>
<p><span style="font-family: Verdana; ">So now we have access to our database but what good is that if we can&#8217;t read or write data to it. This is when the RecordSet Object comes into play.</span></p>
<p><strong><span style="font-family: Verdana; ">Adding Data Using the Recordset Object</span></strong></p>
<p><span style="font-family: Verdana; ">The Recordset Object allows us to read/write/update/delete data from our database. Since we have any empty database, let&#8217;s add data to our table named table1 using the following methods and properties: Open, AddNew, Update and Close.</span></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%" bgcolor="#dcdcdc" bordercolor="#000000">
<tbody>
<tr>
<td><span style="font-family: Courier New; ">&lt;%</span><br />
<span style="font-family: Courier New; ">Set RS = Server.CreateObject(&#8220;adoDB.recordset&#8221;)</span><br />
<span style="font-family: Courier New; ">RS.Open &#8220;table1&#8243;, DB, adOpenKeySet,adLockOptimistic,adCmdTable </span><br />
<span style="font-family: Courier New; ">RS.AddNew</span><br />
<span style="font-family: Courier New; ">RS(&#8220;Name&#8221;) = &#8220;Andrew&#8221;</span><br />
<span style="font-family: Courier New; ">RS.UpDate</span><br />
<span style="font-family: Courier New; ">RS.AddNew</span><br />
<span style="font-family: Courier New; ">RS(&#8220;name&#8221;) = &#8220;Jennifer&#8221;</span><br />
<span style="font-family: Courier New; ">RS.Update</span><br />
<span style="font-family: Courier New; ">RS.AddNew</span><br />
<span style="font-family: Courier New; ">RS(&#8220;name&#8221;) = &#8220;Kelly&#8221;</span><br />
<span style="font-family: Courier New; ">RS.Update </span></p>
<p><span style="font-family: Courier New; ">%&gt;</span></td>
</tr>
</tbody>
</table>
<p><span><span style="font-family: Verdana; ">The code above takes the names Andrew, Jennifer and Kelly and adds them to our database.</span></span></p>
<p><span style="font-family: Verdana; ">Line 2, like the previous example creates a instance of the Recordset Object and names it <em>RS</em>. So now we have a variable named <em>RS </em>which is a copy of the Recordset Object. </span></p>
<p><span style="font-family: Verdana; ">Line 3 opens our database using the following Recordset Object parameters: DB, adOpenStatic, adLockOptimistic, adCmdTable.</span></p>
<p><span style="font-family: Verdana;"><span><em>DB</em> is the <em>ActiveConnection</em> parameter. We need a connection to our database so we use our Connection Object.</span></span></p>
<p><span style="font-family: Verdana; ">AdOpenStatic constant is the <em>CurosorLocation </em>parameter. It describes what cursor type we would like to use. A cursor is used to navigate through records. Forward, backwards, etc. Also, some cursors are non-updateable so we must use a cursor that supports updating a database. The adOpenKeySet allows this.</span></p>
<p><span style="font-family: Verdana; ">AdLockOptimistic constant is the <em>LockType</em> parameter which allows us to add or update data to our database. With the AdLockOptimistic constant in the <em>LockType</em> parameter, the database only locks when the database is being updated. This way no one else can enter data until the data is finished updating. If you want to be on the safe side, you could use the AdLockPessimistic constant in the<em> LockType</em> parameter which locks the database as soon as the Update() method of the RecordSet Object is called.</span></p>
<p><span style="font-family: Verdana; ">AdCmdTable constant is the <em>Options</em> parameter which states how our source string (&#8220;table1&#8243;) should be interpreted. We use the AdCmdTable constant as our <em>Options</em> parameter because we only need to enter data to our table and in our source string, we only add our table name. If we used a source string like (&#8220;SELECT * FROM table1 WHERE NAME = &#8216;Andrew Schools&#8217; &#8220;), we would have to use the AdCmdText constant in the <em>Options</em> parameter because we actually have a string of SQL that needs to be interpreted. More on SQL (Structured Query Language) and using the AdCmdText in the <em>Options</em> parameter later. </span></p>
<p><strong><span style="font-family: Verdana; ">Retrieving Data Using the Recordset Object</span></strong></p>
<p><span style="font-family: Verdana; ">Now lets retrieve the data we just entered into our database.</span></p>
<p><span style="font-family: Verdana; ">The code below reads data from our database using the following properties and methods: Open, BOF (Beginning of File), EOF (End of File), MoveFirst and MoveNext.</span></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%" bgcolor="#dcdcdc" bordercolor="#000000">
<tbody>
<tr>
<td><span style="font-family: Courier New; ">&lt;%</span></p>
<p><span style="font-family: Courier New; ">Set RS = Server.CreateObject(&#8220;adoDB.recordset&#8221;)</span><br />
<span style="font-family: Courier New; ">RS.Open &#8220;table1&#8243;, DB, adOpenKeySet, adLockReadOnly, adCmdTable</span><br />
<span style="font-family: Courier New; ">If RS.BOF and RS.EOF Then</span><br />
<span style="font-family: Courier New; ">Response.Write &#8220;&lt;p align=&#8217;center&#8217;&gt;Sorry, no files!&lt;/p&gt;&#8221;</span><br />
<span style="font-family: Courier New; ">Else</span><br />
<span style="font-family: Courier New; ">RS.MoveFirst</span><br />
<span style="font-family: Courier New; ">While Not RS.EOF</span><br />
<span style="font-family: Courier New; ">Response.Write RS(&#8220;name&#8221;)&amp; &#8220;&lt;BR&gt;&#8221;</span><br />
<span style="font-family: Courier New; ">RS.MoveNext</span><br />
<span style="font-family: Courier New; ">wEnd</span><br />
<span style="font-family: Courier New; ">End If</span></p>
<p><span style="font-family: Courier New; ">%&gt;</span></td>
</tr>
</tbody>
</table>
<p><span><span style="font-family: Verdana; ">The first two lines of code is something we have already seen and talked about. The only thing different is we use a AdLockReadOnly constant instead of a AdLockOptimistic constant since we are not updating the database. Now you don&#8217;t have to do this, however it save resources since the database doesn&#8217;t have to keep track of when you are changing files in the database. </span></span></p>
<p><span style="font-family: Verdana; ">The 3rd line of code checks to see if the database is empty by using the BOF and EOF properties of the Recordset Object. If the following statement is true (no data in our database), then we tell the user by writing to the screen, <span style="text-decoration: underline;">Sorry, no files! </span>If the statement is false (there is data in our database), then we proceed down to line 6. Note that it&#8217;s good pratice to check to see if there isn&#8217;t any files. If you don&#8217;t and there is no files, you will get an ugly error message which states there isn&#8217;t any files.</span></p>
<p><span style="font-family: Verdana; ">Line 6 tells the cursor to move to the Beginning of the file just in case it isn&#8217;t there. We don&#8217;t want to skip any files&#8230;</span></p>
<p><span style="font-family: Verdana; ">Line 7 starts a While&#8230;Loop. It will loop until there is no more data in our database.</span></p>
<p><span style="font-family: Verdana; ">Line 8 writes our data to the screen.</span></p>
<p><span style="font-family: Verdana; ">Line 9 tells the cursor to move to the next file in our database. Without this line, we would have a infinitive loop because we would always display the first file in our database and our While&#8230;Loop would always be true and never end, thus looping for ever or until the script timed out. </span></p>
<p><span style="font-family: Verdana; ">Line 10 ends our loop.</span></p>
<p><span style="font-family: Verdana; ">Line 11 ends our If&#8230;EndIf statement.</span></p>
<p><span style="font-family: Verdana; ">Now since we are opening all of these objects, it&#8217;s good practice to close them once we are finished with them. This also saves precious server memory.</span></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%" bgcolor="#dcdcdc" bordercolor="#000000">
<tbody>
<tr>
<td><span style="font-family: Courier New; ">&lt;%</span></p>
<p><span style="font-family: Courier New; ">RS.Close</span></p>
<p><span style="font-family: Courier New; ">Set RS = Nothing</span></p>
<p><span style="font-family: Courier New; ">DB.Close</span></p>
<p><span style="font-family: Courier New; ">Set DB = Nothing</span></p>
<p><span style="font-family: Courier New; ">%&gt;</span></td>
</tr>
</tbody>
</table>
<p><span><strong><span style="font-family: Verdana; ">Deleting Data Using the Recordset Object</span></strong></span></p>
<p><span style="font-family: Verdana; ">There will come a time when you will need to delete data from your database and it&#8217;s real easy too. The code below will delete the name Kelly from the database.</span></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%" bgcolor="#dcdcdc" bordercolor="#000000">
<tbody>
<tr>
<td><span style="font-family: Courier New; ">&lt;%</span></p>
<p><span style="font-family: Courier New; ">Set RS = Server.CreateObject(&#8220;adoDB.recordset&#8221;)<br />
RS.Open &#8220;SELECT * FROM table1 WHERE name=&#8217;Kelly&#8217; &#8220;, DB, adOpenStatic, adLockOptimistic, adCmdText</span></p>
<p><span style="font-family: Courier New; ">If RS.BOF and RS.EOF Then</span></p>
<p><span style="font-family: Courier New; ">Response.Write &#8220;&lt;p align=&#8217;center&#8217;&gt;Sorry, no files!&lt;/p&gt;&#8221;</span></p>
<p><span style="font-family: Courier New; ">Else</span></p>
<p><span style="font-family: Courier New; ">RS.Delete</span></p>
<p><span style="font-family: Courier New; ">End If</span></p>
<p><span style="font-family: Courier New; ">RS.Close</span></p>
<p><span style="font-family: Courier New; ">Set RS = Nothing</span></p>
<p><span style="font-family: Courier New; ">DB.Close</span></p>
<p><span style="font-family: Courier New; ">Set DB = Nothing</span></p>
<p><span style="font-family: Courier New; ">%&gt;</span></td>
</tr>
</tbody>
</table>
<p><span><span style="font-family: Verdana; ">Line 2 opens the Recordset Object as shown in previous examples, however, the source string is different. It uses a SELECT statement of SQL which states: find all files with the name = Kelly. Note that the <em>Options</em> parameter is set to AdCmdText. </span></span></p>
<p><span style="font-family: Verdana; ">What&#8217;s with the * ? It means All fields. In this statement, you could replace the * with <em>name</em>, since we only have one field we can select from anyway, which is <em>name</em>. </span></p>
<p><span style="font-family: Verdana; ">Once we have found the file(s) with the name(s) = Kelly, line 6 deletes the first file using the Delete() method of the RecordSet Object. Why only the first file? If we wanted to delete all file(s) with the name(s) = Kelly, we would have to use a While&#8230;Loop.</span></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%" bgcolor="#dcdcdc" bordercolor="#000000">
<tbody>
<tr>
<td><span style="font-family: Courier New; ">&lt;%</span></p>
<p><span style="font-family: Courier New; ">Dim RS</span></p>
<p><span style="font-family: Courier New; ">Set RS = Server.CreateObject(&#8220;adoDB.recordset&#8221;)</span><br />
<span style="font-family: Courier New; ">RS.Open &#8220;SELECT * FROM table1 WHERE name=&#8217;Kelly&#8217; &#8220;, DB, adOpenStatic, adLockOptimistic, adCmdText</span></p>
<p><span style="font-family: Courier New; ">If RS.BOF and RS.EOF Then</span></p>
<p><span style="font-family: Courier New; ">Response.Write &#8220;&lt;p align=&#8217;center&#8217;&gt;Sorry, no files!&lt;/p&gt;&#8221;</span></p>
<p><span style="font-family: Courier New; ">Else</span></p>
<p><span style="font-family: Courier New; ">RS.MoveFirst</span></p>
<p><span style="font-family: Courier New; ">While Not RS.EOF</span></p>
<p><span style="font-family: Courier New; ">RS.Delete</span></p>
<p><span style="font-family: Courier New; ">RS.MoveNext</span></p>
<p><span style="font-family: Courier New; ">wEnd</span></p>
<p><span style="font-family: Courier New; ">End If</span></p>
<p><span style="font-family: Courier New; ">RS.Close</span></p>
<p><span style="font-family: Courier New; ">Set RS = Nothing</span></p>
<p><span style="font-family: Courier New; ">DB.Close</span></p>
<p><span style="font-family: Courier New; ">Set DB = Nothing</span></p>
<p><span style="font-family: Courier New; ">%&gt;</span></td>
</tr>
</tbody>
</table>
<p><span><strong><span style="font-family: Verdana; ">Updating Data Using the Recordset Object</span></strong></span></p>
<p><span style="font-family: Verdana; ">Updating data is another very important technique when working with databases and it&#8217;s almost like adding data to a database. Look at the code below: </span></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%" bgcolor="#dcdcdc" bordercolor="#000000">
<tbody>
<tr>
<td><span style="font-family: Courier New; ">&lt;%</span><br />
<span style="font-family: Courier New; ">Set RS = Server.CreateObject(&#8220;adoDB.recordset&#8221;)</span><br />
<span style="font-family: Courier New; ">RS.Open &#8220;SELECT * FROM table1 WHERE name=&#8217;Andrew&#8217; &#8220;, DB, adOpenKeySet,adLockOptimistic,adCmdText</span></p>
<p><span style="font-family: Courier New; ">If RS.BOF and RS.EOF Then</span></p>
<p><span style="font-family: Courier New; ">Response.Write &#8220;&lt;p align=&#8217;center&#8217;&gt;Sorry, no files!&lt;/p&gt;&#8221;</span></p>
<p><span style="font-family: Courier New; ">Else</span><br />
<span style="font-family: Courier New; ">RS(&#8220;Name&#8221;) = &#8220;Andrew loves ASP!&#8221;</span><br />
<span style="font-family: Courier New; ">RS.UpDate</span></p>
<p><span style="font-family: Courier New; ">End If</span></p>
<p><span style="font-family: Courier New; ">RS.Close</span></p>
<p><span style="font-family: Courier New; ">Set RS = Nothing</span></p>
<p><span style="font-family: Courier New; ">DB.Close</span></p>
<p><span style="font-family: Courier New; ">Set DB = Nothing</span><br />
<span style="font-family: Courier New; ">%&gt;</span></td>
</tr>
</tbody>
</table>
<p><span><span style="font-family: Verdana; ">The only thing that&#8217;s different from adding data then updating data is the lack of the AddNew() method of the Recordset Object and of course we use a SELECT statement of SQL to obtain the file we wish to update. Note that if you had more than one file with the name = Andrew, you would have to use a While&#8230;Loop like the previous example to update every file.</span></span></p>
<p><span style="font-family: Verdana; ">If you are copy and pasting these examples, remember to use the Connection Object first. For instance, if you wanted to use the code above, you would have to do the following:</span></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%" bgcolor="#dcdcdc" bordercolor="#000000">
<tbody>
<tr>
<td><span style="font-family: Courier New; ">&lt;!&#8211;#include virtual=&#8221;adovbs.inc&#8221; &#8211;&gt;</span><br />
<span style="font-family: Courier New; ">&lt;%</span><br />
<span style="font-family: Courier New; ">Dim DB, RS</span><br />
<span style="font-family: Courier New; ">Set DB = Server.CreateObject(&#8220;adodb.connection&#8221;)</span><br />
<span style="font-family: Courier New; ">DB.Mode = adModeReadWrite</span><br />
<span style="font-family: Courier New; ">DB.Provider = &#8220;MICROSOFT.JET.OLEDB.4.0&#8243;</span><br />
<span style="font-family: Courier New; ">DB.ConnectionString = Server.MapPath(&#8220;db1.mdb&#8221;)</span><br />
<span style="font-family: Courier New; ">DB.Open</span><br />
<span style="font-family: Courier New; ">Set RS = Server.CreateObject(&#8220;adoDB.recordset&#8221;)</span><br />
<span style="font-family: Courier New; ">RS.Open &#8220;SELECT * FROM table1 WHERE name=&#8217;Andrew&#8217; &#8220;, DB, adOpenKeySet,adLockOptimistic,adCmdText</span></p>
<p><span style="font-family: Courier New; ">If RS.BOF and RS.EOF Then</span></p>
<p><span style="font-family: Courier New; ">Response.Write &#8220;&lt;p align=&#8217;center&#8217;&gt;Sorry, no files!&lt;/p&gt;&#8221;</span></p>
<p><span style="font-family: Courier New; ">Else</span><br />
<span style="font-family: Courier New; ">RS(&#8220;Name&#8221;) = &#8220;Andrew loves ASP!&#8221;</span></p>
<p><span style="font-family: Courier New; ">RS.UpDate</span></p>
<p><span style="font-family: Courier New; ">End If</span></p>
<p><span style="font-family: Courier New; ">RS.Close</span></p>
<p><span style="font-family: Courier New; ">Set RS = Nothing</span></p>
<p><span style="font-family: Courier New; ">DB.Close</span></p>
<p><span style="font-family: Courier New; ">Set DB = Nothing</span><br />
<span style="font-family: Courier New; ">%&gt;</span></td>
</tr>
</tbody>
</table>
<p><span><span style="font-family: Verdana; ">There are many different ways to read/add/update/delete data to a database including complex SQL statements then what this tutorial discusses. For more information on SQL, visit </span><a href="http://www.w3schools.com/sql/default.asp"><span style="font-family: Verdana; ">W3Schools.com</span></a></span></p>
<div class="hotlist"><strong>Author: </strong>Andrew Schools</div>
<p>Post from: <a href="http://www.hotscripts.com/blog">Hot Scripts Blog</a><br/><br/><a href="http://www.hotscripts.com/blog/simple-asp-database-techniques/">Simple ASP database techniques</a></p>
<p>Related posts:<ol>
<li><a href='http://www.hotscripts.com/blog/using-the-asp-querystring/' rel='bookmark' title='Using the ASP QueryString'>Using the ASP QueryString</a></li>
<li><a href='http://www.hotscripts.com/blog/using-built-in-asp-components/' rel='bookmark' title='Using Built-In ASP Components'>Using Built-In ASP Components</a></li>
<li><a href='http://www.hotscripts.com/blog/automatically-hyperlink-urls-and-e-mail-addresses-in-asp-net/' rel='bookmark' title='Automatically Hyperlink URLs and E-Mail Addresses in ASP.NET Pages with C#'>Automatically Hyperlink URLs and E-Mail Addresses in ASP.NET Pages with C#</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.hotscripts.com/blog/simple-asp-database-techniques/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Including a file in a ASP page</title>
		<link>http://www.hotscripts.com/blog/including-a-file-in-a-asp-page/</link>
		<comments>http://www.hotscripts.com/blog/including-a-file-in-a-asp-page/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 21:05:10 +0000</pubDate>
		<dc:creator>DEVpapers</dc:creator>
				<category><![CDATA[ASP & ASP.NET]]></category>

		<guid isPermaLink="false">http://www.hotscripts.com/blog/?p=743</guid>
		<description><![CDATA[Learn the fundamental of using include files in your asp pages.<p>Post from: <a href="http://www.hotscripts.com/blog">Hot Scripts Blog</a><br/><br/><a href="http://www.hotscripts.com/blog/including-a-file-in-a-asp-page/">Including a file in a ASP page</a></p>

Related posts:<ol>
<li><a href='http://www.hotscripts.com/blog/using-the-asp-querystring/' rel='bookmark' title='Using the ASP QueryString'>Using the ASP QueryString</a></li>
<li><a href='http://www.hotscripts.com/blog/using-built-in-asp-components/' rel='bookmark' title='Using Built-In ASP Components'>Using Built-In ASP Components</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div><span><span style="font-family: Verdana; "><strong>Using includes</strong> </span><span style="font-family: Verdana; ">What’s a include file? An include file is just an ASP page that’s called from another page:</span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">&lt;!&#8211;#include file=”myincludefile.asp” &#8211;&gt; </span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">You would include the code above in your ASP page, like this: </span></p>
<p><span style="font-family: Verdana; "><span style="color: #191970;">page1.asp</span></span></p>
<p></span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Verdana; "><span style="font-family: Courier New; color: #ff4500;">&lt;HTML&gt;&lt;HEAD&gt;<br />
&lt;TITLE&gt;MY PAGE&lt;/TITLE&gt;<br />
&lt;/HEAD&gt;&lt;BODY&gt;<br />
&lt;!&#8211;#include file=”myincludefile.asp” &#8211;&gt;<br />
&lt;/BODY&gt;&lt;/HTML&gt;</span> </span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">Make sure both of your pages are of an .asp extension.</span></p>
<p><span style="font-family: Verdana; ">Your include file could include anything:</span></p>
<p><span style="font-family: Verdana; color: #191970; ">myincludefile.asp</span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Verdana; "><span style="font-family: Courier New; color: #ff4500;">&lt;%<br />
Response.Write “Welcome! Today’s date is “ &amp; Now<br />
%&gt;</span> </span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">This would turn your first page into this:</span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">&lt;HTML&gt;&lt;HEAD&gt;<br />
&lt;TITLE&gt;MY PAGE&lt;/TITLE&gt;<br />
&lt;/HEAD&gt;&lt;BODY&gt;<br />
&lt;%<br />
Response.Write “Welcome! Today’s date is “ &amp; Now<br />
%&gt;<br />
&lt;/BODY&gt;&lt;/HTML&gt; </span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">So why use an include file? Why not just add the following code into your page directly? In this instance, it would be easier. However, what if you had a large web site that had copyright information on every page and you needed to change it. Well, if you didn&#8217;t use a include file, you would have to change every page, which could be time consuming. If you used an include file, you would only have to change that file. Instantly, you can see the benefits of using a include file.</span></p>
<p><span style="font-family: Verdana; ">Now you don’t just have to have an .asp extension for your include file. You can have an .htm, .html, .inc and among many more extensions.</span></p>
<p><span style="font-family: Verdana; ">*Remember, if you use a .htm, .html or .inc extension, people can view the source code. To be safe, stick with an .asp extension. </span></p>
<p><span style="font-family: Verdana; ">What if you have a file located somewhere other than the directory your in? You can use the following code:</span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">&lt;!&#8211;#include virtual=”myincludefile.asp” &#8211;&gt; </span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">As you can see, instead of &lt;!&#8211;#include file, we are now using &lt;!&#8211;#include virtual. This is allowing us to start in our root directory. This piece of code above will include the file myincludefile.asp that’s located in your root directory. If your include file is in a folder named includes, your code would look like this: </span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">&lt;!&#8211;#include virtual=”includes/myincludefile.asp” &#8211;&gt; </span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; "><strong>Using variables in your include file</strong></span></p>
<p><span style="font-family: Verdana; ">Say you need the same format on top of every page in your web site; however, the title needs to be different. You could do the following:</span></p>
<p><span style="font-family: Verdana; color: #191970; ">page1.asp</span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Verdana; "><span style="font-family: Courier New; color: #ff4500;">title = “My Index Page”<br />
&lt;!&#8211;#include file=”includes/myincludefile.asp” &#8211;&gt;<br />
&lt;p align=”center”&gt;Welcome to my web site&lt;/p&gt;<br />
&lt;/BODY&gt;&lt;/HTML&gt;</span> </span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; color: #191970; ">myincludefile.asp</span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">&lt;HTML&gt;&lt;HEAD&gt;<br />
&lt;TITLE&gt;&lt;%= title %&gt;&lt;/TITLE&gt;<br />
&lt;/HEAD&gt;&lt;BODY&gt; </span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">This would turn your first page into this:</span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">title = “My Index Page”<br />
&lt;HTML&gt;&lt;HEAD&gt;<br />
&lt;TITLE&gt;&lt;%= title %&gt;&lt;/TITLE&gt;<br />
&lt;/HEAD&gt;&lt;BODY&gt;<br />
&lt;p align=”center”&gt;Welcome to my web site&lt;/p&gt;<br />
&lt;/BODY&gt;&lt;/HTML&gt; </span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">All this does is create a variable named title which you would want in every page. The include file then is added to page1 and pulls that variable and uses it for it&#8217;s title.</span></p>
<p><span style="font-family: Verdana; ">So as you can see, using includes can be very useful in certain circumstances.</span></div>
<div class="hotlist"><strong>Author: </strong>Andrew Schools</div>
<p>Post from: <a href="http://www.hotscripts.com/blog">Hot Scripts Blog</a><br/><br/><a href="http://www.hotscripts.com/blog/including-a-file-in-a-asp-page/">Including a file in a ASP page</a></p>
<p>Related posts:<ol>
<li><a href='http://www.hotscripts.com/blog/using-the-asp-querystring/' rel='bookmark' title='Using the ASP QueryString'>Using the ASP QueryString</a></li>
<li><a href='http://www.hotscripts.com/blog/using-built-in-asp-components/' rel='bookmark' title='Using Built-In ASP Components'>Using Built-In ASP Components</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.hotscripts.com/blog/including-a-file-in-a-asp-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Built-In ASP Components</title>
		<link>http://www.hotscripts.com/blog/using-built-in-asp-components/</link>
		<comments>http://www.hotscripts.com/blog/using-built-in-asp-components/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 21:02:46 +0000</pubDate>
		<dc:creator>DEVpapers</dc:creator>
				<category><![CDATA[ASP & ASP.NET]]></category>

		<guid isPermaLink="false">http://www.hotscripts.com/blog/?p=751</guid>
		<description><![CDATA[In this tutorial, we will be working with three of Microsoft's built-in ASP components. The Ad Rotator, Content Linker and the Browser Capabilities Component.<p>Post from: <a href="http://www.hotscripts.com/blog">Hot Scripts Blog</a><br/><br/><a href="http://www.hotscripts.com/blog/using-built-in-asp-components/">Using Built-In ASP Components</a></p>

Related posts:<ol>
<li><a href='http://www.hotscripts.com/blog/using-the-asp-querystring/' rel='bookmark' title='Using the ASP QueryString'>Using the ASP QueryString</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><span style="font-family: Verdana; "><strong>What&#8217;s a Component?</strong></span></p>
<p><span style="font-family: Verdana; ">A component is just a piece of code someone wrote so you wouldn&#8217;t have to re-invent the wheel. Just like when you create a subroutine, you use the same code over and over again instead of having to re-write virtually the same piece of code somewhere else. </span></p>
<p><span style="font-family: Verdana; "><strong>Why use Components?</strong></span></p>
<p><span style="font-family: Verdana; ">Components make programming easier. You don&#8217;t have to use components, but you will be creating much more work for yourself then needed. </span></p>
<p><span style="font-family: Verdana; "><strong>Using the Ad Rotator Component</strong></span></p>
<p><span style="font-family: Verdana; ">What&#8217;s the Ad Rotator Component? Just what is says. It rotates your ads for you. In order to use this component, you will need three things:</span></p>
<p><span style="font-family: Verdana; "> 1. The rotator schedule file (text file)</span></p>
<p>2. ASP page that redirects the user</p>
<p>3. The ASP page that houses the banners</p>
<p><span style="font-family: Verdana; ">First, let&#8217;s create the schedule file. A schedule file will have the following format:</span></p>
<p><span style="font-family: Verdana; "><strong>schedulefile.txt</strong></span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">redirect.asp</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">width</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">height</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">border</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">*</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">ImageURL</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">HomePageURL</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">AltText</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Weight</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Image2URL</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">HomePage2URL</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">AltText</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Weight</span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">The first 4 lines of code apply to all banners.</span></p>
<p><span style="font-family: Verdana; ">The first line of code tells the browser what file to go to once the banner it clicked. This could be a redirecting script that logs all hits out from your site.</span></p>
<p><span style="font-family: Verdana; ">The second and third lines of code affects the width and height of the banners while the fourth line of code sets a border width around the image.</span></p>
<p><span style="font-family: Verdana; ">The fifth line of code (*) indicates where the first section of the file stops and the second starts.</span></p>
<p><span style="font-family: Verdana; ">ImageURL is the path of your banner</span></p>
<p><span style="font-family: Verdana; ">HomePageURL is the URL that the user is taken to when they click on the banner. This URL is passed to the redirect URL for processing. If there is no site to be taken to, then a hyphen (-) should be used.</span></p>
<p><span style="font-family: Verdana; ">AltText is used to display text instead of an image if the image doesn&#8217;t load.</span></p>
<p><span style="font-family: Verdana; ">Weight is a number between 0 and 10,000 that indicates how many times the ad should be display compared to all other banners in the schedule file. For instance, if you had two banners in the schedule file with the weight of 1o and one banner with the weight of 20, the banner with weight 2o would be shown more times then the first two banners.</span></p>
<p><span style="font-family: Verdana; ">Here&#8217;s a live example:</span></p>
<p><span style="font-family: Verdana; "><strong>schedulefile.txt</strong></span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">REDIRECT out.asp </span><span style="font-family: Courier New; color: #ff4500; ">WIDTH 468</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">HEIGHT 60</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">BORDER 1</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">*</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">ex_pro.gif</span></p>
<p><a href="http://www.batpros.com/"><span style="font-family: Courier New; color: #ff4500; ">http://www.batpros.com</span></a></p>
<p><span style="font-family: Courier New; color: #ff4500; ">BatPros</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">20</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">banner0291.jpg</span></p>
<p><a href="http://www.wavenom.com/"><span style="font-family: Courier New; color: #ff4500; ">http://www.wavenom.com</span></a></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Wavenom</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">20</span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">Now on to the redirection page. This page will redirect the user to the appropriate site when a banner is clicked.</span></p>
<p><span style="font-family: Verdana; ">The Ad Rotator creates a querystring for us to use. When a user clicks on a banner, we will get a querystring with the following information:</span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">redirect.asp?url=homepageURL&amp;image=imageURL </span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">So if we want to redirect the user to the appropriate site, we would use the following line of code:</span></p>
<p><span style="font-family: Verdana; "><strong>redirect.asp</strong></span><span style="font-family: Verdana; "><strong> </strong></span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">&lt;% Response.Redirect Request.QueryString(&#8220;URL&#8221;)%&gt; </span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">The last file we need to create is the ASP page(s) that will display the banners.</span></p>
<p><span style="font-family: Verdana; "><strong>index.asp</strong></span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">&lt;%</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Dim objAdRotator</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Set objAdRotator = Server.CreateObject(&#8220;MSWC.AdRotator&#8221;)</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">%&gt;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">&lt;HTML&gt;&lt;HEAD&gt;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">&lt;TITLE&gt;My Site &lt;/TITLE&gt;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">&lt;/HEAD&gt;&lt;BODY&gt;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Please support this site!&lt;BR&gt;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">&lt;%= objAdRotator.GetAdvertisement(&#8220;schedulefile.txt&#8221;) %&gt;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Set objAdRotator = Nothing</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">&lt;BR&gt;Welcome to my site!!!</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">&lt;/BODY&gt;&lt;/HTML&gt;</span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">This page displays our banners. If you refresh this page several times, you will see that a different image is displayed. Sometimes, especially with fewer banners to display, the same banner will appear. </span></p>
<p><span style="font-family: Verdana; ">The first couple of lines of code creates an instance of the Ad Rotator object and gives it the name of objAdRotator.</span></p>
<p><span style="font-family: Verdana; ">To display our image, we use the following code like shown above: </span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">&lt;%= objAdRotator.GetAdvertisement(&#8220;schedulefile.txt&#8221;) %&gt; </span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">As you can see, our object uses the method GetAdvertisement() with the property of the name of our schedule file.</span></p>
<p><strong><span style="font-family: Verdana; ">Using the Content Linker Component</span></strong></p>
<p><span style="font-family: Verdana; ">What&#8217;s the Content Linker Component? It&#8217;s used to manage large, frequently updated sites which have tutorials, etc. To use the Content Linker Component, you will need a text file to create a linking list file.</span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">webpageURL   description   comment </span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">Each line can contain up to three tab-separated items, like above.</span></p>
<p><span style="font-family: Verdana; ">webpageURL is the page you want to link to. Use file names only, URLS that begin with Http:// won&#8217;t work.</span></p>
<p><span style="font-family: Verdana; ">description is a description of the page.</span></p>
<p><span style="font-family: Verdana; ">comment is used as a comment for programmers.</span></p>
<p><span style="font-family: Verdana; ">So let&#8217;s create a linking list file:</span></p>
<p><span style="font-family: Verdana; "><strong>linkinglistfile.txt</strong></span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">tut_fun.asp   Functions   my functions page </span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">tut_com.asp   Components   my components page</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">tut_inc.asp   Includes   my includes page </span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">Now we need to create our ASP page that will display our pages from our linking list file.</span></p>
<p><span style="font-family: Verdana; "><strong>index.asp</strong></span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">&lt;HTML&gt;&lt;HEAD&gt;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">&lt;TITLE&gt;MY TUTORIALS SECTION&lt;/TITLE&gt;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">&lt;/HEAD&gt;&lt;BODY&gt;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Starting ASP&lt;BR&gt;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Welcome to my tutorial selection for programming in asp! Start by clicking on one of the links below&#8230;&lt;br&gt;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">&lt;%</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Dim objLinker</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Set ObjLinker = Server.CreateObject(&#8220;MSWC.NextLink&#8221;)</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Response.Write &#8220;&lt;P&gt;&lt;A HREF=&#8217;&#8221; &amp; objLinker.GetPreviousURL(&#8220;linkinglistfile.txt&#8221;) &amp; &#8220;&#8216;&gt;&#8221; &amp; objLinker.GetPreviousDescription(&#8220;linkinglistfile.txt&#8221;) &amp; &#8220;&lt;/A&gt;&#8221; &amp; &#8221; &#8221; &amp; &#8220;&lt;A HREF=&#8217;&#8221; &amp; objLinker.GetNextURL(&#8220;linkinglistfile.txt&#8221;) &amp; &#8220;&#8216;&gt;&#8221; &amp; objLinker.GetNextDescription(&#8220;linkinglistfile.txt&#8221;) &amp; &#8220;&lt;/A&gt;&lt;/P&gt;&#8221;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Set objLinker = Nothing</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">%&gt;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">&lt;/BODY&gt;&lt;/HTML&gt;</span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">The only code we need to review is the following:</span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">&lt;%</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Dim objLinker</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Set ObjLinker = Server.CreateObject(&#8220;MSWC.NextLink&#8221;)</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Response.Write &#8220;&lt;P&gt;&lt;A HREF=&#8217;&#8221; &amp; objLinker.GetPreviousURL(&#8220;linkinglistfile.txt&#8221;) &amp; &#8220;&#8216;&gt;&#8221; &amp; objLinker.GetPreviousDescription(&#8220;linkinglistfile.txt&#8221;) &amp; &#8220;&lt;/A&gt;&#8221; &amp; &#8221; &#8221; &amp; &#8220;&lt;A HREF=&#8217;&#8221; &amp; objLinker.GetNextURL(&#8220;linkinglistfile.txt&#8221;) &amp; &#8220;&#8216;&gt;&#8221; &amp; objLinker.GetNextDescription(&#8220;linkinglistfile.txt&#8221;) &amp; &#8220;&lt;/A&gt;&lt;/P&gt;&#8221;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Set objLinker = Nothing</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">%&gt;</span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">The code above creates a previous and next link for us. In order for us to accomplish this, we must use the methods GetPreviousURL(), GetPreviousDescription(), GetNextURL() and GetNextDescription() of the NextLink object. They are self explanatory. </span></p>
<p><span style="font-family: Verdana; ">Remember to include the code above in all the pages you plan on linking. For instance, tut_fun.asp, tut_com.asp and tut_inc.asp would all have the code above at the bottom of their pages, however, different content.</span></p>
<p><span style="font-family: Verdana; ">There are also other methods the NextLink object takes:</span></p>
<p><span style="font-family: Verdana; ">GetListCount(listfile) &#8211; returns the number of pages the linking list file contains</span></p>
<p><span style="font-family: Verdana; ">GetListIndex(listfile) &#8211; returns the index number of the current page in linking list file</span></p>
<p><span style="font-family: Verdana; ">GetNthURL(listfile, num) &#8211; returns the URL of the num page in the linking list file</span></p>
<p><span style="font-family: Verdana; ">GetNthDescription(listfile, num) &#8211; returns the description of the num page in the linking list file</span></p>
<p><span style="font-family: Verdana; ">Using the GetNthURL() and GetNthDescription() methods, we can make a table of contents:</span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">&lt;HTML&gt;&lt;HEAD&gt;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">&lt;TITLE&gt;MY TUTORIALS SECTION&lt;/TITLE&gt;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">&lt;/HEAD&gt;&lt;BODY&gt;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Table of Contents&lt;BR&gt;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">&lt;%</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Dim objLinker, icount, ipage</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Set ObjLinker = Server.CreateObject(&#8220;MSWC.NextLink&#8221;)</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">ipages = objLinker.GetListCount(&#8220;linkinglistfile.txt&#8221;)</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">For icount = 1 to ipages</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Response.Write &#8220;&lt;A HREF=&#8217;&#8221; &amp; objLinker.GetNthURL(&#8220;linkinglistfile.txt&#8221;, icount) &amp; &#8220;&#8216;&gt;&#8221; &amp; objLinker.GetNthDescription(&#8220;linkinglistfile.txt&#8221;, icount) &amp; &#8220;&lt;/A&gt;&lt;BR&gt;&#8221;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Next</span></p>
<p>%&gt;</td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">The code above will give us a table of contents using a For&#8230;Next Loop with a GetNthURL() and GetNthDescription() method.</span></p>
<p><span style="font-family: Verdana; "><strong>Using The Browser Capabilities Component</strong></span></p>
<p><span style="font-family: Verdana; ">What&#8217;s the Browser Capabilities Component? It&#8217;s used to figure out what type of browser and different properties the users browser supports.</span></p>
<p><span style="font-family: Verdana; ">To see if a users browser supports JavaScript, use the following code:</span></p>
<table border="0" cellspacing="2" cellpadding="2" width="100%" bgcolor="#dcdcdc">
<tbody>
<tr>
<td><span style="font-family: Courier New; color: #ff4500; ">&lt;%</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Dim objBrowserCom</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Set objBrowserCom = Server.CreateObject(&#8220;MSWC.BrowserType&#8221;)</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">If objBrowserCom.JavaScript Then</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Response.Write &#8220;This browser supports JavaScript!&#8221;</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">End If</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">Set objBrowserCom = Nothing</span></p>
<p><span style="font-family: Courier New; color: #ff4500; ">%&gt;</span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">The Browser Capabilities Component also supports these methods:</span></p>
<p><span style="font-family: Verdana; ">Browser Name &#8211; (.Browser) Returns a string</span></p>
<p><span style="font-family: Verdana; ">Browser Version &#8211; (.Version) Returns a string </span></p>
<p><span style="font-family: Verdana; ">Check to see if the browser supports frames &#8211; (.Frames) Returns a boolean value of true or false</span></p>
<p><span style="font-family: Verdana; ">Check to see if the browser supports tables &#8211; (.tables) Returns a boolean value of true or false</span></p>
<p><span style="font-family: Verdana; ">Check to see if the browser supports background sound &#8211; (.BackGroundSounds) Returns a boolean value of true or false</span></p>
<p><span style="font-family: Verdana; ">Check to see if the browser supports VBScript &#8211; (.VBScript) Returns a boolean value of true or false</span></p>
<div class="hotlist"><strong>Author: </strong>Andrew Schools</div>
<p>Post from: <a href="http://www.hotscripts.com/blog">Hot Scripts Blog</a><br/><br/><a href="http://www.hotscripts.com/blog/using-built-in-asp-components/">Using Built-In ASP Components</a></p>
<p>Related posts:<ol>
<li><a href='http://www.hotscripts.com/blog/using-the-asp-querystring/' rel='bookmark' title='Using the ASP QueryString'>Using the ASP QueryString</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.hotscripts.com/blog/using-built-in-asp-components/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the ASP QueryString</title>
		<link>http://www.hotscripts.com/blog/using-the-asp-querystring/</link>
		<comments>http://www.hotscripts.com/blog/using-the-asp-querystring/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 19:26:00 +0000</pubDate>
		<dc:creator>DEVpapers</dc:creator>
				<category><![CDATA[ASP & ASP.NET]]></category>

		<guid isPermaLink="false">http://www.hotscripts.com/blog/?p=755</guid>
		<description><![CDATA[In this tutorial, we will discuss the benefits of using the QueryString and how to use the QueryString.<p>Post from: <a href="http://www.hotscripts.com/blog">Hot Scripts Blog</a><br/><br/><a href="http://www.hotscripts.com/blog/using-the-asp-querystring/">Using the ASP QueryString</a></p>

No related posts.]]></description>
			<content:encoded><![CDATA[<div><span><strong><span style="font-family: Verdana; ">What&#8217;s the QueryString</span></strong><span style="font-family: Verdana; ">When you visit a site, you may sometimes see a url like this:</span></p>
<table border="1" cellspacing="0" cellpadding="0" width="75%" bgcolor="#cccccc" bordercolor="#000000">
<tbody>
<tr>
<td><span style="font-family: Courier New; ">http://www.codehungry.com/index.asp?id=12345&amp;name=codehungry</span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">What&#8217;s all this? Well, before the ?, it&#8217;s just a plain old url, however, everything after the ? is considered the QueryString. </span></p>
<p><span style="font-family: Verdana; ">So what&#8217;s so special about the QueryString? It&#8217;s very powerful and of course, very useful. For instance, if you wanted to get a certain file from a database, you would give the user a link to click: </span></p>
<p><strong><span style="font-family: Verdana; ">content.asp</span></strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="75%" bgcolor="#cccccc" bordercolor="#000000">
<tbody>
<tr>
<td><span style="font-family: Verdana; "><span style="font-family: Courier New;">&lt;a href=&#8221;http://www.codehungry.com/index.asp?id=8&#8243;&gt;File 8&lt;/a&gt;</span> </span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">Once the user clicked on the link, they would of course be directed to http://www.codehungry.com/index.asp?id=8. To get the querystring id, you would do the following: </span></p>
<table border="1" cellspacing="0" cellpadding="0" width="75%" bgcolor="#cccccc" bordercolor="#000000">
<tbody>
<tr>
<td><span style="font-family: Courier New; ">Request.QueryString(&#8220;id&#8221;)</span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">If you wanted to write the value of the querystring id, you would do the following:</span></p>
<table border="1" cellspacing="0" cellpadding="0" width="75%" bgcolor="#cccccc" bordercolor="#000000">
<tbody>
<tr>
<td><span style="font-family: Courier New; ">Response.Write Request.QueryString(&#8220;id&#8221;)</span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">Which would give you a value of 8.</span></p>
<p><span style="font-family: Verdana; ">Now in order to make the QueryString useful, we need to create a script that will read through the database looking for the id that&#8217;s = 8. If you do not understand this, then you should read the tutorial </span><a href="http://www.devpapers.com/article/181"><span style="font-family: Verdana; ">Simple Database Techniques</span></a><span style="font-family: Verdana; ">. </span></p>
<p><strong><span style="font-family: Verdana; ">index.asp?id=8</span></strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="75%" bgcolor="#cccccc" bordercolor="#000000">
<tbody>
<tr>
<td><span style="font-family: Courier New; ">&lt;!&#8211;#include virtual=&#8221;adovbs.inc&#8221; &#8211;&gt;</span><br />
<span style="font-family: Courier New; ">&lt;%</span><br />
<span style="font-family: Courier New; ">Dim DB, RS</span><br />
<span style="font-family: Courier New; ">Set DB = Server.CreateObject(&#8220;adodb.connection&#8221;)</span><br />
<span style="font-family: Courier New; ">DB.Mode = adModeReadWrite</span><br />
<span style="font-family: Courier New; ">DB.Provider = &#8220;MICROSOFT.JET.OLEDB.4.0&#8243;</span><br />
<span style="font-family: Courier New; ">DB.ConnectionString = Server.MapPath(&#8220;db1.mdb&#8221;)</span><br />
<span style="font-family: Courier New; ">DB.Open</span><br />
<span style="font-family: Courier New; ">Set RS = Server.CreateObject(&#8220;adoDB.recordset&#8221;)</span><br />
<span style="font-family: Courier New; ">RS.Open &#8220;SELECT * FROM table1 WHERE id= &#8221; &amp; Request.QueryString(&#8220;id&#8221;), DB, adOpenKeySet,adLockOptimistic,adCmdText</span></p>
<p><span style="font-family: Courier New; ">If RS.BOF and RS.EOF Then</span></p>
<p><span style="font-family: Courier New; ">Response.Write &#8220;&lt;p align=&#8217;center&#8217;&gt;Sorry, no files!&lt;/p&gt;&#8221;</span></p>
<p><span style="font-family: Courier New; ">Else</span><br />
<span style="font-family: Courier New; ">Response.Write RS(&#8220;file_description&#8221;)</span></p>
<p><span style="font-family: Courier New; ">End If</span></p>
<p><span style="font-family: Courier New; ">RS.Close</span></p>
<p><span style="font-family: Courier New; ">Set RS = Nothing</span></p>
<p><span style="font-family: Courier New; ">DB.Close</span></p>
<p><span style="font-family: Courier New; ">Set DB = Nothing</span><br />
<span style="font-family: Courier New; ">%&gt;</span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">The following code will obtain a file from the database with it&#8217;s id = 8. </span></p>
<p><span style="font-family: Verdana; ">So, if you wanted to create an content page, create a list of links like so:</span></p>
<p><strong><span style="font-family: Verdana; ">content.asp</span></strong></p>
<table border="1" cellspacing="0" cellpadding="0" width="75%" bgcolor="#cccccc" bordercolor="#000000">
<tbody>
<tr>
<td><span style="font-family: Courier New; ">&lt;a href=&#8221;http://www.codehungry.com/index.asp?id=1&#8243;&gt;File 1 &lt;/a&gt; &lt;BR&gt;</span></p>
<p><span style="font-family: Courier New; ">&lt;a href=&#8221;http://www.codehungry.com/index.asp?id=2&#8243;&gt;File 2 &lt;/a&gt; &lt;BR&gt;</span></p>
<p><span style="font-family: Courier New; ">&lt;a href=&#8221;http://www.codehungry.com/index.asp?id=3&#8243;&gt;File 3 &lt;/a&gt; &lt;BR&gt;</span></p>
<p><span style="font-family: Courier New; ">&lt;a href=&#8221;http://www.codehungry.com/index.asp?id=4&#8243;&gt;File 4 &lt;/a&gt; &lt;BR&gt;</span></p>
<p><span style="font-family: Courier New; ">&lt;a href=&#8221;http://www.codehungry.com/index.asp?id=5&#8243;&gt;File 5 &lt;/a&gt; &lt;BR&gt;</span></p>
<p><span style="font-family: Courier New; ">&lt;a href=&#8221;http://www.codehungry.com/index.asp?id=6&#8243;&gt;File 6 &lt;/a&gt; &lt;BR&gt;</span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">When the user clicks on one of the links, they will be taken to index.asp, which is a processing page that processes the QueryString. It then takes the value of the QueryString id and finds the correct file in the database.</span></p>
<p><strong><span style="font-family: Verdana; ">Using more than one QueryString variable </span></strong></p>
<p><span style="font-family: Verdana; ">What if you want to use more than one QueryString variable in your QueryString? You need to separate them by a &amp;. For instance:</span></p>
<table border="1" cellspacing="0" cellpadding="0" width="75%" bgcolor="#cccccc" bordercolor="#000000">
<tbody>
<tr>
<td><span style="font-family: Courier New; ">http://www.codehungry.com/index.asp?id=8&amp;name=codehungry</span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">To retrieve these values, do the following:</span></p>
<table border="1" cellspacing="0" cellpadding="0" width="75%" bgcolor="#cccccc" bordercolor="#000000">
<tbody>
<tr>
<td><span style="font-family: Courier New; ">Request.QueryString(&#8220;id&#8221;)</span></p>
<p><span style="font-family: Courier New; ">Request.QueryString(&#8220;name&#8221;)</span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">When using spaces in your QueryString or special characters like the &#8216; character, you must use the URLEncode method of the Server object:</span></p>
<table border="1" cellspacing="0" cellpadding="0" width="75%" bgcolor="#cccccc" bordercolor="#000000">
<tbody>
<tr>
<td><span style="font-family: Courier New; ">text = &#8220;Andrew&#8217;s WebSite!&#8221;</span></p>
<p><span style="font-family: Verdana; "><span style="font-family: Courier New;">Response.Write &#8220;&lt;a href=&#8217;index.asp?id=&#8221; &amp; Server.UrlEncode(text) &amp; &#8220;&#8216;&gt;Click Here!&lt;/a&gt;&#8221;</span> </span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">You should get the following QueryString:</span></p>
<table border="1" cellspacing="0" cellpadding="0" width="75%" bgcolor="#cccccc" bordercolor="#000000">
<tbody>
<tr>
<td><span style="font-family: Courier New; ">index.asp?id=Andrew%27s+WebSite%21</span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: Verdana; ">To retrieve this sentence from the QueryString, you would do what you always have:</span></p>
<table border="1" cellspacing="0" cellpadding="0" width="75%" bgcolor="#cccccc" bordercolor="#000000">
<tbody>
<tr>
<td><span style="font-family: Courier New; ">Request.QueryString(&#8220;id&#8221;)</span></td>
</tr>
</tbody>
</table>
<p></span></div>
<div class="hotlist"><strong>Author: </strong>Andrew Schools</div>
<p>Post from: <a href="http://www.hotscripts.com/blog">Hot Scripts Blog</a><br/><br/><a href="http://www.hotscripts.com/blog/using-the-asp-querystring/">Using the ASP QueryString</a></p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.hotscripts.com/blog/using-the-asp-querystring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

