<br>Hi Michael. It depends on what you want to achieve - a challenging programming exercise*, or a desired outcome.  If you just want validated input, I&#39;d say the input mask is far easier and more elegant.<br><br>Preventing invalid data getting in is better than detecting and curing it  :-)<br>


<br>*Yes, I know about programming for sheer problem-solving fun rather than achieving a practical outcome. Many moons ago I reverse-engineered Microsoft Excel in Quickbasic (in DOS), and learned a lot about sparse arrays, stacks, sorting and formula parsing in the process.  Mind you, my version of Excel took about a day to calculate =A1+(B1*C1).<br>


<br>Those were fun days  :-)  <br><br><div class="gmail_quote">On 7 May 2012 13:32, Michael Wooldridge <span dir="ltr">&lt;<a href="mailto:mwo@mornsc.vic.edu.au" target="_blank">mwo@mornsc.vic.edu.au</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div link="blue" vlink="purple" lang="EN-AU"><div><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">I assume you are referring to a MaskedTextBox. That works but it’s kind of cheating isn’t it?<u></u><u></u></span></p>


<div><p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><b><span style="font-size:14.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"><img src="" alt="Description: signiture" height="86" width="194"><u></u><u></u></span></b></p>


<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d" lang="EN-US"><u></u> <u></u></span></b></p><p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d" lang="EN-US">&quot;It is the tragedy of the world that no one knows what he doesn&#39;t know - and the less a man knows, the more sure he is that he knows everything&quot; </span></b><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d" lang="EN-US">Joyce Cary.<u></u><u></u></span></p>


<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d" lang="EN-US"><u></u> <u></u></span></p><p class="MsoNormal"><b><span style="font-size:14.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d" lang="EN-US">Michael Wooldridge<u></u><u></u></span></b></p>


<p class="MsoNormal"><span style="font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#4f6228" lang="EN-US">Information Technology Coordinator<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:8.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d" lang="EN-US">Mornington Secondary College<u></u><u></u></span></p>


<p class="MsoNormal"><span style="font-size:8.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d" lang="EN-US">1051 Nepean Highway, Mornington 3931<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:8.0pt;font-family:Wingdings;color:#1f497d" lang="EN-US">(</span><span style="font-size:8.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d" lang="EN-US">: <a href="tel:03%2059700250" value="+61359700250" target="_blank">03 59700250</a> </span><span style="font-size:8.0pt;font-family:&quot;Wingdings 2&quot;;color:#1f497d" lang="EN-US">6</span><span style="font-size:8.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d" lang="EN-US">: <a href="tel:03%2059700299" value="+61359700299" target="_blank">03 59700299</a><u></u><u></u></span></p>


<p class="MsoNormal"><span style="font-size:8.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d" lang="EN-US"><a href="mailto:mwo@mornsc.vic.edu.au" target="_blank">mwo@mornsc.vic.edu.au</a><u></u><u></u></span></p>


<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><b><span style="font-size:9.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Important - </span></b><span style="font-size:9.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">This email and any attachments may be confidential. If received in error, please contact us and delete all copies. Before opening or using attachments check them for viruses and defects. Regardless of any loss, damage or consequence, whether caused by the negligence of the sender or not, resulting directly or indirectly from the use of any attached files our liability is limited to resupplying any affected attachments. Any representations or opinions expressed are those of the individual sender, and not necessarily those of the Department of Education and Early Childhood Development. There, that just about covers everyone&#39;s arse but yours, sorry.<u></u><u></u></span></p>


<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"><u></u> <u></u></span></p></div><p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;" lang="EN-US">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;" lang="EN-US"> <a href="mailto:sofdev-bounces@edulists.com.au" target="_blank">sofdev-bounces@edulists.com.au</a> [mailto:<a href="mailto:sofdev-bounces@edulists.com.au" target="_blank">sofdev-bounces@edulists.com.au</a>] <b>On Behalf Of </b>Mark KELLY<br>


<b>Sent:</b> Monday, 7 May 2012 11:57 AM</span></p><div><br><b>To:</b> Year 12 Software Development Teachers&#39; Mailing List<br></div><b>Subject:</b> Re: [Year 12 SofDev] help<u></u><u></u><p></p><div><div>
<p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal" style="margin-bottom:12.0pt">Have you thought about using an input mask?<u></u><u></u></p></div></div><div><div><div><p class="MsoNormal">On 7 May 2012 10:04, Michael Wooldridge &lt;<a href="mailto:mwo@mornsc.vic.edu.au" target="_blank">mwo@mornsc.vic.edu.au</a>&gt; wrote:<u></u><u></u></p>


</div></div><div><div><div><div><p class="MsoNormal">Hi guys,<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal" style="text-autospace:none">I need help. Trying to write validation code that limits a text box entry to numerical and one decimal place only (and only two decimal places after the point, as in cash). The following code works fine except that it allows me to enter letters. The problem seems to be this line: <span style="font-size:9.5pt;font-family:Consolas;color:blue">If</span><span style="font-size:9.5pt;font-family:Consolas"> <span style="color:blue">Not</span> <span style="color:blue">Char</span>.IsDigit(e.KeyChar) Then <span style="color:green">&#39;if not a digit</span></span><u></u><u></u></p>


<p class="MsoNormal" style="text-autospace:none">To me, initially, I would have thought it should read: <span style="font-size:9.5pt;font-family:Consolas;color:blue">If</span><span style="font-size:9.5pt;font-family:Consolas"> <span style="color:blue">Not</span> e.KeyChar.IsDigit(e.KeyChar) <span style="color:blue">Then</span> <span style="color:green">&#39;if not a digit </span></span>but VB won’t let me do that<span style="font-size:9.5pt;font-family:Consolas"> </span>and keeps telling me<span style="font-size:9.5pt;font-family:Consolas"> to change it back to “Char” </span><u></u><u></u></p>


<p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">I can’t figure out why! Strangely, if a number is entered in the text box first, then I try to type over it with letters, it works perfectly. <u></u><u></u></p>


<p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">If anyone can solve this for me or has a better way of doing it your suggestions would be much appreciated.<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p>


<p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas">    <span style="color:blue">Private</span> <span style="color:blue">Sub</span> TextBox2_KeyPress(<span style="color:blue">ByVal</span> sender <span style="color:blue">As</span> <span style="color:blue">Object</span>, <span style="color:blue">ByVal</span> e <span style="color:blue">As</span> System.Windows.Forms.<span style="color:#2b91af">KeyPressEventArgs</span>) <span style="color:blue">Handles</span> TextBox2.KeyPress</span><u></u><u></u></p>


<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas"> </span><u></u><u></u></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas">        <span style="color:blue">If</span> <span style="color:blue">Not</span> <span style="color:blue">Char</span>.IsDigit(e.KeyChar) <span style="color:blue">Then</span> <span style="color:green">&#39;if not a digit</span></span><u></u><u></u></p>


<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas">            <span style="color:blue">If</span> <span style="color:blue">Not</span> Asc(e.KeyChar) = 8 <span style="color:blue">Then</span> <span style="color:green">&#39;and not a backspace</span></span><u></u><u></u></p>


<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas">                <span style="color:blue">If</span> <span style="color:blue">Not</span> TextBox2.Text.LastIndexOf(Chr(46)) = -1 <span style="color:blue">Then</span> <span style="color:green">&#39;and a decimal has already been added, dont allow</span></span><u></u><u></u></p>


<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas">                    e.Handled = <span style="color:blue">True</span></span><u></u><u></u></p><p class="MsoNormal" style="text-autospace:none">


<span style="font-size:9.5pt;font-family:Consolas">                    MsgBox(<span style="color:#a31515">&quot;numbers only&quot;</span>)</span><u></u><u></u></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas">                <span style="color:blue">End</span> <span style="color:blue">If</span></span><u></u><u></u></p>


<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas">            <span style="color:blue">End</span> <span style="color:blue">If</span></span><u></u><u></u></p><p class="MsoNormal" style="text-autospace:none">


<span style="font-size:9.5pt;font-family:Consolas">        <span style="color:blue">Else</span> <span style="color:green">&#39;if a digit compare index of decimal point (if it exists) and length of text</span></span><u></u><u></u></p>


<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas">            <span style="color:blue">If</span> <span style="color:blue">Not</span> TextBox2.Text.LastIndexOf(Chr(46)) = -1 <span style="color:blue">Then</span></span><u></u><u></u></p>


<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas">                <span style="color:blue">If</span> TextBox2.TextLength &gt; TextBox2.Text.LastIndexOf(Chr(46)) + 2 <span style="color:blue">Then</span></span><u></u><u></u></p>


<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas">                    <span style="color:green">&#39;if length is over 2 spaces from the decimal point, dont allow </span></span><u></u><u></u></p>


<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas">                    e.Handled = <span style="color:blue">True</span></span><u></u><u></u></p><p class="MsoNormal" style="text-autospace:none">


<span style="font-size:9.5pt;font-family:Consolas">                    MsgBox(<span style="color:#a31515">&quot;only two decimal places allowed&quot;</span>)</span><u></u><u></u></p><p class="MsoNormal" style="text-autospace:none">


<span style="font-size:9.5pt;font-family:Consolas">                <span style="color:blue">End</span> <span style="color:blue">If</span></span><u></u><u></u></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas">            <span style="color:blue">End</span> <span style="color:blue">If</span></span><u></u><u></u></p>


<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas"> </span><u></u><u></u></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas">        <span style="color:blue">End</span> <span style="color:blue">If</span></span><u></u><u></u></p>


<p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas"> </span><u></u><u></u></p><p class="MsoNormal" style="text-autospace:none"><span style="font-size:9.5pt;font-family:Consolas">    <span style="color:blue">End</span> <span style="color:blue">Sub</span></span><u></u><u></u></p>


<p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal"><u></u><u></u></p><p class="MsoNormal"><b><span lang="EN-US"> </span></b><u></u><u></u></p></div></div><p class="MsoNormal">


<b><span lang="EN-US">&quot;It is the tragedy of the world that no one knows what he doesn&#39;t know - and the less a man knows, the more sure he is that he knows everything&quot; </span></b><span lang="EN-US">Joyce Cary.</span><u></u><u></u></p>


<div><div><p class="MsoNormal"><span lang="EN-US"> </span><u></u><u></u></p><p class="MsoNormal"><b><span style="font-size:14.0pt" lang="EN-US">Michael Wooldridge</span></b><u></u><u></u></p><p class="MsoNormal">
<span style="color:#4f6228" lang="EN-US">Information Technology Coordinator</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:8.0pt" lang="EN-US">Mornington Secondary College</span><u></u><u></u></p><p class="MsoNormal">


<span style="font-size:8.0pt" lang="EN-US">1051 Nepean Highway, Mornington 3931</span><u></u><u></u></p><p class="MsoNormal"><span style="font-size:8.0pt;font-family:Wingdings" lang="EN-US">(</span><span style="font-size:8.0pt" lang="EN-US">: <a href="tel:03%2059700250" target="_blank">03 59700250</a> </span><span style="font-size:8.0pt;font-family:&quot;Wingdings 2&quot;" lang="EN-US">6</span><span style="font-size:8.0pt" lang="EN-US">: <a href="tel:03%2059700299" target="_blank">03 59700299</a></span><u></u><u></u></p>


<p class="MsoNormal"><span style="font-size:8.0pt" lang="EN-US"><a href="mailto:mwo@mornsc.vic.edu.au" target="_blank">mwo@mornsc.vic.edu.au</a></span><u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">


<b><span style="font-size:9.0pt">Important - </span></b><span style="font-size:9.0pt">This email and any attachments may be confidential. If received in error, please contact us and delete all copies. Before opening or using attachments check them for viruses and defects. Regardless of any loss, damage or consequence, whether caused by the negligence of the sender or not, resulting directly or indirectly from the use of any attached files our liability is limited to resupplying any affected attachments. Any representations or opinions expressed are those of the individual sender, and not necessarily those of the Department of Education and Early Childhood Development. There, that just about covers everyone&#39;s arse but yours, sorry.</span><u></u><u></u></p>


<p class="MsoNormal"> <u></u><u></u></p></div></div></div></div><div><div><p class="MsoNormal"><br>_______________________________________________<br><a href="http://www.edulists.com.au" target="_blank">http://www.edulists.com.au</a> - FAQ, Subscribe, Unsubscribe<br>


IT Software Development Mailing List kindly supported by<br><a href="http://www.vcaa.vic.edu.au" target="_blank">http://www.vcaa.vic.edu.au</a> - Victorian Curriculum and Assessment Authority and<br><a href="http://www.vcaa.vic.edu.au/vce/studies/infotech/softwaredevel3-4.html" target="_blank">http://www.vcaa.vic.edu.au/vce/studies/infotech/softwaredevel3-4.html</a><br>


<a href="http://www.vitta.org.au" target="_blank">http://www.vitta.org.au</a>  - VITTA Victorian Information Technology Teachers Association Inc<br><a href="http://www.swinburne.edu.au/ict/schools" target="_blank">http://www.swinburne.edu.au/ict/schools</a> - Swinburne University<u></u><u></u></p>


</div></div></div><div><div><p class="MsoNormal" style="margin-bottom:12.0pt"><br><br clear="all"><br>-- <br>Mark Kelly<br>Manager of ICT, Reporting, IT Learning Area<br>McKinnon Secondary College<br>McKinnon Rd McKinnon 3204, Victoria, Australia<br>


Direct line / Voicemail: <a href="tel:%2B613%208520%209085" value="+61385209085" target="_blank">+613 8520 9085</a>, Fax <a href="tel:%2B613%209578%209253" value="+61395789253" target="_blank">+613 9578 9253</a><br><a href="mailto:kel@mckinnonsc.vic.edu.au" target="_blank">kel@mckinnonsc.vic.edu.au</a> (don&#39;t use my Edumail account!)<br>


VCE IT Lecture Notes: <a href="http://vceit.com" target="_blank">http://vceit.com</a><br>Moderator: IT Applications Edulist<br><br>--<br>An E-flat, a C, and a G go into a bar. The bartender says, &quot;I&#39;m sorry, but I can&#39;t serve minors.&quot;<br>


<br><u></u><u></u></p></div></div></div></div><br>_______________________________________________<br>
<a href="http://www.edulists.com.au" target="_blank">http://www.edulists.com.au</a> - FAQ, Subscribe, Unsubscribe<br>
IT Software Development Mailing List kindly supported by<br>
<a href="http://www.vcaa.vic.edu.au" target="_blank">http://www.vcaa.vic.edu.au</a> - Victorian Curriculum and Assessment Authority and<br>
<a href="http://www.vcaa.vic.edu.au/vce/studies/infotech/softwaredevel3-4.html" target="_blank">http://www.vcaa.vic.edu.au/vce/studies/infotech/softwaredevel3-4.html</a><br>
<a href="http://www.vitta.org.au" target="_blank">http://www.vitta.org.au</a>  - VITTA Victorian Information Technology Teachers Association Inc<br>
<a href="http://www.swinburne.edu.au/ict/schools" target="_blank">http://www.swinburne.edu.au/ict/schools</a> - Swinburne University<br></blockquote></div><br><br clear="all"><br>-- <br>Mark Kelly<br>Manager of ICT, Reporting, IT Learning Area<br>


McKinnon Secondary College<br>McKinnon Rd McKinnon 3204, Victoria, Australia<br>Direct line / Voicemail: <a href="tel:%2B613%208520%209085" value="+61385209085" target="_blank">+613 8520 9085</a>, Fax <a href="tel:%2B613%209578%209253" value="+61395789253" target="_blank">+613 9578 9253</a><br>

<a href="mailto:kel@mckinnonsc.vic.edu.au" target="_blank">kel@mckinnonsc.vic.edu.au</a> (don&#39;t use my Edumail account!)<br>
VCE IT Lecture Notes: <a href="http://vceit.com" target="_blank">http://vceit.com</a><br>Moderator: IT Applications Edulist<br><br>--<br>An E-flat, a C, and a G go into a bar. The bartender says, &quot;I&#39;m sorry, but I can&#39;t serve minors.&quot;<br>


<br><br>