Validate textbox input is a multiple of 20

Posted on 2006-05-31
Last Modified: 2010-04-17
I have a text box in an app that has to contain a value that is a multiple of 20.. basically have to divide by 20 and ensure that the remainder is a whole number - help with this is appreciated.
Question by:egdigital
    LVL 2

    Assisted Solution

    Server side or client side?

    Use the mod operator  (%)

    if((int)txtValue % 20 == 0)
            //Value is a multiple of 20
          // Value is not a multiple of 20
    LVL 24

    Expert Comment

    Do you feel that (int) txtValue is an approach that can work? You use of % suggest you are talking about C and I can assure that your code does not work that way.

    To get the content of a the text field. that can be done with either
    GetDlgItemText or as an int with GetDltItemInt.

    You code does the following it casts a char* to some int and divides that after that. Surely not what the OP wanted.

    LVL 2

    Expert Comment

    What language is this being written in?
    That way I can provide a more language specific answer.


    Author Comment

    Its being written in vb
    LVL 4

    Accepted Solution


    if val(txtValue.text) Mod 20 = 0 then
           'Value is a multiple of 20
          'Value is not a multiple of 20
    end if

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Suggested Solutions

    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now