PDA

View Full Version : checking that a user entered decimal number in textbox is only upto 4 decimal places



mathsguy2011
04-06-2011, 09:36 AM
hi, i have a userform with 6 textboxes. in each textbox i want the user to input a decimal number between 0 and 1 and i then want to check before continuing program that this is what they have done. i read in the textbox value using code eg. r1=val(textbox1)
i then want to check that r1 is between 0 and 1 which i can do but also check that it is only upto4 decimal places how do i do that?

Bob Phillips
04-06-2011, 09:53 AM
I would check it on entry using the KeyPress method and make sure that say

Len(TextBox1.Text) - Instr(TextBox1.Text,".")

is not greater than 3, i.e. allow another character.