tag:blogger.com,1999:blog-32287155917334326892024-02-06T21:13:05.876-05:00Bear Naked CodeReal programmers code naked.Adrian Hayeshttp://www.blogger.com/profile/17084091939713264454noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-3228715591733432689.post-77601414186229301612019-12-23T15:20:00.001-05:002019-12-23T15:20:22.775-05:00Word to the wise. Never forget to renew your domain before it expires. <script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3959304-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
<div>
<br /></div>
<div>
Over a year later, with a federal prosecution of the domain squatter who snatched it up (for running a fraudulent store), I finally have it back.</div>
Adrian Hayeshttp://www.blogger.com/profile/17084091939713264454noreply@blogger.com1tag:blogger.com,1999:blog-3228715591733432689.post-19452036826315338392017-09-13T13:51:00.004-04:002017-09-13T13:51:42.513-04:00<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg520b_thTwg_n_54dLB15L3Kvdj3qYqCSHitUj2Movbf_BHvDT3UibfYUgZaI_tLIKDdOl1tNRPr24ex8gyFVTQ_yqyfuvjjFkoKK2dnPnYgegPSwkTwQLlDymGIS8j19yKOY1BwpAI1M/s1600/passwords.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="317" data-original-width="476" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg520b_thTwg_n_54dLB15L3Kvdj3qYqCSHitUj2Movbf_BHvDT3UibfYUgZaI_tLIKDdOl1tNRPr24ex8gyFVTQ_yqyfuvjjFkoKK2dnPnYgegPSwkTwQLlDymGIS8j19yKOY1BwpAI1M/s1600/passwords.png" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
In other words, if you use a glass box, Schrödinger's Cat always dies.</div>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3959304-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>Adrian Hayeshttp://www.blogger.com/profile/17084091939713264454noreply@blogger.com1tag:blogger.com,1999:blog-3228715591733432689.post-40464506926807699022016-09-12T17:00:00.000-04:002016-09-12T17:08:58.393-04:00Multi-threaded Asynchronous File Copy Class for C#It used to be that, since file I/O was your biggest bottleneck, copying files on multiple threads was inefficient, even slowing down the file copy. Multiple simultaneous copy jobs would spend the most time just positioning read heads around disk sectors. Modern disks, however, have vastly improved read-ahead caching. SSD drives eliminate much of the time physical disks would spend positioning the read head. If you have multiple disks in a RAID array or advanced SAN, this reduces the I/O bottleneck for simultaneous file copies.<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3959304-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
<br />
<div>
<br /></div>
<div>
In testing, I have found that multi-threaded copying cuts the time to copy multiple files anywhere from twenty to fifty percent over copying the files individually. This holds true whether copying locally, across a LAN or WAN. The TestCopyForm project linked below has a sample application with this class where you can adjust buffer size and specify whether to use multi-threading to copy files or copy them individually. You can test with various combinations to see what works best for your environment.</div>
<div>
<br /></div>
<h4>
Multi-Threaded Async File Copy Class</h4>
<div>
To use this class, add it to your project. When you initialize an instance of the class, pass it either a single file source path and destination path, create a Queue of KeyValueObjects to pass multiple files, or use a simple new object initialization and add the files through the CopyList queue.</div>
<div>
<br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">FileCopyMTStream fcs = <span style="color: #008800; font-weight: bold;">new</span> FileCopyMTStream();
<span style="color: #333399; font-weight: bold;">string</span> SourcePath = <span style="background-color: #fff0f0;">"c:\\somedir"</span>;
<span style="color: #333399; font-weight: bold;">string</span> TargetPath = <span style="background-color: #fff0f0;">"c:\\someotherdir"</span>;
<span style="color: #333399; font-weight: bold;">string</span> targetfile;
<span style="color: #008800; font-weight: bold;">foreach</span> (<span style="color: #333399; font-weight: bold;">string</span> sourcefile <span style="color: #008800; font-weight: bold;">in</span> Directory.GetFiles(SourcePath))
{
targetpath = Path.Combine(TargetPath, Path.GetFileName(filepath));
fcs.CopyList.Enqueue(<span style="color: #008800; font-weight: bold;">new</span> KeyValuePair<<span style="color: #333399; font-weight: bold;">string</span>, <span style="color: #333399; font-weight: bold;">string</span>>(filepath, targetpath));
}
</pre>
</div>
</div>
<br />
<br />
Next, add event handlers to your code to handle status updates:<br />
<div>
<br /></div>
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">fcs.FileCopyStarted += Fcs_FileCopyStarted;
fcs.ProgressChanged += Fcs_ProgressChanged;
fcs.FileCopyComplete += Fcs_FileCopyComplete;
fcs.FileCopyException += Fcs_FileCopyException;
</pre>
</div>
<div>
<br /></div>
<!-- HTML generated using hilite.me --><br />
When you write the event handlers, make sure that you use Invoke to interact with the UI thread - the event handlers will be running under the context of one of the FileCopyMTStream threadpool threads. If you try to access a control from that thread, it will throw an error.<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">private</span> <span style="color: #008800; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">Fcs_ProgressChanged</span>(<span style="color: #333399; font-weight: bold;">string</span> SourceFile, <span style="color: #333399; font-weight: bold;">int</span> Percentage, <span style="color: #333399; font-weight: bold;">long</span> CopiedSize, <span style="color: #333399; font-weight: bold;">long</span> FileSize)
{
Invoke(<span style="color: #008800; font-weight: bold;">new</span> MethodInvoker(<span style="color: #008800; font-weight: bold;">delegate</span>
{
<span style="color: #008800; font-weight: bold;">if</span> (lvFileList.Items.ContainsKey(SourceFile))
{
lvFileList.Items[SourceFile].SubItems[<span style="color: #6600ee; font-weight: bold;">3</span>].Text = CopiedSize.ToString(<span style="background-color: #fff0f0;">"N0"</span>) + <span style="background-color: #fff0f0;">" copied"</span>;
lvFileList.Items[SourceFile].SubItems[<span style="color: #6600ee; font-weight: bold;">4</span>].Text = Percentage.ToString() + <span style="background-color: #fff0f0;">"%"</span>;
}
}
));
}
</pre>
</div>
<br />
<br />
When you are ready to kick off the copy, call the following method:<br />
<br />
<!-- HTML generated using hilite.me --><br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;">fcs.StartCopy();
</pre>
</div>
<br />
<br />
Here is a test project that includes the class:<br />
<h3>
<br /><a href="https://docs.google.com/uc?id=0B0q_CuHRyntxUDlkOWNnS25aNnc&export=download">TestCopyForm.zip</a></h3>
<br />
<br />
Here is the class. Enjoy!<br />
<br />
<div style="background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;">
<pre style="line-height: 125%; margin: 0;"><span style="color: #008800; font-weight: bold;">using</span> <span style="color: #0e84b5; font-weight: bold;">System</span>;
<span style="color: #008800; font-weight: bold;">using</span> <span style="color: #0e84b5; font-weight: bold;">System.Collections.Generic</span>;
<span style="color: #008800; font-weight: bold;">using</span> <span style="color: #0e84b5; font-weight: bold;">System.IO</span>;
<span style="color: #008800; font-weight: bold;">using</span> <span style="color: #0e84b5; font-weight: bold;">System.Threading</span>;
<span style="color: #888888;">// FileCopyMTStream - File Copy Multi-Threaded Stream</span>
<span style="color: #888888;">// Adrian Hayes</span>
<span style="color: #888888;">// http://www.bearnakedcode.com</span>
<span style="color: #888888;">//</span>
<span style="color: #888888;">// A class which asynchronously copies one or more files using multiple</span>
<span style="color: #888888;">// threadpool threads. It allows file copies without locking UI thread and</span>
<span style="color: #888888;">// provides status reports via events.</span>
<span style="color: #888888;">//</span>
<span style="color: #888888;">// License: You are free to use this code in any of your projects as you wish.</span>
<span style="color: #888888;">// It is offered without warranty. Use at your own risk.</span>
<span style="color: #888888;">// If you publish its source (or any portion thereof), please include</span>
<span style="color: #888888;">// a reference back to http://www.bearnakedcode.com.</span>
<span style="color: #888888;">//</span>
<span style="color: #888888;">// Enjoy!</span>
<span style="color: #008800; font-weight: bold;">namespace</span> <span style="color: #0e84b5; font-weight: bold;">BearNakedCode</span>
{
<span style="color: #888888;">//Delegates for events</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">delegate</span> <span style="color: #008800; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">FileCopyStartedDelegate</span>(<span style="color: #333399; font-weight: bold;">string</span> SourceFile, <span style="color: #333399; font-weight: bold;">long</span> FileSize);
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">delegate</span> <span style="color: #008800; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">FileCopyExceptionDelegate</span>(<span style="color: #333399; font-weight: bold;">string</span> SourceFile, Exception Error);
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">delegate</span> <span style="color: #008800; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">CompleteDelegate</span>(<span style="color: #333399; font-weight: bold;">string</span> SourceFile, <span style="color: #333399; font-weight: bold;">bool</span> Canceled);
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">delegate</span> <span style="color: #008800; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">ProgressChangedDelegate</span>(<span style="color: #333399; font-weight: bold;">string</span> SourceFile, <span style="color: #333399; font-weight: bold;">int</span> Percentage, <span style="color: #333399; font-weight: bold;">long</span> CopiedSize, <span style="color: #333399; font-weight: bold;">long</span> FileSize);
<span style="color: #888888;">/// <summary></span>
<span style="color: #888888;">/// Copies a queue of files asynchronously with multi-threading.</span>
<span style="color: #888888;">/// </summary></span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">class</span> <span style="color: #bb0066; font-weight: bold;">FileCopyMTStream</span>
{
<span style="color: #557799;">#region PublicVariables</span>
<span style="color: #888888;">/// <summary></span>
<span style="color: #888888;">/// A queue of files to copy. Elements are KeyValuePairs with Key = Source / Value = Destination.</span>
<span style="color: #888888;">/// </summary></span>
<span style="color: #008800; font-weight: bold;">public</span> Queue<KeyValuePair<<span style="color: #333399; font-weight: bold;">string</span>, <span style="color: #333399; font-weight: bold;">string</span>>> CopyList = <span style="color: #008800; font-weight: bold;">new</span> Queue<KeyValuePair<<span style="color: #333399; font-weight: bold;">string</span>, <span style="color: #333399; font-weight: bold;">string</span>>>();
<span style="color: #888888;">/// <summary></span>
<span style="color: #888888;">/// Will copy using multiple threads, managed by threadpool(default).</span>
<span style="color: #888888;">/// If false, copy is limited to 1 thread.</span>
<span style="color: #888888;">/// </summary></span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">bool</span> MultiThreaded = <span style="color: #008800; font-weight: bold;">true</span>;
<span style="color: #888888;">/// <summary></span>
<span style="color: #888888;">/// Size of the copy buffer. Default is 4 KB buffer. </span>
<span style="color: #888888;">/// </summary></span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">int</span> BufferSize = <span style="color: #6600ee; font-weight: bold;">4</span> * <span style="color: #6600ee; font-weight: bold;">1024</span>;
<span style="color: #888888;">/// <summary></span>
<span style="color: #888888;">/// When reporting progress, it will wait until it has copied this amount of</span>
<span style="color: #888888;">/// bytes before raising the ProgressChanged event. This is to reduce flicker</span>
<span style="color: #888888;">/// in controls from overly-frequent status updates. Default is 128K bytes.</span>
<span style="color: #888888;">/// </summary></span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #333399; font-weight: bold;">long</span> ReportInterval = (<span style="color: #6600ee; font-weight: bold;">128</span> * <span style="color: #6600ee; font-weight: bold;">1024</span>); <span style="color: #888888;">// report only on each 128K block</span>
<span style="color: #557799;">#endregion</span>
<span style="color: #888888;">//provide cancellation method</span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #008800; font-weight: bold;">static</span> <span style="color: #333399; font-weight: bold;">bool</span> CancelRequested = <span style="color: #008800; font-weight: bold;">false</span>;
<span style="color: #557799;">#region EventHandlers</span>
<span style="color: #888888;">/// <summary></span>
<span style="color: #888888;">/// Event that fires when progress has changed on a file copy. </span>
<span style="color: #888888;">/// </summary></span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">event</span> ProgressChangedDelegate ProgressChanged;
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #008800; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">OnProgressChanged</span>(<span style="color: #333399; font-weight: bold;">string</span> SourceFile, <span style="color: #333399; font-weight: bold;">long</span> CopiedSize, <span style="color: #333399; font-weight: bold;">long</span> FileSize)
{
<span style="color: #333399; font-weight: bold;">int</span> pct = (<span style="color: #333399; font-weight: bold;">int</span>)((<span style="color: #333399; font-weight: bold;">double</span>)CopiedSize * <span style="color: #6600ee; font-weight: bold;">100</span> / (<span style="color: #333399; font-weight: bold;">double</span>)FileSize);
<span style="color: #888888;">//int pct = (int)(Math.Round((double)CopiedSize / (double)FileSize) * 100);</span>
<span style="color: #008800; font-weight: bold;">if</span> (ProgressChanged != <span style="color: #008800; font-weight: bold;">null</span>)
ProgressChanged(SourceFile, pct, CopiedSize, FileSize);
}
<span style="color: #888888;">/// <summary></span>
<span style="color: #888888;">/// Event that fires when a file copy has started.</span>
<span style="color: #888888;">/// </summary></span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">event</span> FileCopyStartedDelegate FileCopyStarted;
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #008800; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">OnFileCopyStarted</span>(<span style="color: #333399; font-weight: bold;">string</span> SourceFile, <span style="color: #333399; font-weight: bold;">long</span> FileSize)
{
<span style="color: #008800; font-weight: bold;">if</span> (FileCopyStarted != <span style="color: #008800; font-weight: bold;">null</span>)
FileCopyStarted(SourceFile, FileSize);
}
<span style="color: #888888;">/// <summary></span>
<span style="color: #888888;">/// Event that fires when a fatal exception occurs on a file copy.</span>
<span style="color: #888888;">/// </summary></span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">event</span> FileCopyExceptionDelegate FileCopyException;
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #008800; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">OnFileCopyException</span>(<span style="color: #333399; font-weight: bold;">string</span> SourceFile, Exception Error)
{
<span style="color: #008800; font-weight: bold;">if</span> (FileCopyException != <span style="color: #008800; font-weight: bold;">null</span>)
FileCopyException(SourceFile, Error);
}
<span style="color: #888888;">/// <summary></span>
<span style="color: #888888;">/// Event that fires when a copy job finishes or is cancelled.</span>
<span style="color: #888888;">/// </summary></span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">event</span> CompleteDelegate FileCopyComplete;
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #008800; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">OnFileCopyComplete</span>(<span style="color: #333399; font-weight: bold;">string</span> SourceFile, <span style="color: #333399; font-weight: bold;">bool</span> Cancelled)
{
<span style="color: #008800; font-weight: bold;">if</span> (FileCopyComplete != <span style="color: #008800; font-weight: bold;">null</span>)
FileCopyComplete(SourceFile, Cancelled);
}
<span style="color: #557799;">#endregion</span>
<span style="color: #557799;">#region Initializers</span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">FileCopyMTStream</span>()
{
}
<span style="color: #888888;">/// <summary></span>
<span style="color: #888888;">/// Initializes a new instance of FileCopyMTStream for a single file copy.</span>
<span style="color: #888888;">/// </summary></span>
<span style="color: #888888;">/// <param name="Source">Full path to the source file.</param></span>
<span style="color: #888888;">/// <param name="Destination">Full path to the destination file, including file name.</param></span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">FileCopyMTStream</span>(<span style="color: #333399; font-weight: bold;">string</span> Source, <span style="color: #333399; font-weight: bold;">string</span> Destination)
{
CopyList.Enqueue(<span style="color: #008800; font-weight: bold;">new</span> KeyValuePair<<span style="color: #333399; font-weight: bold;">string</span>, <span style="color: #333399; font-weight: bold;">string</span>>(Source, Destination));
}
<span style="color: #888888;">/// <summary></span>
<span style="color: #888888;">/// Initializes a new instance of FileCopyMTStream for multiple file copies.</span>
<span style="color: #888888;">/// </summary></span>
<span style="color: #888888;">/// <param name="SourceDestinationList"></param></span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #0066bb; font-weight: bold;">FileCopyMTStream</span>(Queue<KeyValuePair<<span style="color: #333399; font-weight: bold;">string</span>, <span style="color: #333399; font-weight: bold;">string</span>>> SourceDestinationList)
{
CopyList = SourceDestinationList;
}
<span style="color: #557799;">#endregion</span>
<span style="color: #888888;">/// <summary></span>
<span style="color: #888888;">/// Set to True to request all remaining copy jobs cancel at their current progress, close their streams and exit.</span>
<span style="color: #888888;">/// </summary></span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">CancelAll</span>()
{
CancelRequested = <span style="color: #008800; font-weight: bold;">true</span>;
}
<span style="color: #888888;">/// <summary></span>
<span style="color: #888888;">/// Begins the asynchronous file copies.</span>
<span style="color: #888888;">/// </summary></span>
<span style="color: #008800; font-weight: bold;">public</span> <span style="color: #008800; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">StartCopy</span>()
{
WaitCallback callback;
KeyValuePair<<span style="color: #333399; font-weight: bold;">string</span>, <span style="color: #333399; font-weight: bold;">string</span>> job;
<span style="color: #008800; font-weight: bold;">if</span> (MultiThreaded == <span style="color: #008800; font-weight: bold;">false</span>)
{
<span style="color: #008800; font-weight: bold;">new</span> <span style="color: #0066bb; font-weight: bold;">Thread</span>(<span style="color: #008800; font-weight: bold;">delegate</span> () { SingleThreadCopyJob(CopyList); }).Start();
}
<span style="color: #008800; font-weight: bold;">else</span>
{
<span style="color: #008800; font-weight: bold;">while</span> (CopyList.Count > <span style="color: #6600ee; font-weight: bold;">0</span>)
{
job = CopyList.Dequeue();
<span style="color: #008800; font-weight: bold;">if</span> (CheckCancelRequested(job.Key))
<span style="color: #008800; font-weight: bold;">return</span>;
callback = <span style="color: #008800; font-weight: bold;">new</span> WaitCallback(CopyJob);
ThreadPool.QueueUserWorkItem(callback, job);
}
}
}
<span style="color: #888888;">/// <summary></span>
<span style="color: #888888;">/// Copies a file. Used in thread pool operations to copy multiple files simultaneously. </span>
<span style="color: #888888;">/// </summary></span>
<span style="color: #888888;">/// <param name="job">A source/target pair to copy a file.</param></span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #008800; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">CopyJob</span>(<span style="color: #333399; font-weight: bold;">object</span> job)
{
<span style="color: #888888;">//copyjob - KVP. Key = source file. Value = destination file</span>
KeyValuePair<<span style="color: #333399; font-weight: bold;">string</span>, <span style="color: #333399; font-weight: bold;">string</span>> copyjob = (KeyValuePair<<span style="color: #333399; font-weight: bold;">string</span>, <span style="color: #333399; font-weight: bold;">string</span>>)job;
<span style="color: #008800; font-weight: bold;">if</span> (CheckCancelRequested(copyjob.Key))
<span style="color: #008800; font-weight: bold;">return</span>;
CopyFileStream(copyjob);
}
<span style="color: #888888;">/// <summary></span>
<span style="color: #888888;">/// Copies all files, one at a time, on the same thread. </span>
<span style="color: #888888;">/// Use where multiple I/O streams would present a bottleneck.</span>
<span style="color: #888888;">/// </summary></span>
<span style="color: #888888;">/// <param name="JobQueue">A queue of source/target pairs of files to copy.</param></span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #008800; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">SingleThreadCopyJob</span>(Queue<KeyValuePair<<span style="color: #333399; font-weight: bold;">string</span>, <span style="color: #333399; font-weight: bold;">string</span>>> JobQueue)
{
KeyValuePair<<span style="color: #333399; font-weight: bold;">string</span>, <span style="color: #333399; font-weight: bold;">string</span>> job;
<span style="color: #008800; font-weight: bold;">while</span> (CopyList.Count > <span style="color: #6600ee; font-weight: bold;">0</span>)
{
job = CopyList.Dequeue();
<span style="color: #008800; font-weight: bold;">if</span> (CheckCancelRequested(job.Key))
<span style="color: #008800; font-weight: bold;">return</span>;
CopyFileStream(job);
}
}
<span style="color: #888888;">/// <summary></span>
<span style="color: #888888;">/// Checks if the CancelRequested flag has been raised. </span>
<span style="color: #888888;">/// Sends copy Complete event notification if cancelled.</span>
<span style="color: #888888;">/// </summary></span>
<span style="color: #888888;">/// <param name="SourceFile">The file currently set to be copied.</param></span>
<span style="color: #888888;">/// <returns>True if the cancel flag set. False if OK to copy the file.</returns></span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #333399; font-weight: bold;">bool</span> <span style="color: #0066bb; font-weight: bold;">CheckCancelRequested</span>(<span style="color: #333399; font-weight: bold;">string</span> SourceFile)
{
<span style="color: #008800; font-weight: bold;">if</span> (CancelRequested)
{
OnFileCopyComplete(SourceFile, <span style="color: #008800; font-weight: bold;">true</span>);
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">true</span>;
}
<span style="color: #008800; font-weight: bold;">return</span> <span style="color: #008800; font-weight: bold;">false</span>;
}
<span style="color: #888888;">/// <summary></span>
<span style="color: #888888;">/// Uses a FileStream to copy a file from source to destination. </span>
<span style="color: #888888;">/// Sends event notifications on progress and completion. </span>
<span style="color: #888888;">/// </summary></span>
<span style="color: #888888;">/// <param name="CopyJob"></span>
<span style="color: #888888;">/// A Key Value pair of Source and Target paths for the file to copy.</span>
<span style="color: #888888;">/// </param></span>
<span style="color: #008800; font-weight: bold;">private</span> <span style="color: #008800; font-weight: bold;">void</span> <span style="color: #0066bb; font-weight: bold;">CopyFileStream</span>(KeyValuePair<<span style="color: #333399; font-weight: bold;">string</span>, <span style="color: #333399; font-weight: bold;">string</span>> CopyJob)
{
<span style="color: #333399; font-weight: bold;">byte</span>[] buffer = <span style="color: #008800; font-weight: bold;">new</span> <span style="color: #333399; font-weight: bold;">byte</span>[BufferSize]; <span style="color: #888888;">// 16K buffer</span>
<span style="color: #333399; font-weight: bold;">long</span> reporttally = <span style="color: #6600ee; font-weight: bold;">0</span>;
<span style="color: #008800; font-weight: bold;">using</span> (FileStream source = <span style="color: #008800; font-weight: bold;">new</span> FileStream(CopyJob.Key, FileMode.Open, FileAccess.Read))
{
<span style="color: #333399; font-weight: bold;">long</span> filelength = source.Length;
OnFileCopyStarted(CopyJob.Key, filelength);
<span style="color: #008800; font-weight: bold;">using</span> (FileStream dest = <span style="color: #008800; font-weight: bold;">new</span> FileStream(CopyJob.Value, FileMode.Create, FileAccess.Write))
{
<span style="color: #333399; font-weight: bold;">long</span> totalBytes = <span style="color: #6600ee; font-weight: bold;">0</span>;
<span style="color: #333399; font-weight: bold;">int</span> currentBlockSize = <span style="color: #6600ee; font-weight: bold;">0</span>;
<span style="color: #008800; font-weight: bold;">while</span> ((currentBlockSize = source.Read(buffer, <span style="color: #6600ee; font-weight: bold;">0</span>, buffer.Length)) > <span style="color: #6600ee; font-weight: bold;">0</span>)
{
<span style="color: #008800; font-weight: bold;">if</span> (CheckCancelRequested(CopyJob.Key))
<span style="color: #008800; font-weight: bold;">return</span>;
dest.Write(buffer, <span style="color: #6600ee; font-weight: bold;">0</span>, currentBlockSize);
totalBytes += currentBlockSize;
reporttally += currentBlockSize;
<span style="color: #008800; font-weight: bold;">if</span> (reporttally >= ReportInterval)
{
OnProgressChanged(CopyJob.Key, totalBytes, filelength);
reporttally = <span style="color: #6600ee; font-weight: bold;">0</span>;
}
}
}
}
OnFileCopyComplete(CopyJob.Key, CancelRequested);
}
}
}
</pre>
</div>
Adrian Hayeshttp://www.blogger.com/profile/17084091939713264454noreply@blogger.com1tag:blogger.com,1999:blog-3228715591733432689.post-45739750336590075362013-01-25T21:24:00.000-05:002013-01-25T21:28:12.480-05:00Regular Expression TesterI "regularly" (nyuk nyuk!) use regular expressions in my .Net code. However, I find that I spend no small amount of time designing them, troubleshooting why they aren't working and trying to work out the escape characters correctly. So much so that I decided to write a Regex testing application. <br />
<br />
<a href="http://sites.google.com/site/bearnakedcode/bearnakedcode-files/RegexTest.zip">Regex Tester (zipped .exe)</a><br />
<br />
<a href="http://sites.google.com/site/bearnakedcode/bearnakedcode-files/RegexTestSource.zip">C# Source Code</a><br />
<br />
This tool allows me to rapidly test regular expressions against sample text with or without options.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEHA_w42KlYb-jQd6xyDVEeie8jihEgx7J5rEMHqovuXvipMhfOkQzaaoJy8CL34FNTJX7ZLJ-Q9-kGV4wkR74uk8QKSBVAlB7zH6DYv2Yt6Yv4J_luQIXVJFZaNPCJ3gzTYYR2jo3i1E/s1600/RegexTester.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEHA_w42KlYb-jQd6xyDVEeie8jihEgx7J5rEMHqovuXvipMhfOkQzaaoJy8CL34FNTJX7ZLJ-Q9-kGV4wkR74uk8QKSBVAlB7zH6DYv2Yt6Yv4J_luQIXVJFZaNPCJ3gzTYYR2jo3i1E/s640/RegexTester.JPG" width="592" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
It shows me matches, splits and replaced text.<br />
<br />
If the Regex phrase is invalid, it will display the error text:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqP2x38AVrtbGzFuL53JdOCQ-UCC9csZXO2LyZ-fKr6x8g3wn6kqJ4LCXdNYeyZmVntPHIxFzQLjytC061HJyrOsYJFIWwlyC7RIxkI9tp6RiwHdOzgqo1BeI_4JBTZcL3lvlfO7on4Fc/s1600/error.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="98" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhqP2x38AVrtbGzFuL53JdOCQ-UCC9csZXO2LyZ-fKr6x8g3wn6kqJ4LCXdNYeyZmVntPHIxFzQLjytC061HJyrOsYJFIWwlyC7RIxkI9tp6RiwHdOzgqo1BeI_4JBTZcL3lvlfO7on4Fc/s400/error.JPG" width="400" /></a></div>
<br />
<br />
When I'm satisfied with the phrase and options, I click Copy Regex Initializer to copy it to the clipboard:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglaQezM5bk9_z443ISFoMKUyy5sahUU6Gfiu-R_eDP4ZPc-8z4oxVevXAiksGk6aFxGmsO4kJO4BQE4PuvrB3-nEjLTyU8vMBdBRmxHMvbzGSciwth2RWrSWZycNiD-d84u8QSQJs-ecw/s1600/Copy.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="186" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglaQezM5bk9_z443ISFoMKUyy5sahUU6Gfiu-R_eDP4ZPc-8z4oxVevXAiksGk6aFxGmsO4kJO4BQE4PuvrB3-nEjLTyU8vMBdBRmxHMvbzGSciwth2RWrSWZycNiD-d84u8QSQJs-ecw/s400/Copy.JPG" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
I can paste the copied text directly into my code after declaring the Regex object:</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjj5i10cFXEBFrOulm4830Ep3xPFw5zA6paC8JGWnt_VEEGg0uElLJqosMzv6DTZ0eN5RZss7rU90R4Gdo580j9jmsPWbCyqNU4XKxU58DDi3-vDgXN-ZVEZoWlxBp0wmeLmHxov3KWJbw/s1600/code.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjj5i10cFXEBFrOulm4830Ep3xPFw5zA6paC8JGWnt_VEEGg0uElLJqosMzv6DTZ0eN5RZss7rU90R4Gdo580j9jmsPWbCyqNU4XKxU58DDi3-vDgXN-ZVEZoWlxBp0wmeLmHxov3KWJbw/s1600/code.JPG" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
I hope you find it useful.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<br />Adrian Hayeshttp://www.blogger.com/profile/17084091939713264454noreply@blogger.com1tag:blogger.com,1999:blog-3228715591733432689.post-8801762703176156382011-06-29T14:47:00.018-04:002016-11-03T11:48:59.346-04:00Win 2008 Terminal Server Network App CrashingHow many Microsoft Developers does it take to change a lightbulb? None. They just make darkness the new standard.<br />
<br />
You can no longer safely run applications from a network location in Windows 2008 & R2 terminal server. When a user opens a program across the network and logs off, it will crash the program for all other users running it on the same server. It appears that Microsoft is no longer supporting functionality that has
been present for 20+ years and is not going to fix the bug due to
"Architectural Changes" in Windows 2008.<br />
<br />
<a href="http://support.microsoft.com/kb/2536487" target="_blank">http://support.microsoft.com/kb/2536487</a> <br />
<br />
Here is a summary of the issue:<br />
<ol>
<li>When a user opens any network application in a 2008 or R2 Terminal Server environment, the OS creates a File Control Block (FCB). The FCB is a handle that the OS uses to access the program file loaded into memory.<br />
<br />
</li>
<li>If another user on the terminal server opens the same program, the OS will give the second user access to the first user’s FCB and access to that part of the original user’s memory space that stores the executable. <br />
<br />
</li>
<li>When the first user logs off, all their FCB’s are dropped and become inaccessible to other users that were sharing them.<br />
<br />
</li>
<li>The next action the remaining users perform in the program fails and it crashes the application because it cannot access the program files.<br />
</li>
</ol>
<br />
You can see this reported in the Application event log on two entries with the same time stamp:<br />
<ul>
<li>Application Error, Event ID 1000 – “Faulting application xxxxx<application>.exe, version xxxxx…”<br />
<br />
</application></li>
<li>Application Error, Event ID 1005 – “Windows cannot access the file for one of the following reasons: there is a problem with the network connection, the disk that the file is stored on, or the storage drivers installed on this computer; or the disk is missing. Windows closed the program XXXXX<program name=""> because of this error.”</program></li>
</ul>
Microsoft says the "New Standard" is to load applications locally or use a WebDAV share. Local install works ok in one or two-server environments, not so well in 400+ server environments. Applying program updates to multiple servers is an administrative nightmare and a waste of resources as your environment grows. And WebDAV? Really?<br />
<br />
We've gotten past Microsoft's Offshore Support Defense Forces and we're finally in discussions with high-level US engineers at Microsoft. We're attempting to convince them of the gravity of the issue and to resolve it. The engineers have acknowledged that they have received multiple reports of the issue but that MS development is refusing to fix it.<br />
<br />
They said that the bug is coded deep in the 2008 OS and would require architectural redesign, so they are reluctant to make any changes. It looks like they tried to fix it in 2008 R2, because it now shares the FCB of the last user who opened the program file instead of the first, but it still crashes when they log off before another user grabs the ball.<br />
<br />
It seems like they forked in the wrong direction and locked themselves in a faulty design. <br />
<br />
<span style="color: red;"><b>Update - 2016.11.03</b></span> - The <a href="http://support.microsoft.com/kb/2536487" target="_blank">Microsoft KB article 2536487</a> states that Windows Server 2016 fixes this issue. If you have installed Windows 2016 and verified that this is fixed, I would love to hear from you in the comments. Thanks!<br />
<b><span style="color: red;"><br /></span></b>
<b><span style="color: red;">Update - 2012.05.01</span></b> - Multiple responders have reported that accessing the network files over a DFS share eliminates the FCB errors. See comments below.<br />
<br />
<b><span style="color: red;">Update - 2011.09.23</span></b> - We have had some success running the programs from a UNC path instead of using the mapped network drive. This is still in testing, but I believe you may also need to remove the mapped drive to eliminate the application crashes. If this works in your environment, please post back in the comments.Adrian Hayeshttp://www.blogger.com/profile/17084091939713264454noreply@blogger.com58tag:blogger.com,1999:blog-3228715591733432689.post-92002755037845906372010-02-01T13:28:00.005-05:002011-09-27T14:30:19.774-04:00Connect to a UNC path with security credentials<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script><P>I had an ASP.NET site where I wanted to access network resources, but did not have sufficient share permissions because the code ran under the ASP user. I also had a service that copied files every night between file shares in two different domains. I wanted a way to access remote resources without opening up security holes by changing permissions or running as a privileged user. Surprisingly, there is a lack of .Net managed code that will allow you to do this.</P>
<P>I have seen many coders who get around this problem via LogonUser() - programmatically log onto the box as a user who has the necessary privileges and perform the required task. This works fine if you grant the user local logon rights on the box. I'm not comfortable doing that on a public-facing box. I have also encountered code that shells out and performs a net use command. Tsk. So uncivilized. :)</P>
<P>The <span style="font-weight: bold;">NetUseAdd() </span>and <span style="font-weight: bold;">NetUseDel()</span> commands of <span style="font-weight: bold;">NetApi32.dll</span> provide a way to add access to a network resource with network credentials. This will allow you to run the process from whatever user you wish, but still access protected network resources.</P>
<P>The UNCAccessWithCredentials.cs class wraps these functions in an IDisposable class that allows you to encompass your code in a <span style="font-style: italic;">using</span> block. When you encounter the end of the block, the class disconnects from the resource and the connection is closed. If you need a persistent connection, call the <span style="font-style: italic;">NetUseWithCredentials</span> function, but remember to clean up your mess with the <span style="font-style: italic;">NetUseDelete</span> function.</P>
<P><span style="font-size: 130%;"><span style="font-weight: bold;">Example usage:</span></span></P>
<pre class="csharpcode"> 
<span class="kwrd">using</span> (UNCAccessWithCredentials unc = <span class="kwrd">new</span> UNCAccessWithCredentials())
{
<span class="kwrd">if</span> (unc.NetUseWithCredentials(UNCPath, UserName, Domain, Password))
{
<span class="rem">//Code that accesses the remote resource</span>
}
<span class="kwrd">else</span>
{
MessageBox.Show(<span class="str">"Failed to connect to "</span> + UNCPath + <span class="str">"\r\nLastError = "</span> + unc.LastError.ToString(),
<span class="str">"Failed to connect"</span>,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
</pre>
<span style="font-size: 130%; font-weight: bold;">UNCAccessWithCredentials.cs:</span><br />
<pre class="csharpcode"> 
<span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Runtime.InteropServices;
<span class="kwrd">using</span> BOOL = System.Boolean;
<span class="kwrd">using</span> DWORD = System.UInt32;
<span class="kwrd">using</span> LPWSTR = System.String;
<span class="kwrd">using</span> NET_API_STATUS = System.UInt32;
<span class="kwrd">namespace</span> ConnectUNCWithCredentials
{
<span class="kwrd">public</span> <span class="kwrd">class</span> UNCAccessWithCredentials : IDisposable
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
<span class="kwrd">internal</span> <span class="kwrd">struct</span> USE_INFO_2
{
<span class="kwrd">internal</span> LPWSTR ui2_local;
<span class="kwrd">internal</span> LPWSTR ui2_remote;
<span class="kwrd">internal</span> LPWSTR ui2_password;
<span class="kwrd">internal</span> DWORD ui2_status;
<span class="kwrd">internal</span> DWORD ui2_asg_type;
<span class="kwrd">internal</span> DWORD ui2_refcount;
<span class="kwrd">internal</span> DWORD ui2_usecount;
<span class="kwrd">internal</span> LPWSTR ui2_username;
<span class="kwrd">internal</span> LPWSTR ui2_domainname;
}
[DllImport(<span class="str">"NetApi32.dll"</span>, SetLastError = <span class="kwrd">true</span>, CharSet = CharSet.Unicode)]
<span class="kwrd">internal</span> <span class="kwrd">static</span> <span class="kwrd">extern</span> NET_API_STATUS NetUseAdd(
LPWSTR UncServerName,
DWORD Level,
<span class="kwrd">ref</span> USE_INFO_2 Buf,
<span class="kwrd">out</span> DWORD ParmError);
[DllImport(<span class="str">"NetApi32.dll"</span>, SetLastError = <span class="kwrd">true</span>, CharSet = CharSet.Unicode)]
<span class="kwrd">internal</span> <span class="kwrd">static</span> <span class="kwrd">extern</span> NET_API_STATUS NetUseDel(
LPWSTR UncServerName,
LPWSTR UseName,
DWORD ForceCond);
<span class="kwrd">private</span> <span class="kwrd">bool</span> disposed = <span class="kwrd">false</span>;
<span class="kwrd">private</span> <span class="kwrd">string</span> sUNCPath;
<span class="kwrd">private</span> <span class="kwrd">string</span> sUser;
<span class="kwrd">private</span> <span class="kwrd">string</span> sPassword;
<span class="kwrd">private</span> <span class="kwrd">string</span> sDomain;
<span class="kwrd">private</span> <span class="kwrd">int</span> iLastError;
<span class="rem">/// <summary></span>
<span class="rem">/// A disposeable class that allows access to a UNC resource with credentials.</span>
<span class="rem">/// </summary></span>
<span class="kwrd">public</span> UNCAccessWithCredentials()
{
}
<span class="rem">/// <summary></span>
<span class="rem">/// The last system error code returned from NetUseAdd or NetUseDel. Success = 0</span>
<span class="rem">/// </summary></span>
<span class="kwrd">public</span> <span class="kwrd">int</span> LastError
{
get { <span class="kwrd">return</span> iLastError; }
}
<span class="kwrd">public</span> <span class="kwrd">void</span> Dispose()
{
<span class="kwrd">if</span> (!<span class="kwrd">this</span>.disposed)
{
NetUseDelete();
}
disposed = <span class="kwrd">true</span>;
GC.SuppressFinalize(<span class="kwrd">this</span>);
}
<span class="rem">/// <summary></span>
<span class="rem">/// Connects to a UNC path using the credentials supplied.</span>
<span class="rem">/// </summary></span>
<span class="rem">/// <param name="UNCPath">Fully qualified domain name UNC path</param></span>
<span class="rem">/// <param name="User">A user with sufficient rights to access the path.</param></span>
<span class="rem">/// <param name="Domain">Domain of User.</param></span>
<span class="rem">/// <param name="Password">Password of User</param></span>
<span class="rem">/// <returns>True if mapping succeeds. Use LastError to get the system error code.</returns></span>
<span class="kwrd">public</span> <span class="kwrd">bool</span> NetUseWithCredentials(<span class="kwrd">string</span> UNCPath, <span class="kwrd">string</span> User, <span class="kwrd">string</span> Domain, <span class="kwrd">string</span> Password)
{
sUNCPath = UNCPath;
sUser = User;
sPassword = Password;
sDomain = Domain;
<span class="kwrd">return</span> NetUseWithCredentials();
}
<span class="kwrd">private</span> <span class="kwrd">bool</span> NetUseWithCredentials()
{
<span class="kwrd">uint</span> returncode;
<span class="kwrd">try</span>
{
USE_INFO_2 useinfo = <span class="kwrd">new</span> USE_INFO_2();
useinfo.ui2_remote = sUNCPath;
useinfo.ui2_username = sUser;
useinfo.ui2_domainname = sDomain;
useinfo.ui2_password = sPassword;
useinfo.ui2_asg_type = 0;
useinfo.ui2_usecount = 1;
<span class="kwrd">uint</span> paramErrorIndex;
returncode = NetUseAdd(<span class="kwrd">null</span>, 2, <span class="kwrd">ref</span> useinfo, <span class="kwrd">out</span> paramErrorIndex);
iLastError = (<span class="kwrd">int</span>)returncode;
<span class="kwrd">return</span> returncode == 0;
}
<span class="kwrd">catch</span>
{
iLastError = Marshal.GetLastWin32Error();
<span class="kwrd">return</span> <span class="kwrd">false</span>;
}
}
<span class="rem">/// <summary></span>
<span class="rem">/// Ends the connection to the remote resource </span>
<span class="rem">/// </summary></span>
<span class="rem">/// <returns>True if it succeeds. Use LastError to get the system error code</returns></span>
<span class="kwrd">public</span> <span class="kwrd">bool</span> NetUseDelete()
{
<span class="kwrd">uint</span> returncode;
<span class="kwrd">try</span>
{
returncode = NetUseDel(<span class="kwrd">null</span>, sUNCPath, 2);
iLastError = (<span class="kwrd">int</span>)returncode;
<span class="kwrd">return</span> (returncode == 0);
}
<span class="kwrd">catch</span>
{
iLastError = Marshal.GetLastWin32Error();
<span class="kwrd">return</span> <span class="kwrd">false</span>;
}
}
~UNCAccessWithCredentials()
{
Dispose();
}
}
}
</pre>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3959304-1");pageTracker._initData();pageTracker._trackPageview();
</script>Adrian Hayeshttp://www.blogger.com/profile/17084091939713264454noreply@blogger.com6tag:blogger.com,1999:blog-3228715591733432689.post-10541443536774663222008-09-06T13:59:00.011-04:002008-09-07T11:37:40.995-04:00Change Height of TextBoxes Using Font Size<script type="text/javascript"><br />var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");<br />document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));<br /></script><a href="http://www.freewebs.com/bears82199/code/SetTextBoxHeight.zip">Download sample code</a><br /><br />I had a c# project that required a single-line text box with adjustable height. I found many examples of how to adjust the width, but nothing on how to dynamically change the height of a text box. I did not want to use multi-line because I wanted to use the auto-complete features of the single-line text box.<br /><br />Single-line textbox height is set by the size of the font, not the TextBox.Height property. This makes it difficult if you are looking for an exact height. Luckily, the font property uses a float for the font size (emSize). You can use fractions of fonts to fine-tune the textbox height.<br /><br />The calculation the textbox uses to determine its height is:<span style="font-weight: bold;"><br /><br />Height</span> = <span style="font-weight: bold;">( </span><span style="font-weight: bold;">Font Size * Font Line Spacing / Font Em Height ) + 7</span><br /><ul><li><span style="font-weight: bold;">Font Size</span> - It is easiest to measure font in pixels so you do not have to factor in screen dpi.</li><li><span style="font-weight: bold;">Font Line Spacing</span> - The distance, in design units, between two consecutive lines of text.</li><li><span style="font-weight: bold;">Font Em Height</span> - height, in design units of the font's widest letter - typically the letter M.</li></ul>Text boxes have a 3-pixel lower and 4-pixel upper white space around the font height. Therefore, the calculation adjusts the height by 7 pixels.<br /><br />We can reverse this calculation to obtain the font size needed for a desired height:<span style="font-weight: bold;"><br /><br />Font Size</span> = <span style="font-weight: bold;">( </span><span style="font-weight: bold;">height</span><span style="font-weight: bold;"> - 7 ) * Font Em Height / Font Line Spacing</span><br /><br />This method will return a font object that will set the size of your text box:<br /><!-- code formatted by http://manoli.net/csharpformat/ --><br /><style type="text/css"><br />.csharpcode, .csharpcode pre<br />{<br /> font-size: small;<br /> color: green;<br /> font-family: Consolas, "Courier New", Courier, Monospace;<br /> background-color: #ffffff;<br /> /*white-space: pre;*/<br />}<br /><br />.csharpcode pre { margin: 0em; }<br /><br />.csharpcode .rem { color: #008000; }<br /><br />.csharpcode .kwrd { color: #0000ff; }<br /><br />.csharpcode .str { color: #006080; }<br /><br />.csharpcode .op { color: #0000c0; }<br /><br />.csharpcode .preproc { color: #cc6633; }<br /><br />.csharpcode .asp { background-color: #ffff00; }<br /><br />.csharpcode .html { color: #800000; }<br /><br />.csharpcode .attr { color: #ff0000; }<br /><br />.csharpcode .alt <br />{<br /> background-color: #f4f4f4;<br /> width: 100%;<br /> margin: 0em;<br />}<br /><br />.csharpcode .lnum { color: #606060; }<br /></style><br /><pre class="csharpcode"><br /><span class="kwrd">private</span> Font GetFontForTextBoxHeight(<span class="kwrd">int</span> TextBoxHeight)<br />{<br /> <span class="rem">// What is the target size of the text box?</span><br /> <span class="kwrd">float</span> desiredheight = (<span class="kwrd">float</span>)TextBoxHeight;<br /><br /> <span class="rem">// Set the font from the existing TextBox font.</span><br /> <span class="rem">// We use the fnt = new Font(...) method so we can ensure that</span><br /> <span class="rem">// we're setting the GraphicsUnit to Pixels. This avoids all</span><br /> <span class="rem">// the DPI conversions between point & pixel.</span><br /> Font fnt = <span class="kwrd">new</span> Font(textBox1.Font.FontFamily,<br /> textBox1.Font.Size,<br /> textBox1.Font.Style,<br /> GraphicsUnit.Pixel);<br /><br /> <span class="rem">// TextBoxes never size below 8 pixels. This consists of the</span><br /> <span class="rem">// 4 pixels above & 3 below of whitespace, and 1 pixel line of</span><br /> <span class="rem">// greeked text.</span><br /> <span class="kwrd">if</span> (desiredheight < 8)<br /> desiredheight = 8;<br /><br /> <span class="rem">// Determine the Em sizes of the font and font line spacing</span><br /> <span class="rem">// These values are constant for each font at the given font style.</span><br /> <span class="rem">// and screen DPI.</span><br /> <span class="kwrd">float</span> FontEmSize = fnt.FontFamily.GetEmHeight(fnt.Style);<br /> <span class="kwrd">float</span> FontLineSpacing = fnt.FontFamily.GetLineSpacing(fnt.Style);<br /><br /> <span class="rem">// emSize is the target font size. TextBoxes have a total of</span><br /> <span class="rem">// 7 pixels above and below the FontHeight of the font.</span><br /> <span class="kwrd">float</span> emSize = (desiredheight - 7) * FontEmSize / FontLineSpacing;<br /> <br /> <span class="rem">// Create the font, with the proper size to change the TextBox Height to the desired size.</span><br /> fnt = <span class="kwrd">new</span> Font(fnt.FontFamily, emSize, fnt.Style, GraphicsUnit.Pixel);<br /><br /> <span class="kwrd">return</span> fnt;<br />}</pre><br />Whenever you have to set the textbox size, set the font property using the above method:<br /><br /><span style="font-weight: bold;">TextBox.Font = GetFontForTextBoxHeight(int TextBoxHeight)</span><br /><br /><blockquote></blockquote><script type="text/javascript"><br />var pageTracker = _gat._getTracker("UA-3959304-1");<br />pageTracker._initData();<br />pageTracker._trackPageview();<br /></script>Adrian Hayeshttp://www.blogger.com/profile/17084091939713264454noreply@blogger.com0tag:blogger.com,1999:blog-3228715591733432689.post-80638556770073022052008-04-07T11:22:00.003-04:002008-04-07T12:57:22.252-04:00Good Hex Editor<span style="font-size:85%;"><span style="font-family:verdana;">Every once in a while, I need a hex editor to poke at a file. There are a lot of editors out there, and a lot of chaff among them. I have a few requirements for what constitutes a good hex editor:<br /></span></span><ul><li><span style="font-size:85%;"><span style="font-family:verdana;">Free - I don't use hex editors enough to justify a $40 editor.</span></span></li><li><span style="font-size:85%;"><span style="font-family:verdana;">GUI<br /></span></span></li><li><span style="font-size:85%;"><span style="font-family:verdana;">Unicode capabilities</span></span></li><li><span style="font-size:85%;"><span style="font-family:verdana;">byte-level editing</span></span></li><li><span style="font-size:85%;"><span style="font-family:verdana;">Cursor tracking between hex and text frames</span></span></li><li><span style="font-size:85%;"><span style="font-family:verdana;">hex and ASCII/Unicode text searches</span></span></li><li><span style="font-size:85%;"><span style="font-family:verdana;">File comparison - what has changed?</span></span></li></ul><span style="font-size:85%;"><span style="font-family:verdana;">I found one that covers most of these requirements, plus a few more neato features. If you haven't checked out <a href="http://www.chmaas.handshake.de/delphi/freeware/xvi32/xvi32.htm" target="_blank" >XVI32</a>, give it a try. I particularly like the wildcard search and replace function.<br /><br />The only thing I would like to see is a file comparison feature. It helps in hacking another program: save a copy of some program's data, then make a change through the program and compare with the reference file. There may be a way to do this through the scripting interface (another neat feature), but it would be nice to see that in the application.<br /></span></span><script type="text/javascript"><br />var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");<br />document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));<br /></script><script type="text/javascript"><br />var pageTracker = _gat._getTracker("UA-3959304-1");<br />pageTracker._initData();<br />pageTracker._trackPageview();<br /></script>Adrian Hayeshttp://www.blogger.com/profile/17084091939713264454noreply@blogger.com0tag:blogger.com,1999:blog-3228715591733432689.post-64148275429508317992008-03-24T15:58:00.011-04:002008-12-30T15:08:22.041-05:00Encheferizer<span style="font-size:85%;"><span style="font-family:trebuchet ms;">This is a VB.Net function that you can use to translate your message to Swedish Chef. It's great for error reporting! Paste this function into your VB.Net class. To use it, simply pass the text you want translated and it will return a string of "translated" text.<br /><br /><br /></span><a style="font-family: trebuchet ms;" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAXjXJ-WRS46VJsTnC3hE4axmPyBusXq86G4nJVhDv9rOlWPJ6ONrTXYGpnRnxoZSh8THMx33JcxVK-NQ90YwMOzftgaKiVZkTXDFl3MVTpA2Ygx2RpUh2A2QH3X6qdJ_FtCUWxJE2HZ0/s1600-h/SwedishChef.JPG"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAXjXJ-WRS46VJsTnC3hE4axmPyBusXq86G4nJVhDv9rOlWPJ6ONrTXYGpnRnxoZSh8THMx33JcxVK-NQ90YwMOzftgaKiVZkTXDFl3MVTpA2Ygx2RpUh2A2QH3X6qdJ_FtCUWxJE2HZ0/s320/SwedishChef.JPG" alt="" id="BLOGGER_PHOTO_ID_5181854004225284290" border="0" /></a></span><span style=";font-family:trebuchet ms;font-size:85%;" ><span style="font-weight: bold;">Sample Translation:</span><br /><span style="font-size:85%;">Zeees is a FB.Net fooncshun zeet yuoo cun use tu trunslete yuoor messege tu Svedeesh Cheff. It's greet fur irrur repurteeng! Peste zeees fooncshun intu yuoor FB.Net cless. Tu use it, seemply pess zee text yuoo vunt trunsleted und it veell retoorn a streeng ooff "trunsleted" text, Bork Bork Bork!</span></span><span style=";font-family:trebuchet ms;font-size:85%;" ><br /><br /><br /><br /><br /><br />Here is a sample application that uses the Encheferizer code. Enjoy!<br /></span><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://sites.google.com/site/bearnakedcode/bearnakedcode-files/EnCheferizer.zip?attredirects=0"><img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 48px; height: 48px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifGsxX3PlLoyJAUa1sAUVmZVKKzp1ywNt7mPsjJ5gJhusn6bL01L0XqomCMv4Bd4WJxO6YEu5onE5XyDeBrOF7CxSDCoBd3UXBBMyKORL4tVDgcFqObZv07ALYQmAVrSj9kRjHslBzGeg/s200/chef.JPG" alt="" id="BLOGGER_PHOTO_ID_5285665232753720578" border="0" /></a><a href="http://sites.google.com/site/bearnakedcode/bearnakedcode-files/EnCheferizer.zip?attredirects=0"><span style="font-size:130%;"><span style="font-weight: bold;font-family:arial;" >Encheferizer.zip</span></span></a><br /><span style="font-size:85%;"><p><br /></p><pre><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" ><br />Public</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Class</span><span style="font-size:100%;"> Encheferizer<br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >'Encheferize</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >'Adrian Hayes</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >' http://www.bearnakedcode.com<br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >' You are free to use this code as you wish. It is offered without<br />' warranty. Use at your own risk - especially if you have a touchy<br />' manager who would not appreciate funny error reports or easter eggs.<br />'</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >' If you publish its source (or any portion thereof), please include</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >' a reference back to http://www.bearnakedcode.com.</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >' Translate English text to "Swedish Chef" dialect</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >' Based on PHP Encheferize from Eric Bakker - <a style="color: rgb(0, 153, 0);" href="http://bork.eamelink.nl">http://bork.eamelink.nl</a><span style="color: rgb(0, 153, 0);"> </span></span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >' and original chef.x from John Hagerman</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >'</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >'Translation guide:</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >'an -> un -f -> ff th| -> t</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >'au -> oo -ir -> ur -tion -> shun</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >'a- -> e -I -> ee or I -u -> oo</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >'en -> ee -ow -> oo v -> f</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >'-ew -> oo |o -> oo w -> v</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >'</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >'"|" indicates a word boundary </span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >'"-" indicates in the middle of a word</span><span style="font-size:100%;"><br /><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Public</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Function</span><span style="font-size:100%;"> Encheferize</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >ByVal</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >text</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >As</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >String</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >As</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >String</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Dim</span><span style="font-size:100%;"> retval </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >As</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >String</span><span style="font-size:100%;"> </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >""</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >' return value</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >'separators is a character array used for searching the phrase for </span><span style="font-size:100%;"><br />?separating characters </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >to</span><span style="font-size:100%;"> find word boundaries<br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Dim</span><span style="font-size:100%;"> separators</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >As</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Char</span><span style="font-size:100%;"> </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> {vbCr</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> vbLf</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >" "</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >","</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"."</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >";"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >":"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"<"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >">"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"><br /></span><span style="color: rgb(255, 0, 0);font-size:100%;" >""</span><span style="color: rgb(255, 0, 0);font-size:100%;" >""</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"''"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"["</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"{"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"]"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"}"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"|"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"="</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"+"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"><br /></span><span style="color: rgb(255, 0, 0);font-size:100%;" >"-"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"_"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"!"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"@"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"#"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"$"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"%"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"^"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"&"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"><br /></span><span style="color: rgb(255, 0, 0);font-size:100%;" >"*"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"("</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >")"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"~"</span><span style="font-size:100%;">}<br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Dim</span><span style="font-size:100%;"> word </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >As</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >String</span><span style="font-size:100%;"> </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >""</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Dim</span><span style="font-size:100%;"> rand </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >As</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >New</span><span style="font-size:100%;"> Random<br /><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Dim</span><span style="font-size:100%;"> c </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >As</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Char</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >For</span><span style="font-size:100%;"> i </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >As</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Long</span><span style="font-size:100%;"> </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >0</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >To</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >text</span><span style="color: rgb(0, 140, 0);font-size:100%;" >.</span><span style="font-size:100%;">Length<br />c </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >""</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" ><</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >text</span><span style="color: rgb(0, 140, 0);font-size:100%;" >.</span><span style="font-size:100%;">Length </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Then</span><span style="font-size:100%;"><br />c </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >text</span><span style="color: rgb(0, 140, 0);font-size:100%;" >.</span><span style="font-size:100%;">Substring</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="font-size:100%;">i</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >1</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >' set c to the i'th character in the text</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Char</span><span style="color: rgb(0, 140, 0);font-size:100%;" >.</span><span style="font-size:100%;">IsLetter</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="font-size:100%;">c</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Then</span><span style="font-size:100%;"><br />word </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> c<br />Continue </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >For</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Else</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Array</span><span style="color: rgb(0, 140, 0);font-size:100%;" >.</span><span style="font-size:100%;">IndexOf</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="font-size:100%;">separators</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> c</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"> </span><span style="color: rgb(48, 128, 128);font-size:100%;" >></span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >0</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Or</span><span style="font-size:100%;"> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >text</span><span style="color: rgb(0, 140, 0);font-size:100%;" >.</span><span style="font-size:100%;">Length </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Then</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >' word found - send for "translation"</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"> word</span><span style="color: rgb(0, 140, 0);font-size:100%;" >.</span><span style="font-size:100%;">Length </span><span style="color: rgb(48, 128, 128);font-size:100%;" >></span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >0</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Then</span><span style="font-size:100%;"> <br /> retval </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> EncheferizeWord</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="font-size:100%;">word</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"><br /> word </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >""</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'"25% chance of ending a sentance with "Bork Bork Bork!"</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"> </span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="font-size:100%;">c </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"."</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Or</span><span style="font-size:100%;"> c </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"!"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >And</span><span style="font-size:100%;"> rand</span><span style="color: rgb(0, 140, 0);font-size:100%;" >.</span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Next</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="color: rgb(0, 140, 0);font-size:100%;" >0</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >4</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"> </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >1</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Then</span><span style="font-size:100%;"><br /> retval </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >", Bork Bork Bork!"</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Else</span><span style="font-size:100%;"><br /> retval </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> c<br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Else</span><span style="font-size:100%;"><br /> word </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> c<br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Next</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Return</span><span style="font-size:100%;"> retval<br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Function</span><span style="font-size:100%;"><br /><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Public</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Function</span><span style="font-size:100%;"> EncheferizeWord</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >ByVal</span><span style="font-size:100%;"> word </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >As</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >String</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >As</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >String</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Dim</span><span style="font-size:100%;"> retval </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >As</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >String</span><span style="font-size:100%;"> </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >""</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'return value</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Dim</span><span style="font-size:100%;"> i </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >As</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Integer</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'tracks character position within word</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Dim</span><span style="font-size:100%;"> c </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >As</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Char</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'character currently under evaluation</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Dim</span><span style="font-size:100%;"> nc </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >As</span><span style="font-size:100%;"> Cha </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'next character - if empty, then c is the </span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'last character in the word.</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Dim</span><span style="font-size:100%;"> biseen </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >As</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Boolean</span><span style="font-size:100%;"> </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(15, 77, 117);font-size:100%;" >False</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'used to insure we don't replace</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'"i" with "ee" more than once in a word.</span><span style="font-size:100%;"><br /><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"> word</span><span style="color: rgb(0, 140, 0);font-size:100%;" >.</span><span style="font-size:100%;">ToLower </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"bork"</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Then</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'why improve perfection? :)</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Return</span><span style="font-size:100%;"> word<br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"><br /><br />i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >0</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >' Get the character at position i.</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >' if not the last character, then get the next character as well</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >While</span><span style="font-size:100%;"> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" ><</span><span style="font-size:100%;"> word</span><span style="color: rgb(0, 140, 0);font-size:100%;" >.</span><span style="font-size:100%;">Length<br />c </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> word</span><span style="color: rgb(0, 140, 0);font-size:100%;" >.</span><span style="font-size:100%;">Substring</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="font-size:100%;">i</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >1</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" ><</span><span style="font-size:100%;"> word</span><span style="color: rgb(0, 140, 0);font-size:100%;" >.</span><span style="font-size:100%;">Length </span><span style="color: rgb(48, 128, 128);font-size:100%;" >-</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >1</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Then</span><span style="font-size:100%;"><br />nc </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> word</span><span style="color: rgb(0, 140, 0);font-size:100%;" >.</span><span style="font-size:100%;">Substring</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="font-size:100%;">i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >1</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >1</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Else</span><span style="font-size:100%;"><br />nc </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >""</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"><br /><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >'"The" -> "Zee" "Put the cake in the oven" -> "Poot zee ceke in zee oofee"</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"> word</span><span style="color: rgb(0, 140, 0);font-size:100%;" >.</span><span style="font-size:100%;">ToLower </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"the"</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Then</span><span style="font-size:100%;"><br />retval </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> MatchCase</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="font-size:100%;">c</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"z"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"> </span><span style="color: rgb(48, 128, 128);font-size:100%;" >&</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"ee"</span><span style="font-size:100%;"><br />i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >3</span><span style="font-size:100%;"><br />Continue </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >While</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"><br /><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >'If the first character</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >0</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Then</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Select</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Case</span><span style="font-size:100%;"> c<br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Case</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"E"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"e"</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'"e" -> "i"; "East" -> "Iest"</span><span style="font-size:100%;"><br /> retval </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> MatchCase</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="font-size:100%;">c</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"i"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"><br /> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >1</span><span style="font-size:100%;"><br /> Continue </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >While</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Case</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"o"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"O"</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'"o" -> "oo"; "Open" -> "Oopin"</span><span style="font-size:100%;"><br /> retval </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> MatchCase</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="font-size:100%;">c</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"o"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"> </span><span style="color: rgb(48, 128, 128);font-size:100%;" >&</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"o"</span><span style="font-size:100%;"><br /> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >1</span><span style="font-size:100%;"><br /> Continue </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >While</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Select</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Else</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >' not the first character</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Select</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Case</span><span style="font-size:100%;"> c<br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Case</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"e"</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"> nc </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"w"</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Then</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'"ew" -> "oo"; "new" -> "noo"</span><span style="font-size:100%;"><br /> retval </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"oo"</span><span style="font-size:100%;"><br /> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >2</span><span style="font-size:100%;"><br /> Continue </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >While</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"> nc </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >""</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Then</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'"e<end>" -> "e-a"; "gone" -> "gune-a"</end></span><span style="font-size:100%;"><br /> retval </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"e-a"</span><span style="font-size:100%;"><br /> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >1</span><span style="font-size:100%;"><br /> Continue </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >While</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Case</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"f"</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'"f" -> "ff"; "of" -> "ooff"</span><span style="font-size:100%;"><br /> retval </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"ff"</span><span style="font-size:100%;"><br /> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >1</span><span style="font-size:100%;"><br /> Continue </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >While</span><span style="font-size:100%;"><br /><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Case</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"i"</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"> nc </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"r"</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Then</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'"ir" -> "ur"; "fire" -> "fure-a"</span><span style="font-size:100%;"><br /> retval </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"ur"</span><span style="font-size:100%;"><br /> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >2</span><span style="font-size:100%;"><br /> Continue </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >While</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'If we've not replaced an "i" before. Prevents too many "ee"'s in a word.</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Not</span><span style="font-size:100%;"> biseen </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Then</span><span style="font-size:100%;"><br /> retval </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"ee"</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'"i" -> "ee"; "bid" -> "beed"</span><span style="font-size:100%;"><br /> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >1</span><span style="font-size:100%;"><br /> biseen </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(15, 77, 117);font-size:100%;" >True</span><span style="font-size:100%;"><br /> Continue </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >While</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"><br /><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Case</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"o"</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"> nc </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"w"</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Then</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'"ow" -> "oo"; "Owl" -> "Oowl"</span><span style="font-size:100%;"><br /> retval </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"oo"</span><span style="font-size:100%;"><br /> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >2</span><span style="font-size:100%;"><br /> Continue </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >While</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Else</span><span style="font-size:100%;"><br /> retval </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"u"</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'"o" -> "u"; "tool" -> "tuul"</span><span style="font-size:100%;"><br /> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >1</span><span style="font-size:100%;"><br /> Continue </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >While</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"><br /><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Case</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"t"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"s"</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" ><</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> word</span><span style="color: rgb(0, 140, 0);font-size:100%;" >.</span><span style="font-size:100%;">Length </span><span style="color: rgb(48, 128, 128);font-size:100%;" >-</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >4</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Then</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'"-sion" or "-tion" -> "-shun"; "compulsion" -> "cumpoolshun"</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"> word</span><span style="color: rgb(0, 140, 0);font-size:100%;" >.</span><span style="font-size:100%;">Substring</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="font-size:100%;">i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >1</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >3</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"> </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"ion"</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Then</span><span style="font-size:100%;"><br /> retval </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"shun"</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"Action"</span><span style="font-size:100%;"> </span><span style="color: rgb(48, 128, 128);font-size:100%;" >-</span><span style="color: rgb(48, 128, 128);font-size:100%;" >></span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"Ecshun"</span><span style="font-size:100%;"><br /> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >4</span><span style="font-size:100%;"><br /> Continue </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >While</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Case</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"U"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"u"</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'"u" -> "oo"; "bun" -> "boon"</span><span style="font-size:100%;"><br /> retval </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> MatchCase</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="font-size:100%;">c</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"o"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"> </span><span style="color: rgb(48, 128, 128);font-size:100%;" >&</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"o"</span><span style="font-size:100%;"><br /> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >1</span><span style="font-size:100%;"><br /> Continue </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >While</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Select</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"><br /><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >' characters that may be replaced anywhere</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Select</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Case</span><span style="font-size:100%;"> c<br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Case</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"A"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"a"</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Select</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Case</span><span style="font-size:100%;"> nc<br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Case</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"n"</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'"an" -> "un"; "American" -> "Emereecun"</span><span style="font-size:100%;"><br /> retval </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> MatchCase</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="font-size:100%;">c</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"u"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"> </span><span style="color: rgb(48, 128, 128);font-size:100%;" >&</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"n"</span><span style="font-size:100%;"><br /> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >2</span><span style="font-size:100%;"><br /> Continue </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >While</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Case</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"u"</span><span style="font-size:100%;"><br /> retval </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> MatchCase</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="font-size:100%;">c</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"o"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"> </span><span style="color: rgb(48, 128, 128);font-size:100%;" >&</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"o"</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'"au" -> "ao"; "because" -> "becoose"</span><span style="font-size:100%;"><br /> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >2</span><span style="font-size:100%;"><br /> Continue </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >While</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Case</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >""</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'do default action if "a" is last character</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Case</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Else</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >' "a" is not last character and nc <> "n" or "u"</span><span style="font-size:100%;"><br /> retval </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> MatchCase</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="font-size:100%;">c</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"e"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'"a" -> "e"; "easy" -> "iesy"</span><span style="font-size:100%;"><br /> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >1</span><span style="font-size:100%;"><br /> Continue </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >While</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Select</span><span style="font-size:100%;"><br /><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Case</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"e"</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"> nc </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"n"</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >And</span><span style="font-size:100%;"> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> word</span><span style="color: rgb(0, 140, 0);font-size:100%;" >.</span><span style="font-size:100%;">Length </span><span style="color: rgb(48, 128, 128);font-size:100%;" >-</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >2</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Then</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'"en" -> "ee"; "golden" -> "guldee"</span><span style="font-size:100%;"><br /> retval </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"ee"</span><span style="font-size:100%;"><br /> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >2</span><span style="font-size:100%;"><br /> Continue </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >While</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Else</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >' do nothing - use existing character</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"><br /><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Case</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"T"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"t"</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"> nc </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"h"</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Then</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> word</span><span style="color: rgb(0, 140, 0);font-size:100%;" >.</span><span style="font-size:100%;">Length </span><span style="color: rgb(48, 128, 128);font-size:100%;" >-</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >2</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Then</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >' If "th" at end of word, "th" -> "t"; "worth" -> "vurt"</span><span style="font-size:100%;"><br /> retval </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> MatchCase</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="font-size:100%;">c</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"t"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"><br /> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >2</span><span style="font-size:100%;"><br /> Continue </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >While</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Else</span><span style="font-size:100%;"> <br /> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >' If "th" not at end of word, "th" -> "ze"; "this" -> "zeees"</span><span style="font-size:100%;"><br /> retval </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> MatchCase</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="font-size:100%;">c</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"z"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"> </span><span style="color: rgb(48, 128, 128);font-size:100%;" >&</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"e"</span><span style="font-size:100%;"><br /> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >2</span><span style="font-size:100%;"><br /> Continue </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >While</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"><br /> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"><br /><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Case</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"V"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"v"</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'"v" -> "f"; "fever" -> "fefer"</span><span style="font-size:100%;"><br /> retval </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> MatchCase</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="font-size:100%;">c</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"f"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"><br /> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >1</span><span style="font-size:100%;"><br /> Continue </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >While</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Case</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"W"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"w"</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 128, 0);font-size:100%;" >'"w" -> "v"; "worth" -> "vurt"</span><span style="font-size:100%;"><br /> retval </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> MatchCase</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="font-size:100%;">c</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(255, 0, 0);font-size:100%;" >"v"</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"><br /> i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >1</span><span style="font-size:100%;"><br /> Continue </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >While</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Select</span><span style="font-size:100%;"><br /><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >' Default behavior is to replace character with character.</span><span style="font-size:100%;"><br />retval </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> c<br />i </span><span style="color: rgb(48, 128, 128);font-size:100%;" >+</span><span style="color: rgb(48, 128, 128);font-size:100%;" >=</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 140, 0);font-size:100%;" >1</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >While</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Return</span><span style="font-size:100%;"> retval<br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Function</span><span style="font-size:100%;"><br /><br /><br /></span><span style="color: rgb(0, 128, 0);font-size:100%;" >'MatchCase returns the resultant, in the same case of the determinate</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Private</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Function</span><span style="font-size:100%;"> MatchCase</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >ByVal</span><span style="font-size:100%;"> determinate </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >As</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Char</span><span style="color: rgb(48, 128, 128);font-size:100%;" >,</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >ByVal</span><span style="font-size:100%;"> resultant </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >As</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Char</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >As</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Char</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Char</span><span style="color: rgb(0, 140, 0);font-size:100%;" >.</span><span style="font-size:100%;">IsUpper</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="font-size:100%;">determinate</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Then</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Return</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Char</span><span style="color: rgb(0, 140, 0);font-size:100%;" >.</span><span style="font-size:100%;">ToUpper</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="font-size:100%;">resultant</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Else</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Return</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Char</span><span style="color: rgb(0, 140, 0);font-size:100%;" >.</span><span style="font-size:100%;">ToLower</span><span style="color: rgb(48, 128, 128);font-size:100%;" >(</span><span style="font-size:100%;">resultant</span><span style="color: rgb(48, 128, 128);font-size:100%;" >)</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >If</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Function</span><span style="font-size:100%;"><br /></span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >End</span><span style="font-size:100%;"> </span><span style="color: rgb(0, 0, 255); font-weight: bold;font-size:100%;" >Class</span></pre></span>Adrian Hayeshttp://www.blogger.com/profile/17084091939713264454noreply@blogger.com0