<?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>GuShH&#039;s Development Blog</title>
	<atom:link href="http://gushh.net/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://gushh.net/blog</link>
	<description>This blog is about software, electronics and game development.</description>
	<lastBuildDate>Fri, 27 Aug 2010 01:38:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Why I hate helpdesks!</title>
		<link>http://gushh.net/blog/2010/08/26/why-i-hate-helpdesks/</link>
		<comments>http://gushh.net/blog/2010/08/26/why-i-hate-helpdesks/#comments</comments>
		<pubDate>Fri, 27 Aug 2010 01:38:43 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Have you tried turning it off and on again?]]></category>
		<category><![CDATA[helpdesk]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[it crowd]]></category>
		<category><![CDATA[monkey]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=493</guid>
		<description><![CDATA[What is it with help-desks and canned answers?, sometimes I feel like punching right through the screen, reaching the monkey on the other side and smacking it &#8217;til it can&#8217;t tap the keyboard no more! Joking aside, what really annoys me is the fact that they treat me like an idiot, I could be talking [...]]]></description>
			<content:encoded><![CDATA[<!-- AdSense Now! V1.95 -->
<!-- Post[count: 3] -->
<div class="adsense adsense-leadin" style="text-align:center;margin: 12px;"><script type="text/javascript"><!--
google_ad_client = "pub-2462949361920197";
/* 468x15, created 4/6/10 */
google_ad_slot = "8315313616";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p>What is it with help-desks and canned answers?, sometimes I feel like punching right through the screen, reaching the monkey on the other side and smacking it &#8217;til it can&#8217;t tap the keyboard no more!</p>
<p>Joking aside, what really annoys me is the fact that they treat me like an idiot, I could be talking about specific details of whatever, and they&#8217;ll answer with more or less &#8220;Have you tried turning it off and on again?&#8221; &#8212; It&#8217;s outrageous!</p>
<p>Companies should really add a field tn the registration form that reads &#8220;I&#8217;m a: *select* Dummy, Somehow of a geek, Professional nerd&#8221; &#8212; And route their tickets accordingly!</p>
<p>Oh well&#8230; I should probably ease off the monologues and rants for today.</p>
<p>Now, If only I could find that sysadmin&#8217;s email address&#8230; That would make me a happy guy, I&#8217;ll even forget about the monkeys!</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://gushh.net/blog/2008/07/06/server-migration-completed/" rel="bookmark" class="crp_title">Server migration completed.</a></li><li><a href="http://gushh.net/blog/2010/08/17/harte-hanks-and-ti-backordered-msp430/" rel="bookmark" class="crp_title">Harte Hanks and TI &#8211; Backordered MSP430</a></li><li><a href="http://gushh.net/blog/2008/07/11/hosting-nightmares-and-deja-vu/" rel="bookmark" class="crp_title">Hosting nightmares and deja vu.</a></li><li><a href="http://gushh.net/blog/2010/07/18/validate-email-address/" rel="bookmark" class="crp_title">Validate email address</a></li><li><a href="http://gushh.net/blog/2010/07/17/msp430-backordered/" rel="bookmark" class="crp_title">MSP430 &#8211; backordered</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/2010/08/26/why-i-hate-helpdesks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Harte Hanks and TI &#8211; Backordered MSP430</title>
		<link>http://gushh.net/blog/2010/08/17/harte-hanks-and-ti-backordered-msp430/</link>
		<comments>http://gushh.net/blog/2010/08/17/harte-hanks-and-ti-backordered-msp430/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 16:52:52 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[Backorder]]></category>
		<category><![CDATA[Harte Hanks]]></category>
		<category><![CDATA[Launchpad]]></category>
		<category><![CDATA[MSP430]]></category>
		<category><![CDATA[pickit]]></category>
		<category><![CDATA[Texas Instruments]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=471</guid>
		<description><![CDATA[These Harte Hanks, or should I call them &#8220;Hard at Wanks&#8221; guys are shameless. I (and a few others) could not contact them or get any information whatsoever on the shipping status for the MSP430 Launchpad. To contact TI you must spend at least half an hour filling out a massive form just to never [...]]]></description>
			<content:encoded><![CDATA[<p>These Harte Hanks, or should I call them &#8220;Hard at Wanks&#8221; guys are shameless. I (and a few others) could not contact them or get any information whatsoever on the shipping status for the MSP430 Launchpad. </p>
<p>To contact TI you must spend at least half an hour filling out a massive form just to never be contacted by them&#8230; </p>
<p>It&#8217;s rather obvious that the whole MSP430 Launchpad was an afterthought and that TI has no infrastructure for small companies and/or buyers; they play with the big fish and they don&#8217;t know how to handle regular human beings. Heck, they&#8217;re paying some clowns to deal with them and look at what happened!<span id="more-471"></span></p>
<p>Even their wiki is a total mess, I&#8217;ve no idea who is in charge of the project but it&#8217;s clear they don&#8217;t know what they&#8217;re doing.</p>
<p>I thought this being such a massive company, they would at least have the manpower to come up with a brilliant marketing strategy, backed up by proper material and support. Turns out they can&#8217;t. They&#8217;re good at putting together calculators, but that&#8217;s about it.</p>
<p>Furthermore I always feel discriminated by these companies; If you&#8217;re outside the US they&#8217;ll treat you as a lesser person. Someone with the time and cash should teach these guys a lesson or two on how to handle their customers. The worst part is that Harte Hanks sell themselves as marketing specialists&#8230;</p>
<blockquote><p>Marketing is used to identify the customer, to keep the customer, and to satisfy the customer.</p></blockquote>
<p>Anyone can tell an orange from an apple&#8230; They clearly failed at every other aspect.</p>
<p>Oh well, I&#8217;ll just forget about it and get a pickit or arduino, at least the companies behind those products do care about their customers.</p>
<p>RIP TI, you&#8217;re dead to quite a few people.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://gushh.net/blog/2010/07/17/msp430-backordered/" rel="bookmark" class="crp_title">MSP430 &#8211; backordered</a></li><li><a href="http://gushh.net/blog/2008/07/06/server-migration-completed/" rel="bookmark" class="crp_title">Server migration completed.</a></li><li><a href="http://gushh.net/blog/2010/07/01/bluetooth-dongle/" rel="bookmark" class="crp_title">What can you buy with $1.85?</a></li><li><a href="http://gushh.net/blog/2007/09/10/have-you-heard-japan-trying-to-remake-the-internet/" rel="bookmark" class="crp_title">Have you heard? &#8211; Japan &#8220;trying&#8221; to remake the Internet&#8230;</a></li><li><a href="http://gushh.net/blog/2010/08/26/why-i-hate-helpdesks/" rel="bookmark" class="crp_title">Why I hate helpdesks!</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/2010/08/17/harte-hanks-and-ti-backordered-msp430/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AutoComplete Library</title>
		<link>http://gushh.net/blog/2010/08/14/autocomplete-library/</link>
		<comments>http://gushh.net/blog/2010/08/14/autocomplete-library/#comments</comments>
		<pubDate>Sun, 15 Aug 2010 02:24:32 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[PureBasic]]></category>
		<category><![CDATA[ajax autocomplete]]></category>
		<category><![CDATA[auto complete]]></category>
		<category><![CDATA[autocomplete]]></category>
		<category><![CDATA[autocomplete library]]></category>
		<category><![CDATA[autocompletion]]></category>
		<category><![CDATA[lib autocomplete]]></category>
		<category><![CDATA[pb autocomplete]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=452</guid>
		<description><![CDATA[This nifty library will allow you to incorporate auto-completion in your latest game/software project without much hassle. It supports the use of a dictionary with both load and save routines, it keeps track of hits and allows to filter the suggestion using a &#8220;headroom&#8221; parameter. The &#8220;algorithm&#8221; used to populate the suggestion list is down [...]]]></description>
			<content:encoded><![CDATA[<p>This nifty library will allow you to incorporate auto-completion in your latest game/software project without much hassle. It supports the use of a dictionary with both load and save routines, it keeps track of hits and allows to filter the suggestion using a &#8220;headroom&#8221; parameter.</p>
<p>The &#8220;algorithm&#8221; used to populate the suggestion list is down to the bare basics, reason being I wanted to keep the library small and simple. In fact some &#8220;methods&#8221; were not implemented for this very same reason. But please feel free to write a helper lib and I&#8217;ll happily add a link towards it.</p>
<p>The 4.50 source:</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">Structure</span> AUTOCOMPLETE_ENTRY	<span style="color: #ff0000; font-style: italic;">; This represents each word in the dictionary</span>
	word.s			<span style="color: #ff0000; font-style: italic;">; The word</span>
	length.i		<span style="color: #ff0000; font-style: italic;">; The length of the word (cached for speed)</span>
	hits.i			<span style="color: #ff0000; font-style: italic;">; Amount of hits this word received (see GetSuggestions for more information on this)</span>
<span style="color: #000066; font-weight: bold;">EndStructure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Structure</span> AUTOCOMPLETE
	DictionaryFileName.s			<span style="color: #ff0000; font-style: italic;">; Filename for the dictionary, optional.</span>
	last_input.s				<span style="color: #ff0000; font-style: italic;">; Handy last input helper</span>
	last_suggestion.s			<span style="color: #ff0000; font-style: italic;">; Likewise but it holds the last &quot;best&quot; suggestion, in case you don't want to go through the list.</span>
	List dictionary.AUTOCOMPLETE_ENTRY<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>	<span style="color: #ff0000; font-style: italic;">; Holds complete words or sentences, it is our database.</span>
	List suggestion.AUTOCOMPLETE_ENTRY<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>	<span style="color: #ff0000; font-style: italic;">; This list will be populated with results once GetSuggestion is called.</span>
<span style="color: #000066; font-weight: bold;">EndStructure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Declare</span>.i AutoComplete_LoadDictionary<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.AUTOCOMPLETE, DictionaryFile.s <span style="color: #000066;">&#41;</span>
<span style="color: #000066; font-weight: bold;">Declare</span>.i AutoComplete_SaveDictionary<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.AUTOCOMPLETE, DictionaryFile.s <span style="color: #000066;">=</span> <span style="color: #009900;">&quot;&quot;</span> <span style="color: #000066;">&#41;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i AutoComplete_Create<span style="color: #000066;">&#40;</span> DictionaryFile.s <span style="color: #000066;">=</span> <span style="color: #009900;">&quot;&quot;</span> <span style="color: #000066;">&#41;</span>
	<span style="color: #ff0000; font-style: italic;">; Creates an instance of the AutoComplete library.</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Define</span>.AUTOCOMPLETE <span style="color: #000066;">*</span>this <span style="color: #000066;">=</span> <span style="color: #0000ff;">AllocateMemory</span><span style="color: #000066;">&#40;</span> <span style="color: #0000ff;">SizeOf</span><span style="color: #000066;">&#40;</span> AUTOCOMPLETE <span style="color: #000066;">&#41;</span> <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this
&nbsp;
		InitializeStructure<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this, AUTOCOMPLETE <span style="color: #000066;">&#41;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">If</span> DictionaryFile
			AutoComplete_LoadDictionary<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this, DictionaryFile <span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #000066;">*</span>this	
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i AutoComplete_Destroy<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.AUTOCOMPLETE, AutoSave.i <span style="color: #000066;">=</span> #False <span style="color: #000066;">&#41;</span>
	<span style="color: #ff0000; font-style: italic;">; Destroys an instance of the AutoComplete library.</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this
&nbsp;
		<span style="color: #000066; font-weight: bold;">If</span> AutoSave
			AutoComplete_SaveDictionary<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this <span style="color: #000066;">&#41;</span>	
		<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
		ClearStructure<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this, AUTOCOMPLETE <span style="color: #000066;">&#41;</span>
		<span style="color: #0000ff;">FreeMemory</span><span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.s AutoComplete_GetSuggestion<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.AUTOCOMPLETE, PartialInput.s, Headroom.i <span style="color: #000066;">=</span> <span style="color: #CC0000;">4</span> <span style="color: #000066;">&#41;</span>
	<span style="color: #ff0000; font-style: italic;">; Generates a suggestion list based on input string.</span>
	<span style="color: #ff0000; font-style: italic;">; The Headroom variable limits how bigger a suggestion can be, compared to the input length.</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this
&nbsp;
		<span style="color: #000066; font-weight: bold;">Define</span>.i PartialFindLength	<span style="color: #000066;">=</span> <span style="color: #CC0000;">99999</span>
		<span style="color: #000066; font-weight: bold;">Define</span>.i PartialInputLength 	<span style="color: #000066;">=</span> <span style="color: #0000ff;">Len</span><span style="color: #000066;">&#40;</span> PartialInput <span style="color: #000066;">&#41;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">If</span> PartialInputLength <span style="color: #000066;">&gt;</span> <span style="color: #CC0000;">0</span>
&nbsp;
			<span style="color: #0000ff;">ClearList</span><span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>suggestion<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">&#41;</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">ForEach</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>dictionary<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
&nbsp;
				<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">Left</span><span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>dictionary<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">\</span>word, PartialInputLength <span style="color: #000066;">&#41;</span> <span style="color: #000066;">=</span> PartialInput
&nbsp;
					<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>dictionary<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">\</span>word <span style="color: #000066;">=</span> PartialInput
						<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>dictionary<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">\</span>hits <span style="color: #000066;">+</span> <span style="color: #CC0000;">1</span>
					<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
					<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>dictionary<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">\</span>length <span style="color: #000066;">&lt;</span> PartialFindLength <span style="color: #000066;">+</span> Headroom
&nbsp;
						PartialFindLength <span style="color: #000066;">=</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>dictionary<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">\</span>length
&nbsp;
						<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">AddElement</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>suggestion<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">&#41;</span>
							<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>suggestion<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span> 	<span style="color: #000066;">=</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>dictionary<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
							<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>last_suggestion 	<span style="color: #000066;">=</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>suggestion<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">\</span>word
						<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
					<span style="color: #000066; font-weight: bold;">EndIf</span>
				<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">Next</span>
&nbsp;
			<span style="color: #0000ff;">SortStructuredList</span><span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>suggestion<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>,  #PB_Sort_Integer, <span style="color: #0000ff;">OffsetOf</span><span style="color: #000066;">&#40;</span> AUTOCOMPLETE_ENTRY<span style="color: #000066;">\</span>hits <span style="color: #000066;">&#41;</span>, #PB_Sort_Descending <span style="color: #000066;">&#41;</span>
			<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>last_suggestion
&nbsp;
		<span style="color: #000066; font-weight: bold;">EndIf</span>
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i AutoComplete_AddWord<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.AUTOCOMPLETE, Word.s, Hits.i <span style="color: #000066;">=</span> <span style="color: #CC0000;">0</span> <span style="color: #000066;">&#41;</span>
	<span style="color: #ff0000; font-style: italic;">; Adds a word to the dictionary.</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this
&nbsp;
		<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">AddElement</span><span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>dictionary<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">&#41;</span>
			<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>dictionary<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">\</span>word 	<span style="color: #000066;">=</span> Word
			<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>dictionary<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">\</span>length 	<span style="color: #000066;">=</span> <span style="color: #0000ff;">Len</span><span style="color: #000066;">&#40;</span>Word<span style="color: #000066;">&#41;</span>
			<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>dictionary<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">\</span>hits 	<span style="color: #000066;">=</span> Hits
		<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> #True
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i AutoComplete_ClearHits<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.AUTOCOMPLETE <span style="color: #000066;">&#41;</span>
	<span style="color: #ff0000; font-style: italic;">; Clears all word hits from the dictionary.</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this
&nbsp;
		<span style="color: #000066; font-weight: bold;">ForEach</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>dictionary<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
			<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>dictionary<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">\</span>hits <span style="color: #000066;">=</span> <span style="color: #CC0000;">0</span>
		<span style="color: #000066; font-weight: bold;">Next</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> #True
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i AutoComplete_LoadDictionary<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.AUTOCOMPLETE, DictionaryFile.s <span style="color: #000066;">&#41;</span>
	<span style="color: #ff0000; font-style: italic;">; Loads a dictionary from a file.</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this
		<span style="color: #000066; font-weight: bold;">If</span> DictionaryFile
&nbsp;
			<span style="color: #000066; font-weight: bold;">Define</span>.s sInput, sOutput
			<span style="color: #000066; font-weight: bold;">Define</span>.i Hits <span style="color: #000066;">=</span> <span style="color: #CC0000;">0</span>
			<span style="color: #000066; font-weight: bold;">Define</span>.i fp <span style="color: #000066;">=</span> <span style="color: #0000ff;">ReadFile</span><span style="color: #000066;">&#40;</span> #PB_Any, DictionaryFile <span style="color: #000066;">&#41;</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">IsFile</span><span style="color: #000066;">&#40;</span> fp <span style="color: #000066;">&#41;</span>
&nbsp;
				<span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>DictionaryFileName <span style="color: #000066;">=</span> DictionaryFile
&nbsp;
				<span style="color: #000066; font-weight: bold;">While</span> <span style="color: #000066; font-weight: bold;">Not</span> <span style="color: #0000ff;">Eof</span><span style="color: #000066;">&#40;</span> fp <span style="color: #000066;">&#41;</span>
&nbsp;
					sInput <span style="color: #000066;">=</span> <span style="color: #0000ff;">ReadString</span><span style="color: #000066;">&#40;</span> fp <span style="color: #000066;">&#41;</span>
&nbsp;
					<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">FindString</span><span style="color: #000066;">&#40;</span> sInput, <span style="color: #009900;">&quot;,&quot;</span>, <span style="color: #CC0000;">1</span> <span style="color: #000066;">&#41;</span> <span style="color: #ff0000; font-style: italic;">; If there's a comma in the line, then it means we have to load the hits.</span>
&nbsp;
						sOutput <span style="color: #000066;">=</span> <span style="color: #0000ff;">StringField</span><span style="color: #000066;">&#40;</span> sInput, <span style="color: #CC0000;">1</span>, <span style="color: #009900;">&quot;,&quot;</span> <span style="color: #000066;">&#41;</span>
						Hits 	<span style="color: #000066;">=</span> <span style="color: #0000ff;">Val</span><span style="color: #000066;">&#40;</span> <span style="color: #0000ff;">StringField</span><span style="color: #000066;">&#40;</span> sInput, <span style="color: #CC0000;">2</span>, <span style="color: #009900;">&quot;,&quot;</span> <span style="color: #000066;">&#41;</span> <span style="color: #000066;">&#41;</span>
&nbsp;
					<span style="color: #000066; font-weight: bold;">Else</span> <span style="color: #ff0000; font-style: italic;">; Otherwise no hits are present in the dictionary file, assume 0.</span>
&nbsp;
						sOutput <span style="color: #000066;">=</span> sInput
						Hits	<span style="color: #000066;">=</span> <span style="color: #CC0000;">0</span>
&nbsp;
					<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
					AutoComplete_AddWord<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this, sOutput, Hits <span style="color: #000066;">&#41;</span>
				<span style="color: #000066; font-weight: bold;">Wend</span>
&nbsp;
				<span style="color: #0000ff;">CloseFile</span><span style="color: #000066;">&#40;</span> fp <span style="color: #000066;">&#41;</span>	
			<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">EndIf</span>
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i AutoComplete_SaveDictionary<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this.AUTOCOMPLETE, DictionaryFile.s <span style="color: #000066;">=</span> <span style="color: #009900;">&quot;&quot;</span> <span style="color: #000066;">&#41;</span>
	<span style="color: #ff0000; font-style: italic;">; Saves the dictionary to a file.</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>this
&nbsp;
		<span style="color: #000066; font-weight: bold;">If</span> DictionaryFile <span style="color: #000066;">=</span> <span style="color: #009900;">&quot;&quot;</span>
			DictionaryFile <span style="color: #000066;">=</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>DictionaryFileName	
		<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">If</span> DictionaryFile
&nbsp;
			<span style="color: #000066; font-weight: bold;">Define</span>.s sInput, sOutput
			<span style="color: #000066; font-weight: bold;">Define</span>.i fp <span style="color: #000066;">=</span> <span style="color: #0000ff;">CreateFile</span><span style="color: #000066;">&#40;</span> #PB_Any, DictionaryFile <span style="color: #000066;">&#41;</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">IsFile</span><span style="color: #000066;">&#40;</span> fp <span style="color: #000066;">&#41;</span>
&nbsp;
				<span style="color: #000066; font-weight: bold;">ForEach</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>dictionary<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
&nbsp;
					sOutput <span style="color: #000066;">=</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>dictionary<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">\</span>word
					sOutput <span style="color: #000066;">+</span> <span style="color: #009900;">&quot;,&quot;</span> <span style="color: #000066;">+</span> <span style="color: #0000ff;">Str</span><span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>this<span style="color: #000066;">\</span>dictionary<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">\</span>hits <span style="color: #000066;">&#41;</span>
					<span style="color: #0000ff;">WriteStringN</span><span style="color: #000066;">&#40;</span> fp, sOutput <span style="color: #000066;">&#41;</span>
&nbsp;
				<span style="color: #000066; font-weight: bold;">Next</span>
&nbsp;
				<span style="color: #0000ff;">CloseFile</span><span style="color: #000066;">&#40;</span>fp<span style="color: #000066;">&#41;</span>	
			<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">EndIf</span>
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span></pre></div></div>

<p>And a quick example:</p>
<p>Notice: The example requires a dictionary, you may download a sample one based on english words by clicking <a href="http://gushh.net/dev/?file=pb/english.txt" target="_blank">here</a>.</p>
</pre>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">Define</span>.AUTOCOMPLETE <span style="color: #000066;">*</span>auto <span style="color: #000066;">=</span> AutoComplete_Create<span style="color: #000066;">&#40;</span> <span style="color: #009900;">&quot;english.txt&quot;</span> <span style="color: #000066;">&#41;</span> <span style="color: #ff0000; font-style: italic;">; load this dictionary for future auto completion assistance.</span>
<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000066;">*</span>auto
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">OpenConsole</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
		<span style="color: #0000ff;">PrintN</span><span style="color: #000066;">&#40;</span><span style="color: #009900;">&quot; Type part of a word and press enter to view the suggestions&quot;</span> <span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">Repeat</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">Define</span>.s <span style="color: #000fff;">in</span> <span style="color: #000066;">=</span> <span style="color: #0000ff;">Input</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
			<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #000fff;">in</span>
&nbsp;
				<span style="color: #000066; font-weight: bold;">If</span> AutoComplete_GetSuggestion<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>auto, <span style="color: #000fff;">in</span>, <span style="color: #CC0000;">2</span> <span style="color: #000066;">&#41;</span>
					<span style="color: #000066; font-weight: bold;">ForEach</span> <span style="color: #000066;">*</span>auto<span style="color: #000066;">\</span>suggestion<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
						<span style="color: #0000ff;">PrintN</span><span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>auto<span style="color: #000066;">\</span>suggestion<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">\</span>word <span style="color: #000066;">+</span> <span style="color: #009900;">&quot; - &quot;</span> <span style="color: #000066;">+</span> <span style="color: #0000ff;">Str</span><span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>auto<span style="color: #000066;">\</span>suggestion<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">\</span>hits <span style="color: #000066;">&#41;</span> <span style="color: #000066;">&#41;</span>
					<span style="color: #000066; font-weight: bold;">Next</span>
					<span style="color: #0000ff;">PrintN</span><span style="color: #000066;">&#40;</span><span style="color: #009900;">&quot;&quot;</span><span style="color: #000066;">&#41;</span>
				<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
			<span style="color: #0000ff;">Delay</span><span style="color: #000066;">&#40;</span><span style="color: #CC0000;">100</span><span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">Until</span> <span style="color: #0000ff;">Inkey</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">=</span> <span style="color: #0000ff;">Chr</span><span style="color: #000066;">&#40;</span><span style="color: #CC0000;">27</span><span style="color: #000066;">&#41;</span> <span style="color: #000066; font-weight: bold;">Or</span> <span style="color: #000fff;">in</span> <span style="color: #000066;">=</span> <span style="color: #009900;">&quot;exit&quot;</span>
&nbsp;
		<span style="color: #0000ff;">CloseConsole</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
	AutoComplete_Destroy<span style="color: #000066;">&#40;</span> <span style="color: #000066;">*</span>auto, #True <span style="color: #000066;">&#41;</span> <span style="color: #ff0000; font-style: italic;">; Because we loaded a dictionary, if we pass True as the second parameter, the dictionary will be saved before the instance is destroyed.</span>
<span style="color: #000066; font-weight: bold;">EndIf</span></pre></div></div>

<p>Another good point about this library is that it's 100% cross-platform, so you're not depending on the OS to auto-complete your fields and like I said before, you could easily implement it in your game, etc. A bad point is that it includes no error handling at the moment.</p>
<p>That's it for now, you can download the entire source <a href="http://gushh.net/dev/?file=pb/AutoComplete.pb" target="_blank">here</a>. And a sample dictionary <a href="http://gushh.net/dev/?raw=1&#038;file=pb/english.txt" target="_blank">here</a>.</p>
<p>Cheers!</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://gushh.net/blog/2010/04/06/filetomemory-memorytofile/" rel="bookmark" class="crp_title">FileToMemory &#8211; MemoryToFile</a></li><li><a href="http://gushh.net/blog/2009/08/28/structuring-libraries-basic-design-tips/" rel="bookmark" class="crp_title">Structuring libraries, basic design tips.</a></li><li><a href="http://gushh.net/blog/2009/08/05/timelapse-lib/" rel="bookmark" class="crp_title">TimeLapse lib</a></li><li><a href="http://gushh.net/blog/2010/07/18/validate-email-address/" rel="bookmark" class="crp_title">Validate email address</a></li><li><a href="http://gushh.net/blog/2009/08/06/animation-lib/" rel="bookmark" class="crp_title">Animation lib</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/2010/08/14/autocomplete-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WuLine (Antialiased lines)</title>
		<link>http://gushh.net/blog/2010/08/02/wuline-antialiased-lines/</link>
		<comments>http://gushh.net/blog/2010/08/02/wuline-antialiased-lines/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 17:36:34 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[PureBasic]]></category>
		<category><![CDATA[AA Lines]]></category>
		<category><![CDATA[jagged edges]]></category>
		<category><![CDATA[PB AA LINE]]></category>
		<category><![CDATA[Purebasic antialiasing]]></category>
		<category><![CDATA[Wu Lines]]></category>
		<category><![CDATA[Xiaolin Wu]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=432</guid>
		<description><![CDATA[This is a simple implementation of Xiaolin Wu&#8217;s line algorithm It doesn&#8217;t support colors or blending at all, but it should be a good starting point for anyone willing to implement proper AA lines in PB. The code: EnableExplicit &#160; Procedure.f trunc&#40;X.f&#41; ProcedureReturn Int&#40;X&#41; EndProcedure &#160; Procedure.f frac&#40;X.f&#41; ProcedureReturn &#40;X - trunc&#40;X&#41;&#41; EndProcedure &#160; Procedure.f [...]]]></description>
			<content:encoded><![CDATA[<p>This is a simple implementation of <a href="http://en.wikipedia.org/wiki/Xiaolin_Wu's_line_algorithm" target="_blank">Xiaolin Wu&#8217;s line algorithm</a> It doesn&#8217;t support colors or blending at all, but it should be a good starting point for anyone willing to implement proper AA lines in PB.</p>
<p>The code:</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">EnableExplicit</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.f  trunc<span style="color: #000066;">&#40;</span>X.f<span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #0000ff;">Int</span><span style="color: #000066;">&#40;</span>X<span style="color: #000066;">&#41;</span>
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.f frac<span style="color: #000066;">&#40;</span>X.f<span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #000066;">&#40;</span>X <span style="color: #000066;">-</span> trunc<span style="color: #000066;">&#40;</span>X<span style="color: #000066;">&#41;</span><span style="color: #000066;">&#41;</span>
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.f invfrac<span style="color: #000066;">&#40;</span>X.f<span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #000066;">&#40;</span><span style="color: #CC0000;">1.0</span> <span style="color: #000066;">-</span> frac<span style="color: #000066;">&#40;</span>X<span style="color: #000066;">&#41;</span><span style="color: #000066;">&#41;</span>
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i DrawPixel<span style="color: #000066;">&#40;</span> x.i, y.i, color.i <span style="color: #000066;">&#41;</span>
	<span style="color: #0000ff;">Plot</span><span style="color: #000066;">&#40;</span> x, y, <span style="color: #0000ff;">RGB</span><span style="color: #000066;">&#40;</span>color, color, color<span style="color: #000066;">&#41;</span> <span style="color: #000066;">&#41;</span> <span style="color: #ff0000; font-style: italic;">; you would need to perform bound checking in here, or use your own plotting routine...</span>
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span> WuLine<span style="color: #000066;">&#40;</span> x1.f, y1.f, x2.f, y2.f<span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Define</span>.i MaxPixelValue <span style="color: #000066;">=</span> <span style="color: #CC0000;">255</span>
	<span style="color: #000066; font-weight: bold;">Define</span>.f grad, xd, yd, length, xm, ym, xgap, ygap, xend, yend, xf, yf, brightness1, brightness2
	<span style="color: #000066; font-weight: bold;">Define</span>.i x, y, ix1, ix2, iy1, iy2
	<span style="color: #000066; font-weight: bold;">Define</span>.b c1, c2
&nbsp;
	xd <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>x2<span style="color: #000066;">-</span>x1<span style="color: #000066;">&#41;</span>
	yd <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>y2<span style="color: #000066;">-</span>y1<span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">Abs</span><span style="color: #000066;">&#40;</span>xd<span style="color: #000066;">&#41;</span> <span style="color: #000066;">&gt;</span> <span style="color: #0000ff;">Abs</span><span style="color: #000066;">&#40;</span>yd<span style="color: #000066;">&#41;</span> <span style="color: #ff0000; font-style: italic;">;-------------------- Horizontal --------------------</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">If</span> x1 <span style="color: #000066;">&gt;</span> x2
			<span style="color: #000066; font-weight: bold;">Swap</span> x1, x2
			<span style="color: #000066; font-weight: bold;">Swap</span> y1, y2
			xd <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>x2<span style="color: #000066;">-</span>x1<span style="color: #000066;">&#41;</span>
			yd <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>y2<span style="color: #000066;">-</span>y1<span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
		grad <span style="color: #000066;">=</span> yd<span style="color: #000066;">/</span>xd
&nbsp;
		xend <span style="color: #000066;">=</span> trunc<span style="color: #000066;">&#40;</span>x1<span style="color: #000066;">+</span><span style="color: #CC0000;">0.5</span><span style="color: #000066;">&#41;</span>
		yend <span style="color: #000066;">=</span> y1 <span style="color: #000066;">+</span> grad<span style="color: #000066;">*</span><span style="color: #000066;">&#40;</span>xend<span style="color: #000066;">-</span>x1<span style="color: #000066;">&#41;</span>
		xgap <span style="color: #000066;">=</span> invfrac<span style="color: #000066;">&#40;</span>x1<span style="color: #000066;">+</span><span style="color: #CC0000;">0.5</span><span style="color: #000066;">&#41;</span>
		ix1  <span style="color: #000066;">=</span> <span style="color: #0000ff;">Int</span><span style="color: #000066;">&#40;</span>xend<span style="color: #000066;">&#41;</span>
		iy1  <span style="color: #000066;">=</span> <span style="color: #0000ff;">Int</span><span style="color: #000066;">&#40;</span>yend<span style="color: #000066;">&#41;</span>
&nbsp;
		brightness1 <span style="color: #000066;">=</span> invfrac<span style="color: #000066;">&#40;</span>yend<span style="color: #000066;">&#41;</span> <span style="color: #000066;">*</span> xgap
		brightness2 <span style="color: #000066;">=</span>    frac<span style="color: #000066;">&#40;</span>yend<span style="color: #000066;">&#41;</span> <span style="color: #000066;">*</span> xgap
&nbsp;
		c1 <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>brightness1 <span style="color: #000066;">*</span> MaxPixelValue<span style="color: #000066;">&#41;</span>
		c2 <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>brightness2 <span style="color: #000066;">*</span> MaxPixelValue<span style="color: #000066;">&#41;</span>
&nbsp;
		DrawPixel<span style="color: #000066;">&#40;</span>ix1,iy1, c1<span style="color: #000066;">&#41;</span>
		DrawPixel<span style="color: #000066;">&#40;</span>ix1,iy1<span style="color: #000066;">+</span><span style="color: #CC0000;">1</span>, c2<span style="color: #000066;">&#41;</span>
&nbsp;
		yf <span style="color: #000066;">=</span> yend<span style="color: #000066;">+</span>grad
&nbsp;
		xend <span style="color: #000066;">=</span> trunc<span style="color: #000066;">&#40;</span>x2<span style="color: #000066;">+</span><span style="color: #CC0000;">0.5</span><span style="color: #000066;">&#41;</span>
		yend <span style="color: #000066;">=</span> y2 <span style="color: #000066;">+</span> grad<span style="color: #000066;">*</span><span style="color: #000066;">&#40;</span>xend<span style="color: #000066;">-</span>x2<span style="color: #000066;">&#41;</span>
&nbsp;
		xgap <span style="color: #000066;">=</span> invfrac<span style="color: #000066;">&#40;</span>x2<span style="color: #000066;">-</span><span style="color: #CC0000;">0.5</span><span style="color: #000066;">&#41;</span>
&nbsp;
		ix2  <span style="color: #000066;">=</span> <span style="color: #0000ff;">Int</span><span style="color: #000066;">&#40;</span>xend<span style="color: #000066;">&#41;</span>
		iy2  <span style="color: #000066;">=</span> <span style="color: #0000ff;">Int</span><span style="color: #000066;">&#40;</span>yend<span style="color: #000066;">&#41;</span>
&nbsp;
		brightness1 <span style="color: #000066;">=</span> invfrac<span style="color: #000066;">&#40;</span>yend<span style="color: #000066;">&#41;</span> <span style="color: #000066;">*</span> xgap
		brightness2 <span style="color: #000066;">=</span>    frac<span style="color: #000066;">&#40;</span>yend<span style="color: #000066;">&#41;</span> <span style="color: #000066;">*</span> xgap
&nbsp;
		c1 <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>brightness1 <span style="color: #000066;">*</span> MaxPixelValue<span style="color: #000066;">&#41;</span>
		c2 <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>brightness2 <span style="color: #000066;">*</span> MaxPixelValue<span style="color: #000066;">&#41;</span>
&nbsp;
		DrawPixel<span style="color: #000066;">&#40;</span>ix2,iy2, c1		<span style="color: #000066;">&#41;</span>
		DrawPixel<span style="color: #000066;">&#40;</span>ix2,iy2<span style="color: #000066;">+</span><span style="color: #CC0000;">1</span>, c2<span style="color: #000066;">&#41;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">For</span> x<span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>ix1<span style="color: #000066;">+</span><span style="color: #CC0000;">1</span><span style="color: #000066;">&#41;</span> <span style="color: #000066; font-weight: bold;">To</span> <span style="color: #000066;">&#40;</span>ix2<span style="color: #000066;">-</span><span style="color: #CC0000;">1</span><span style="color: #000066;">&#41;</span>
&nbsp;
			brightness1 <span style="color: #000066;">=</span> invfrac<span style="color: #000066;">&#40;</span>yf<span style="color: #000066;">&#41;</span>
			brightness2 <span style="color: #000066;">=</span>    frac<span style="color: #000066;">&#40;</span>yf<span style="color: #000066;">&#41;</span>
&nbsp;
			c1 <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>brightness1 <span style="color: #000066;">*</span> MaxPixelValue<span style="color: #000066;">&#41;</span>
			c2 <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>brightness2 <span style="color: #000066;">*</span> MaxPixelValue<span style="color: #000066;">&#41;</span>
&nbsp;
			DrawPixel<span style="color: #000066;">&#40;</span>x,<span style="color: #0000ff;">Int</span><span style="color: #000066;">&#40;</span>yf<span style="color: #000066;">&#41;</span>, c1	<span style="color: #000066;">&#41;</span>
			DrawPixel<span style="color: #000066;">&#40;</span>x,<span style="color: #0000ff;">Int</span><span style="color: #000066;">&#40;</span>yf<span style="color: #000066;">&#41;</span><span style="color: #000066;">+</span><span style="color: #CC0000;">1</span>, c2<span style="color: #000066;">&#41;</span>
&nbsp;
			yf <span style="color: #000066;">=</span> yf <span style="color: #000066;">+</span> grad
&nbsp;
		<span style="color: #000066; font-weight: bold;">Next</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Else</span> <span style="color: #ff0000; font-style: italic;">;-------------------- Vertical --------------------</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">If</span> y1 <span style="color: #000066;">&gt;</span> y2
			<span style="color: #000066; font-weight: bold;">Swap</span> x1, x2
			<span style="color: #000066; font-weight: bold;">Swap</span> y1, y2
			xd <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>x2<span style="color: #000066;">-</span>x1<span style="color: #000066;">&#41;</span>
			yd <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>y2<span style="color: #000066;">-</span>y1<span style="color: #000066;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
		grad <span style="color: #000066;">=</span> xd<span style="color: #000066;">/</span>yd
		yend <span style="color: #000066;">=</span> trunc<span style="color: #000066;">&#40;</span>y1<span style="color: #000066;">+</span><span style="color: #CC0000;">0.5</span><span style="color: #000066;">&#41;</span>
		xend <span style="color: #000066;">=</span> x1 <span style="color: #000066;">+</span> grad<span style="color: #000066;">*</span><span style="color: #000066;">&#40;</span>yend<span style="color: #000066;">-</span>y1<span style="color: #000066;">&#41;</span>
		ygap <span style="color: #000066;">=</span> invfrac<span style="color: #000066;">&#40;</span>y1<span style="color: #000066;">+</span><span style="color: #CC0000;">0.5</span><span style="color: #000066;">&#41;</span>
&nbsp;
		ix1  <span style="color: #000066;">=</span> <span style="color: #0000ff;">Int</span><span style="color: #000066;">&#40;</span>xend<span style="color: #000066;">&#41;</span>
		iy1  <span style="color: #000066;">=</span> <span style="color: #0000ff;">Int</span><span style="color: #000066;">&#40;</span>yend<span style="color: #000066;">&#41;</span>
&nbsp;
		brightness1 <span style="color: #000066;">=</span> invfrac<span style="color: #000066;">&#40;</span>xend<span style="color: #000066;">&#41;</span> <span style="color: #000066;">*</span> ygap
		brightness2 <span style="color: #000066;">=</span>    frac<span style="color: #000066;">&#40;</span>xend<span style="color: #000066;">&#41;</span> <span style="color: #000066;">*</span> ygap
&nbsp;
		c1 <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>brightness1 <span style="color: #000066;">*</span> MaxPixelValue<span style="color: #000066;">&#41;</span>
		c2 <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>brightness2 <span style="color: #000066;">*</span> MaxPixelValue<span style="color: #000066;">&#41;</span>
&nbsp;
		DrawPixel<span style="color: #000066;">&#40;</span>ix1,iy1, c1<span style="color: #000066;">&#41;</span>
		DrawPixel<span style="color: #000066;">&#40;</span>ix1,iy1<span style="color: #000066;">+</span><span style="color: #CC0000;">1</span>, c2<span style="color: #000066;">&#41;</span>
&nbsp;
		xf <span style="color: #000066;">=</span> xend<span style="color: #000066;">+</span>grad
&nbsp;
		yend <span style="color: #000066;">=</span> trunc<span style="color: #000066;">&#40;</span>y2<span style="color: #000066;">+</span><span style="color: #CC0000;">0.5</span><span style="color: #000066;">&#41;</span>
		xend <span style="color: #000066;">=</span> x2 <span style="color: #000066;">+</span> grad<span style="color: #000066;">*</span><span style="color: #000066;">&#40;</span>yend<span style="color: #000066;">-</span>y2<span style="color: #000066;">&#41;</span>
		ygap <span style="color: #000066;">=</span> invfrac<span style="color: #000066;">&#40;</span>y2<span style="color: #000066;">-</span><span style="color: #CC0000;">0.5</span><span style="color: #000066;">&#41;</span>
		ix2  <span style="color: #000066;">=</span> <span style="color: #0000ff;">Int</span><span style="color: #000066;">&#40;</span>xend<span style="color: #000066;">&#41;</span>
		iy2  <span style="color: #000066;">=</span> <span style="color: #0000ff;">Int</span><span style="color: #000066;">&#40;</span>yend<span style="color: #000066;">&#41;</span>
&nbsp;
		brightness1 <span style="color: #000066;">=</span> invfrac<span style="color: #000066;">&#40;</span>xend<span style="color: #000066;">&#41;</span> <span style="color: #000066;">*</span> ygap
		brightness2 <span style="color: #000066;">=</span>    frac<span style="color: #000066;">&#40;</span>xend<span style="color: #000066;">&#41;</span> <span style="color: #000066;">*</span> ygap
&nbsp;
		c1 <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>brightness1 <span style="color: #000066;">*</span> MaxPixelValue<span style="color: #000066;">&#41;</span>
		c2 <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>brightness2 <span style="color: #000066;">*</span> MaxPixelValue<span style="color: #000066;">&#41;</span>
&nbsp;
		DrawPixel<span style="color: #000066;">&#40;</span>ix2,iy2, c1		<span style="color: #000066;">&#41;</span>
		DrawPixel<span style="color: #000066;">&#40;</span>ix2,iy2<span style="color: #000066;">+</span><span style="color: #CC0000;">1</span>, c2<span style="color: #000066;">&#41;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">For</span> y<span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>iy1<span style="color: #000066;">+</span><span style="color: #CC0000;">1</span><span style="color: #000066;">&#41;</span> <span style="color: #000066; font-weight: bold;">To</span> <span style="color: #000066;">&#40;</span>iy2<span style="color: #000066;">-</span><span style="color: #CC0000;">1</span><span style="color: #000066;">&#41;</span>
&nbsp;
			brightness1 <span style="color: #000066;">=</span> invfrac<span style="color: #000066;">&#40;</span>xf<span style="color: #000066;">&#41;</span>
			brightness2 <span style="color: #000066;">=</span>    frac<span style="color: #000066;">&#40;</span>xf<span style="color: #000066;">&#41;</span>
&nbsp;
			c1 <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>brightness1 <span style="color: #000066;">*</span> MaxPixelValue<span style="color: #000066;">&#41;</span>
			c2 <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span>brightness2 <span style="color: #000066;">*</span> MaxPixelValue<span style="color: #000066;">&#41;</span>
&nbsp;
			DrawPixel<span style="color: #000066;">&#40;</span><span style="color: #0000ff;">Int</span><span style="color: #000066;">&#40;</span>xf<span style="color: #000066;">&#41;</span>,y, c1	<span style="color: #000066;">&#41;</span>
			DrawPixel<span style="color: #000066;">&#40;</span><span style="color: #0000ff;">Int</span><span style="color: #000066;">&#40;</span>xf<span style="color: #000066;">&#41;</span><span style="color: #000066;">+</span><span style="color: #CC0000;">1</span>,y, c2<span style="color: #000066;">&#41;</span>
&nbsp;
			xf <span style="color: #000066;">=</span> xf <span style="color: #000066;">+</span> grad
&nbsp;
		<span style="color: #000066; font-weight: bold;">Next</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span></pre></div></div>

<div class="wp-caption aligncenter" style="width: 295px"><a href="http://gushh.net/blog/wp-content/uploads/2010/08/WuLine450.png"><img title="WuLine450" src="http://gushh.net/blog/wp-content/uploads/2010/08/WuLine450-285x300.png" alt="" width="285" height="300" /></a><p class="wp-caption-text">You&#39;ll quickly notice there&#39;s no coloring and no blending, ie. lines that overlap each other are not blended; we would have to sample the frame buffer to do this and quite frankly, I&#39;d rather use OpenGL if I needed to draw hundredths of AA lines.</p></div>
<p>There&#8217;s at least one issue with this code, sometimes the start/end points are drawn with an offset, etc. I don&#8217;t really have time to hunt down the bug though, but heres a quick and <strong>dirty</strong> example:</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">Macro</span> RAD2DEG<span style="color: #000066;">&#40;</span>_n_<span style="color: #000066;">&#41;</span> 	: <span style="color: #000066;">&#40;</span>_n_ <span style="color: #000066;">*</span> <span style="color: #CC0000;">57.295779513082323</span> <span style="color: #000066;">&#41;</span> : <span style="color: #000066; font-weight: bold;">EndMacro</span>
<span style="color: #000066; font-weight: bold;">Macro</span> DEG2RAD<span style="color: #000066;">&#40;</span>_n_<span style="color: #000066;">&#41;</span> 	: <span style="color: #000066;">&#40;</span>_n_ <span style="color: #000066;">*</span> <span style="color: #CC0000;">0.0174532925199432</span> <span style="color: #000066;">&#41;</span> : <span style="color: #000066; font-weight: bold;">EndMacro</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i render<span style="color: #000066;">&#40;</span> img.i <span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Define</span>.f scalar <span style="color: #000066;">=</span> <span style="color: #CC0000;">240</span>
	<span style="color: #000066; font-weight: bold;">Define</span>.i ot, nt, theta, x, y
	<span style="color: #000066; font-weight: bold;">Define</span>.f t, time,frames
&nbsp;
	<span style="color: #000066; font-weight: bold;">Define</span>.i mode <span style="color: #000066;">=</span> <span style="color: #CC0000;">1</span>
&nbsp;
	<span style="color: #0000ff;">InitKeyboard</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Repeat</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">StartDrawing</span><span style="color: #000066;">&#40;</span><span style="color: #0000ff;">ImageOutput</span><span style="color: #000066;">&#40;</span>img<span style="color: #000066;">&#41;</span><span style="color: #000066;">&#41;</span>
&nbsp;
			<span style="color: #0000ff;">Box</span><span style="color: #000066;">&#40;</span><span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">0</span>,<span style="color: #CC0000;">512</span>,<span style="color: #CC0000;">512</span>, <span style="color: #CC0000;">0</span><span style="color: #000066;">&#41;</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">ExamineKeyboard</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span> <span style="color: #ff0000; font-style: italic;">; who would've guessed, this works fine without openscreen() if we're not in debug mode...</span>
				<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">KeyboardReleased</span><span style="color: #000066;">&#40;</span> #PB_Key_Space <span style="color: #000066;">&#41;</span>
					mode <span style="color: #000066;">=</span> <span style="color: #CC0000;">1</span> <span style="color: #000066;">-</span> mode
				<span style="color: #000066; font-weight: bold;">EndIf</span>
			<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">For</span> theta<span style="color: #000066;">=</span><span style="color: #CC0000;">0</span> <span style="color: #000066; font-weight: bold;">To</span> <span style="color: #CC0000;">360</span> <span style="color: #000066; font-weight: bold;">Step</span> <span style="color: #CC0000;">8</span>
&nbsp;
				t <span style="color: #000066;">=</span> DEG2RAD<span style="color: #000066;">&#40;</span>theta<span style="color: #000066;">&#41;</span><span style="color: #000066;">+</span><span style="color: #000066;">&#40;</span>frames<span style="color: #000066;">*</span><span style="color: #CC0000;">0.005</span><span style="color: #000066;">&#41;</span>
				x <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span> <span style="color: #0000ff;">Cos</span><span style="color: #000066;">&#40;</span>t<span style="color: #000066;">&#41;</span> <span style="color: #000066;">*</span> scalar <span style="color: #000066;">&#41;</span> <span style="color: #000066;">+</span> <span style="color: #CC0000;">16</span>
				y <span style="color: #000066;">=</span> <span style="color: #000066;">&#40;</span> <span style="color: #0000ff;">Sin</span><span style="color: #000066;">&#40;</span>t<span style="color: #000066;">&#41;</span> <span style="color: #000066;">*</span> scalar <span style="color: #000066;">&#41;</span> <span style="color: #000066;">+</span> <span style="color: #CC0000;">16</span>
&nbsp;
				<span style="color: #000066; font-weight: bold;">If</span> mode
					WuLine<span style="color: #000066;">&#40;</span> scalar<span style="color: #000066;">+</span>y<span style="color: #000066;">*</span>time<span style="color: #000066;">*</span><span style="color: #CC0000;">2</span>, scalar<span style="color: #000066;">+</span>x<span style="color: #000066;">*</span>time<span style="color: #000066;">*</span><span style="color: #CC0000;">2</span>, scalar<span style="color: #000066;">+</span>x, scalar<span style="color: #000066;">+</span>y <span style="color: #000066;">&#41;</span>
				<span style="color: #000066; font-weight: bold;">Else</span>
					<span style="color: #0000ff;">LineXY</span><span style="color: #000066;">&#40;</span> scalar<span style="color: #000066;">+</span>y<span style="color: #000066;">*</span>time<span style="color: #000066;">*</span><span style="color: #CC0000;">2</span>, scalar<span style="color: #000066;">+</span>x<span style="color: #000066;">*</span>time<span style="color: #000066;">*</span><span style="color: #CC0000;">2</span>, scalar<span style="color: #000066;">+</span>x, scalar<span style="color: #000066;">+</span>y, $ffffff <span style="color: #000066;">&#41;</span>
				<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">Next</span>
&nbsp;
			time <span style="color: #000066;">+</span> <span style="color: #000066;">&#40;</span><span style="color: #0000ff;">Cos</span><span style="color: #000066;">&#40;</span>frames<span style="color: #000066;">*</span><span style="color: #CC0000;">0.01</span><span style="color: #000066;">&#41;</span><span style="color: #000066;">*</span><span style="color: #CC0000;">0.0045</span><span style="color: #000066;">&#41;</span>
			frames <span style="color: #000066;">+</span> <span style="color: #CC0000;">1</span>
&nbsp;
			<span style="color: #0000ff;">StopDrawing</span><span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
			<span style="color: #0000ff;">SetGadgetState</span><span style="color: #000066;">&#40;</span> <span style="color: #CC0000;">0</span>, <span style="color: #0000ff;">ImageID</span><span style="color: #000066;">&#40;</span>img<span style="color: #000066;">&#41;</span> <span style="color: #000066;">&#41;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
		<span style="color: #0000ff;">Delay</span><span style="color: #000066;">&#40;</span><span style="color: #CC0000;">8</span><span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">ForEver</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Define</span>.i img
<span style="color: #000066; font-weight: bold;">If</span> <span style="color: #0000ff;">OpenWindow</span><span style="color: #000066;">&#40;</span><span style="color: #CC0000;">0</span>, <span style="color: #CC0000;">0</span>, <span style="color: #CC0000;">0</span>, <span style="color: #CC0000;">512</span>, <span style="color: #CC0000;">512</span>, <span style="color: #009900;">&quot;WuLine 4.50 by GuShH&quot;</span>, #PB_Window_SystemMenu <span style="color: #000066;">|</span> #PB_Window_ScreenCentered<span style="color: #000066;">&#41;</span>
	img <span style="color: #000066;">=</span> <span style="color: #0000ff;">CreateImage</span><span style="color: #000066;">&#40;</span>#PB_Any, <span style="color: #CC0000;">512</span>, <span style="color: #CC0000;">512</span><span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">If</span> img
		<span style="color: #0000ff;">CreateThread</span><span style="color: #000066;">&#40;</span>@render<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>, img<span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">EndIf</span>
	<span style="color: #0000ff;">ImageGadget</span><span style="color: #000066;">&#40;</span><span style="color: #CC0000;">0</span>,  <span style="color: #CC0000;">0</span>, <span style="color: #CC0000;">0</span>, <span style="color: #CC0000;">0</span>, <span style="color: #CC0000;">0</span>, <span style="color: #0000ff;">ImageID</span><span style="color: #000066;">&#40;</span>img<span style="color: #000066;">&#41;</span><span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">Repeat</span>
	<span style="color: #000066; font-weight: bold;">Until</span> <span style="color: #0000ff;">WaitWindowEvent</span><span style="color: #000066;">&#40;</span><span style="color: #CC0000;">16</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">=</span> #PB_Event_CloseWindow
<span style="color: #000066; font-weight: bold;">EndIf</span></pre></div></div>

<p>Either way, enjoy.</p>
<p>PS: You may find the complete source in <a href="http://gushh.net/dev/?file=pb/WuLine450.pb" target="_blank">here</a></p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://gushh.net/blog/2009/08/06/animation-lib/" rel="bookmark" class="crp_title">Animation lib</a></li><li><a href="http://gushh.net/blog/2009/07/13/macro-templates-by-example/" rel="bookmark" class="crp_title">Macro Templates, by example.</a></li><li><a href="http://gushh.net/blog/2010/08/14/autocomplete-library/" rel="bookmark" class="crp_title">AutoComplete Library</a></li><li><a href="http://gushh.net/blog/2010/04/06/filetomemory-memorytofile/" rel="bookmark" class="crp_title">FileToMemory &#8211; MemoryToFile</a></li><li><a href="http://gushh.net/blog/2010/07/18/validate-email-address/" rel="bookmark" class="crp_title">Validate email address</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/2010/08/02/wuline-antialiased-lines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Validate email address</title>
		<link>http://gushh.net/blog/2010/07/18/validate-email-address/</link>
		<comments>http://gushh.net/blog/2010/07/18/validate-email-address/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 13:11:21 +0000</pubDate>
		<dc:creator>GuShH</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[PureBasic]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[email helper]]></category>
		<category><![CDATA[get mx records]]></category>
		<category><![CDATA[mail validation]]></category>
		<category><![CDATA[purebasic how to validate emails]]></category>
		<category><![CDATA[regular expression]]></category>
		<category><![CDATA[validate email]]></category>

		<guid isPermaLink="false">http://gushh.net/blog/?p=396</guid>
		<description><![CDATA[Once in a while you&#8217;ll be forced to validate an email address (or many!) &#8212; The usual no-brainer method is to perform a quick syntactical test to ensure the address is not malformed, however even a properly formed address may be invalid or, unreachable. Clearly we must add a second validation step&#8230; &#8212; Hey I [...]]]></description>
			<content:encoded><![CDATA[<p>Once in a while you&#8217;ll be forced to validate an email address (or many!) &#8212; The usual no-brainer method is to perform a quick syntactical test to ensure the address is not malformed, however even a properly formed address may be invalid or, unreachable.</p>
<p>Clearly we must add a second validation step&#8230; &#8212; Hey I know, let&#8217;s check the MX records!</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">Procedure</span>.s Email_GetHost<span style="color: #000066;">&#40;</span> eMail.s <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">If</span> eMail
		<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> <span style="color: #0000ff;">Right</span><span style="color: #000066;">&#40;</span> eMail, <span style="color: #0000ff;">Len</span><span style="color: #000066;">&#40;</span>eMail<span style="color: #000066;">&#41;</span> <span style="color: #000066;">-</span> <span style="color: #0000ff;">FindString</span><span style="color: #000066;">&#40;</span>eMail, <span style="color: #009900;">&quot;@&quot;</span>, <span style="color: #CC0000;">1</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">EndIf</span>
<span style="color: #000066; font-weight: bold;">EndProcedure</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">Procedure</span>.i Email_ValidateAddress<span style="color: #000066;">&#40;</span> eMail.s, CompleteValidation.i <span style="color: #000066;">=</span> #True <span style="color: #000066;">&#41;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">Define</span>.s pattern <span style="color: #000066;">=</span> <span style="color: #009900;">&quot;^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$&quot;</span>
	<span style="color: #000066; font-weight: bold;">Define</span>.i is_valid <span style="color: #000066;">=</span> #False
&nbsp;
	<span style="color: #000066; font-weight: bold;">Define</span>.i handle <span style="color: #000066;">=</span> CreateRegularExpression<span style="color: #000066;">&#40;</span> #PB_Any, pattern <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">If</span> IsRegularExpression<span style="color: #000066;">&#40;</span> handle <span style="color: #000066;">&#41;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">If</span> MatchRegularExpression<span style="color: #000066;">&#40;</span> handle, eMail <span style="color: #000066;">&#41;</span>
			<span style="color: #000066; font-weight: bold;">If</span> CompleteValidation
&nbsp;
				<span style="color: #000066; font-weight: bold;">Dim</span> mx.s<span style="color: #000066;">&#40;</span><span style="color: #CC0000;">99</span><span style="color: #000066;">&#41;</span>
				<span style="color: #000066; font-weight: bold;">If</span> getmxrr<span style="color: #000066;">&#40;</span> Email_GetHost<span style="color: #000066;">&#40;</span>eMail<span style="color: #000066;">&#41;</span>, mx<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span> <span style="color: #000066;">&#41;</span> <span style="color: #ff0000; font-style: italic;">; see http://gushh.net/blog/2010/07/17/get-mx-records/</span>
					is_valid <span style="color: #000066;">=</span> #True
				<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">Else</span>
				is_valid <span style="color: #000066;">=</span> #True
			<span style="color: #000066; font-weight: bold;">EndIf</span>
		<span style="color: #000066; font-weight: bold;">Else</span>
				is_valid <span style="color: #000066;">=</span> <span style="color: #000066;">-</span><span style="color: #CC0000;">1</span>
		<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
		FreeRegularExpression<span style="color: #000066;">&#40;</span> handle <span style="color: #000066;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">EndIf</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">ProcedureReturn</span> is_valid
&nbsp;
<span style="color: #000066; font-weight: bold;">EndProcedure</span></pre></div></div>

<p>For the getmxrr() function <a href="http://gushh.net/blog/2010/07/17/get-mx-records/" target="_blank">click here</a>. Or <a href="http://gushh.net/dev/?file=pb/email_helper.pb" target="_blank">click here</a> for the full code + example usage</p>
<p>The <a href="http://gushh.net/dev/?file=pb/email_helper.pb">full code</a> also contains a few other helper routines, I left them in there in case someone finds them useful.</p>
<p>These are the functions included in the source:</p>

<div class="wp_syntax"><div class="code"><pre class="purebasic" style="font-family:monospace;">Email_GetName<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
Email_GetHost<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
Email_ValidateAddress<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span>
Email_ConvertToLiteral<span style="color: #000066;">&#40;</span><span style="color: #000066;">&#41;</span></pre></div></div>

<p>Obviously you&#8217;ll have to tweak a bit the code, specially the way it handles the arrays. But overall it should be pretty usable. I might come up with a cross-platform version in the future, but so far I haven&#8217;t found a need for it.</p>
<p>Please double-check the example code, make sure you understand the routine could return &lt;= 0 if validation fails (two modes basically, syntax fault and mx fault).</p>
<p>Feel free to leave a comment or <a href="http://gushh.net/blog/contact/">send me your own version of the code</a>!</p>
<p>Cheers!</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://gushh.net/blog/2010/07/17/get-mx-records/" rel="bookmark" class="crp_title">Get MX Records</a></li><li><a href="http://gushh.net/blog/2010/08/26/why-i-hate-helpdesks/" rel="bookmark" class="crp_title">Why I hate helpdesks!</a></li><li><a href="http://gushh.net/blog/2010/04/06/filetomemory-memorytofile/" rel="bookmark" class="crp_title">FileToMemory &#8211; MemoryToFile</a></li><li><a href="http://gushh.net/blog/2008/07/11/hosting-nightmares-and-deja-vu/" rel="bookmark" class="crp_title">Hosting nightmares and deja vu.</a></li><li><a href="http://gushh.net/blog/2008/06/11/strescape-strquotemeta-from-php-to-pb-quotemeta-addslashes/" rel="bookmark" class="crp_title">StrEscape, StrQuoteMeta From PHP to PB. (quotemeta, addslashes)</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://gushh.net/blog/2010/07/18/validate-email-address/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
