[Year 12 SofDev] help

Mark KELLY kel at mckinnonsc.vic.edu.au
Mon May 7 14:20:09 EST 2012


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'd say the input mask is far easier and more elegant.

Preventing invalid data getting in is better than detecting and curing it
:-)

*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).

Those were fun days  :-)

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

> I assume you are referring to a MaskedTextBox. That works but it’s kind of
> cheating isn’t it?****
>
> ** **
>
> *[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.****
>
> ** **
>
> *From:* sofdev-bounces at edulists.com.au [mailto:
> sofdev-bounces at edulists.com.au] *On Behalf Of *Mark KELLY
> *Sent:* Monday, 7 May 2012 11:57 AM
>
> *To:* Year 12 Software Development Teachers' Mailing List
> *Subject:* Re: [Year 12 SofDev] help****
>
> ** **
>
> 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****
>
>  ****
>
>  ****
>
> ****
>
> * *****
>
> *"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."
>
> ****
>
> _______________________________________________
> 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/6acaf434/attachment-0001.html 


More information about the sofdev mailing list