You seem to have deleted one of the superfluous lines, but left the other!
Richard.
Any 'entry filtering' ideally needs to be compatible with the normal input editing operations that the user might perform: repositioning the caret with the mouse, tabbing betwen input fields, typing backspace and delete etc.
Let's assume the user has entered a number (including a decimal point) but then realises the decimal point is in the wrong place. He could first delete the old decimal point and then insert a new one - presumably that would work as expected. Alternatively he could insert a new decimal point in the correct place and then delete the old one; if I've understood you correctly that will not give the expected result. Ideally, I would want the two approaches to have the same effect; that could include the first decimal point automatically being deleted by the insertion of the second one (but leaving all the other digits unchanged). I would not expect it to make a difference whether the new DP is to the left or the right of the old one.
I hear what you say and in the ideal world, that's what would happen. The problem is, how to achieve it. I've been playing around with it and can't get my head around how it would work. The only thing I could think of was to trap the insertion of a second decimal point and bring up an error message that pointed out the two decimal points and to delete which was inappropriate - then the problem is to produce the code.Let's assume the user has entered a number (including a decimal point) but then realises the decimal point is in the wrong place. He could first delete the old decimal point and then insert a new one - presumably that would work as expected. Alternatively he could insert a new decimal point in the correct place and then delete the old one; if I've understood you correctly that will not give the expected result. Ideally, I would want the two approaches to have the same effect; that could include the first decimal point automatically being deleted by the insertion of the second one (but leaving all the other digits unchanged). I would not expect it to make a difference whether the new DP is to the left or the right of the old one.
Code: Select all
function num$(d$)
t = 0': t1 =0 't1 is not used
for i=1 to len(d$)
a=asc(mid$(d$,i,1))
if a = 46 then t = t + 1
'if t > 1 then a = 77 'this one deleted everything after second dot
if (a = 46) and (t > 1) then a = 77 'only DOT after FIRST is cleared
if a = 45 and i>1 then a = 77 'so really almost anything do, not just 8
if a = 46 and i = 1 then num$ = "0" + num$
if a = 45 or a = 46 or a>47 and a<58 then num$=num$+chr$(a)
next
end function
As I noted, lineYou're right, a = 8 is the equivalent of a$ = chr$(8), which is indeed a backspace that overwrites the offending digit and allows you to carry on with your input. I must be backspace, because anything else would be entered as you input it.
Code: Select all
if a = 45 or a = 46 or a>47 and a<58 then num$=num$+chr$(a)
Code: Select all
if a = 46 and i = 1 then num$ = "0" + num$
Presumably yes: if it's a Textbox EM_GETSEL returns that.
A common approach is to read the contents of the Textbox periodically, in a TIMER handler, then you can compare what's in the textbox now with what was in it a short time ago and therefore deduce what and where the change is.If not, how program could tell which dot is old and which new?
I didn't understand Ray's comment either. I agree with you that any value other than the code for a digit or decimal point would have the same effect.and about "You're right, a = 8 is the equivalent of a$ = chr$(8), which is indeed a backspace that overwrites the offending digit" ... a backspace never actually made to textbox.