<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
        {font-family:"Wingdings 2";
        panose-1:5 2 1 2 1 5 7 7 7 7;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";
        mso-fareast-language:EN-US;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-AU link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>Hi guys,<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></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'>'if not a digit</span><o:p></o:p></span></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'>'if not a digit </span></span>but VB won&#8217;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 &#8220;Char&#8221; <o:p></o:p></span></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal>I can&#8217;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. <o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></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.<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal style='text-autospace:none'><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:#2B91AF'>KeyPressEventArgs</span>) <span style='color:blue'>Handles</span> TextBox2.KeyPress<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal style='text-autospace:none'><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><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><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><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><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><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><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><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><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:#A31515'>&quot;numbers only&quot;</span>)<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><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><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><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><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><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><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><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><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><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)) + 2 <span style='color:blue'>Then</span><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><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><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><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><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><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:#A31515'>&quot;only two decimal places allowed&quot;</span>)<o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><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><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><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><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal style='text-autospace:none'><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><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas'>&nbsp;&nbsp;&nbsp; <span style='color:blue'>End</span> <span style='color:blue'>Sub<o:p></o:p></span></span></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><b><span style='font-size:14.0pt;mso-fareast-language:EN-AU'><img width=194 height=86 id="Picture_x0020_2" src="cid:image001.png@01CD2C38.D02E7A30" alt="Description: signiture"><o:p></o:p></span></b></p><p class=MsoNormal><b><span lang=EN-US style='mso-fareast-language:EN-AU'><o:p>&nbsp;</o:p></span></b></p><p class=MsoNormal><b><span lang=EN-US style='mso-fareast-language:EN-AU'>&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 lang=EN-US style='mso-fareast-language:EN-AU'>Joyce Cary.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='mso-fareast-language:EN-AU'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><b><span lang=EN-US style='font-size:14.0pt;mso-fareast-language:EN-AU'>Michael Wooldridge<o:p></o:p></span></b></p><p class=MsoNormal><span lang=EN-US style='font-size:12.0pt;color:#4F6228;mso-fareast-language:EN-AU'>Information Technology Coordinator<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:8.0pt;mso-fareast-language:EN-AU'>Mornington Secondary College<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:8.0pt;mso-fareast-language:EN-AU'>1051 Nepean Highway, Mornington 3931<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:8.0pt;font-family:Wingdings;mso-fareast-language:EN-AU'>(</span><span lang=EN-US style='font-size:8.0pt;mso-fareast-language:EN-AU'>: 03 59700250 </span><span lang=EN-US style='font-size:8.0pt;font-family:"Wingdings 2";mso-fareast-language:EN-AU'>6</span><span lang=EN-US style='font-size:8.0pt;mso-fareast-language:EN-AU'>: 03 59700299<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:8.0pt;mso-fareast-language:EN-AU'><a href="mailto:mwo@mornsc.vic.edu.au"><span style='color:blue'>mwo@mornsc.vic.edu.au</span></a><o:p></o:p></span></p><p class=MsoNormal><span style='mso-fareast-language:EN-AU'><o:p>&nbsp;</o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><b><span style='font-size:9.0pt;mso-fareast-language:EN-AU'>Important - </span></b><span style='font-size:9.0pt;mso-fareast-language:EN-AU'>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.<o:p></o:p></span></p><p class=MsoNormal><o:p>&nbsp;</o:p></p></div></body></html>