Does not change the value

Hello everyone
xojo

The present is to greet you and thank you for your attention to the following:

In a window of a desktop system, I have a textField where I enter a code
for example if you enter 35 the code is 0000000035

In the event Lostfocus I have the following:

Me.text = RIGHT (“0000000000” + TRIM (Self.txtCodigo.text), 10)
Me.Refresh

On the same screen I have a Generic Button, which performs calculation according to the entered code
if the user press enter in the textfield after entering the 35 in the Generic Button shows me
0000000035 and the whole calculation is perfect.

But if the USER does NOT press enter, in the textField when exiting, but with the mouse click directly on the Generic Button
the code that shows me on the Generic Button is 35 and what it really should be 0000000035
and being code 35 does not make any calculation

What is the reason why it does not change the value of the code with zeros to the left, when NO pulse enter when leaving the textField?

Some scope will be greatly appreciated.

Infinite thanks

Raúl Juárez Pulache

The button does not get the focus.
So the lostfocus event does not fire.

Do not rely upon it.
Add the leading zeroes when you NEED them, (in the button action event?).

Thank you so much
Jeff Tullin

What happens is the textfield I have to validate if the entered code exists in the base
of data and if so I should also show in another textField the name, in another textField
the address etc.

and if everything is correct I must click on the button to print a listing

For all users with press enter everything is solved but I have an older adult who does not do it and that is the situation

Cordially,

Raul

…which is why you need to have a routine that validates all the input before you save.

In the button action code call

if ValidateAllFields() then //save else msgbox "correct some mistake" end if

[code]sub ValidateAllFields() as boolean
dim ret as boolean = true

txtCodigo.text = RIGHT (“0000000000” + TRIM (txtCodigo.text), 10)

//other things you did in lostfocus

//now check them

if txtCodigo.text then ret =false
if txtSomefield.text = “” then ret = false
//etc

return ret

end if[/code]

You might be able to achieve the same (or similar) effect without any code using the text field’s Format property.
In the IDE set the Format on this text field in the properties list to 0000000000.

More information on how the format mask works here: http://documentation.xojo.com/index.php/TextEdit.Mask

Using the Format property affects the value after the user enters it, Mask will prevent invalid entry.

Many thanks Jeff Tullin
Many Thanks Tim Parnell

With his great help I could solve the situation raised

A hug

Raul Juarez Pulache