[Year 12 SofDev] help

Mark KELLY kel at mckinnonsc.vic.edu.au
Mon May 7 11:56:34 EST 2012


Have you thought about using an input mask?

On 7 May 2012 10:04, Michael Wooldridge <mwo at mornsc.vic.edu.au> wrote:

> Hi guys,****
>
> ** **
>
> 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: If Not Char.IsDigit(e.KeyChar)
> Then 'if not a digit****
>
> To me, initially, I would have thought it should read: If Note.KeyChar.IsDigit(e.KeyChar)
> Then 'if not a digit but VB won’t let me do that and keeps telling me to
> change it back to “Char” ****
>
> ** **
>
> ** **
>
> 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. ****
>
> ** **
>
> If anyone can solve this for me or has a better way of doing it your
> suggestions would be much appreciated.****
>
> ** **
>
> ** **
>
>     Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.
> KeyPressEventArgs) Handles TextBox2.KeyPress****
>
> ** **
>
>         If Not Char.IsDigit(e.KeyChar) Then 'if not a digit****
>
>             If Not Asc(e.KeyChar) = 8 Then 'and not a backspace****
>
>                 If Not TextBox2.Text.LastIndexOf(Chr(46)) = -1 Then 'and
> a decimal has already been added, dont allow****
>
>                     e.Handled = True****
>
>                     MsgBox("numbers only")****
>
>                 End If****
>
>             End If****
>
>         Else 'if a digit compare index of decimal point (if it exists)
> and length of text****
>
>             If Not TextBox2.Text.LastIndexOf(Chr(46)) = -1 Then****
>
>                 If TextBox2.TextLength >
> TextBox2.Text.LastIndexOf(Chr(46)) + 2 Then****
>
>                     'if length is over 2 spaces from the decimal point,
> dont allow ****
>
>                     e.Handled = True****
>
>                     MsgBox("only two decimal places allowed")****
>
>                 End If****
>
>             End If****
>
> ** **
>
>         End If****
>
> ** **
>
>     End Sub****
>
> ** **
>
> ** **
>
> *[image: Description: signiture]*
>
> * *
>
> *"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" *Joyce
> Cary.****
>
> ** **
>
> *Michael Wooldridge*
>
> Information Technology Coordinator****
>
> Mornington Secondary College****
>
> 1051 Nepean Highway, Mornington 3931****
>
> (: 03 59700250 6: 03 59700299****
>
> mwo at mornsc.vic.edu.au****
>
> ** **
>
> *Important - *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.****
>
> ** **
>
> _______________________________________________
> http://www.edulists.com.au - FAQ, Subscribe, Unsubscribe
> IT Software Development Mailing List kindly supported by
> http://www.vcaa.vic.edu.au - Victorian Curriculum and Assessment
> Authority and
> http://www.vcaa.vic.edu.au/vce/studies/infotech/softwaredevel3-4.html
> http://www.vitta.org.au  - VITTA Victorian Information Technology
> Teachers Association Inc
> http://www.swinburne.edu.au/ict/schools - Swinburne University
>



-- 
Mark Kelly
Manager of ICT, Reporting, IT Learning Area
McKinnon Secondary College
McKinnon Rd McKinnon 3204, Victoria, Australia
Direct line / Voicemail: +613 8520 9085, Fax +613 9578 9253
kel at mckinnonsc.vic.edu.au (don't use my Edumail account!)
VCE IT Lecture Notes: http://vceit.com
Moderator: IT Applications Edulist

--
An E-flat, a C, and a G go into a bar. The bartender says, "I'm sorry, but
I can't serve minors."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.edulists.com.au/pipermail/sofdev/attachments/20120507/0730c03c/attachment.html 


More information about the sofdev mailing list