I am using a textfield for the following calculations.
dim ratio as double
ratio = val(txtmm.text) * 0.0393700787
txtanswer.text = Format(ratio,“0.00000”) + " Inches"
txtcalculation.text = “1 mm = 0.03937 inches”
My question is how do I make the textfield ignor inputs that are not numerical.
Put the format into the mask property of the textfield.
Hi Wayne, thanks but not sure how to do that, just learning programming.
Thanks, but now I am more confused.
Using the information you can gather from TextEdit.Mask you can apply it to the text field using the IDE:
Thanks, if I use #### you can input 1234, but no percentage such as 12.34
then if I use ##.## you can enter 12.34 but not 1234
I need to be able to do it both ways, I seem to be not grasping it.
That is correct…MASK is designed to allow for a pattern matching input…
Otherwise capture KEY in the keydown event and determine if you wish to keep it or not
There are many examples posted thru out this forum
If key=ChrB(13) Or key=ChrB(3) Or key=ChrB(9) Then Return False
If key=ChrB(8) Then Return False
If (key<"0" Or key>"9") and key<>"." Then Return True
I will leave it up to you to figure out duplicate decimal points, plus/minus signs etc.
Thanks Dave have have it working fine with the -sign now
If (key<“0” Or key>“9”) and key<>"." and key <>"-" Then Return True
But I am having problems when I try and add a Backspace to it, I have tried the following
If (key<“0” Or key>“9”) and key<>"." and key <>"-" and key=ChrB(8) Then Return True … This is allowing all alpha characters
If (key<“0” Or key>“9”) and key<>"." and key <>"-" and key<>ChrB(8) Then Return True… Back Space doesn’t work with this
If (key<“0” Or key>“9”) and key<>"." and key <>"-" or key<>ChrB(8) Then Return True… This allows no input at all
If (key<“0” Or key>“9”) and key<>"." and key <>"-" or key = ChrB(8) Then Return True…Back Space doesn’t work with this
It already handled Backspace, CR, LF and TAB … look at the 1st two lines of what I gave you
FYI… when you have AND as well as OR in the same statment… you better have () to keep things straight
If (key<“0” Or key>“9”) and key<>"." and key <>"-" and Asc(Key) <> 8 Then Return True
Thanks, searched the forum.
still not sure why you just didn’t leave it as it was… it worked just fine as I provided it
Dave’s code is much easier to read and maintain than what you came up with.
This just shows my limited knowledge, I thought Dave was just giving me some examples and I had to figure the rest out, Thanks Dave and Tim, I have now used Daves full code and added the bit for the minus and it works fine.