<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style>
<!--
@font-face
        {font-family:Wingdings}
@font-face
        {font-family:Wingdings}
@font-face
        {font-family:Calibri}
@font-face
        {font-family:Tahoma}
@font-face
        {font-family:Consolas}
@font-face
        {font-family:"Wingdings 2"}
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif"}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif"}
span.EmailStyle17
        {font-family:"Calibri","sans-serif";
        color:windowtext}
span.BalloonTextChar
        {font-family:"Tahoma","sans-serif"}
.MsoChpDefault
        {font-family:"Calibri","sans-serif"}
@page WordSection1
        {margin:72.0pt 72.0pt 72.0pt 72.0pt}
-->
</style><style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1" lang="EN-AU" link="blue" vlink="purple">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">hi Michael,<br>
<br>
this is how i'd do the dec. place bit<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim i As Integer<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim length as integer = Len(TextBox1.Text)<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' validate dec place<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i = 1 To length<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Mid(TextBox1.Text, i, 1) = &quot;.&quot; Then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If length - i &gt; 2 Then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox(&quot;too many places&quot;)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<br>
<br>
cheers<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Gordon<br>
<br>
<div><br>
<div style="font-family: Tahoma; font-size: 13px;"><font style="font-weight: bold;" size="2"><span style="font-family: Arial;">-----------</span><br style="font-family: Arial;">
<span style="font-family: Arial;">Gordon Poultney</span><br style="font-family: Arial;">
<span style="font-family: Arial;">Horsham College</span></font><br>
</div>
</div>
<div style="font-family: Times New Roman; color: rgb(0, 0, 0); font-size: 16px;">
<hr tabindex="-1">
<div style="direction: ltr;" id="divRpF783063"><font face="Tahoma" color="#000000" size="2"><b>From:</b> sofdev-bounces@edulists.com.au [sofdev-bounces@edulists.com.au] on behalf of Michael Wooldridge [mwo@mornsc.vic.edu.au]<br>
<b>Sent:</b> Monday, 7 May 2012 10:04 AM<br>
<b>To:</b> Year 12 Software Development Teachers' Mailing List<br>
<b>Subject:</b> [Year 12 SofDev] help<br>
</font><br>
</div>
<div></div>
<div>
<div class="WordSection1">
<p class="MsoNormal">Hi guys,</p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal" style="">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;">
'if not a digit</span></span></p>
<p class="MsoNormal" style="">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;">'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></p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">&nbsp;</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.
</p>
<p class="MsoNormal">&nbsp;</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.</p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal" style=""><span style="font-size: 9.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;
<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: rgb(43, 145, 175);">KeyPressEventArgs</span>)
<span style="color: blue;">Handles</span> TextBox2.KeyPress</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9.5pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<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;">
'if not a digit</span></span></p>
<p class="MsoNormal" style=""><span style="font-size: 9.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<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;">'and not a backspace</span></span></p>
<p class="MsoNormal" style=""><span style="font-size: 9.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<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;">'and a decimal has already been added, dont allow</span></span></p>
<p class="MsoNormal" style=""><span style="font-size: 9.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.Handled =
<span style="color: blue;">True</span></span></p>
<p class="MsoNormal" style=""><span style="font-size: 9.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox(<span style="color: rgb(163, 21, 21);">&quot;numbers only&quot;</span>)</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span style="color: blue;">End</span> <span style="color: blue;">If</span></span></p>
<p class="MsoNormal" style=""><span style="font-size: 9.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span style="color: blue;">End</span> <span style="color: blue;">If</span></span></p>
<p class="MsoNormal" style=""><span style="font-size: 9.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span style="color: blue;">Else</span> <span style="color: green;">'if a digit compare index of decimal point (if it exists) and length of text</span></span></p>
<p class="MsoNormal" style=""><span style="font-size: 9.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<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></p>
<p class="MsoNormal" style=""><span style="font-size: 9.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span style="color: blue;">If</span> TextBox2.TextLength &gt; TextBox2.Text.LastIndexOf(Chr(46)) &#43; 2
<span style="color: blue;">Then</span></span></p>
<p class="MsoNormal" style=""><span style="font-size: 9.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span style="color: green;">'if length is over 2 spaces from the decimal point, dont allow
</span></span></p>
<p class="MsoNormal" style=""><span style="font-size: 9.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.Handled =
<span style="color: blue;">True</span></span></p>
<p class="MsoNormal" style=""><span style="font-size: 9.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox(<span style="color: rgb(163, 21, 21);">&quot;only two decimal places allowed&quot;</span>)</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span style="color: blue;">End</span> <span style="color: blue;">If</span></span></p>
<p class="MsoNormal" style=""><span style="font-size: 9.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span style="color: blue;">End</span> <span style="color: blue;">If</span></span></p>
<p class="MsoNormal" style=""><span style="font-size: 9.5pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span style="color: blue;">End</span> <span style="color: blue;">If</span></span></p>
<p class="MsoNormal" style=""><span style="font-size: 9.5pt; font-family: Consolas;">&nbsp;</span></p>
<p class="MsoNormal" style=""><span style="font-size: 9.5pt; font-family: Consolas;">&nbsp;&nbsp;&nbsp;
<span style="color: blue;">End</span> <span style="color: blue;">Sub</span></span></p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal"><b><span style="font-size: 14pt;"><img id="Picture_x0020_2" src="cid:image001.png@01CD2C38.D02E7A30" alt="Description: signiture" height="86" width="194"></span></b></p>
<p class="MsoNormal"><b><span style="" lang="EN-US">&nbsp;</span></b></p>
<p class="MsoNormal"><b><span style="" lang="EN-US">&quot;It is the tragedy of the world that no one knows what he doesn't know - and the less a man knows, the more sure he is that he knows everything&quot;
</span></b><span style="" lang="EN-US">Joyce Cary.</span></p>
<p class="MsoNormal"><span style="" lang="EN-US">&nbsp;</span></p>
<p class="MsoNormal"><b><span style="font-size: 14pt;" lang="EN-US">Michael Wooldridge</span></b></p>
<p class="MsoNormal"><span style="font-size: 12pt; color: rgb(79, 98, 40);" lang="EN-US">Information Technology Coordinator</span></p>
<p class="MsoNormal"><span style="font-size: 8pt;" lang="EN-US">Mornington Secondary College</span></p>
<p class="MsoNormal"><span style="font-size: 8pt;" lang="EN-US">1051 Nepean Highway, Mornington 3931</span></p>
<p class="MsoNormal"><span style="font-size: 8pt; font-family: Wingdings;" lang="EN-US">(</span><span style="font-size: 8pt;" lang="EN-US">: 03 59700250
</span><span style="font-size: 8pt; font-family: &quot;Wingdings 2&quot;;" lang="EN-US">6</span><span style="font-size: 8pt;" lang="EN-US">: 03 59700299</span></p>
<p class="MsoNormal"><span style="font-size: 8pt;" lang="EN-US"><a href="mailto:mwo@mornsc.vic.edu.au" target="_blank"><span style="color: blue;">mwo@mornsc.vic.edu.au</span></a></span></p>
<p class="MsoNormal"><span style="">&nbsp;</span></p>
<p class="MsoNormal" style=""><b><span style="font-size: 9pt;">Important - </span>
</b><span style="font-size: 9pt;">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's arse but yours, sorry.</span></p>
<p class="MsoNormal">&nbsp;</p>
</div>
</div>
</div>
</div>
<p></p><p><b>Important - </b>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.</p>
</body>
</html>