How to de-select entered text

When I enter new text in a field, the entry is selected. How can I unselect it after the entry?
“TxtBox.SelLength = 0” doesn’t work.

Then you might be doing something wrong (as in putting that command in the wrong place)

Please post enough code to give us an idea of the flow you have, and what you are expecting.

Here’s my action:

dim A as Double

if Key = Chr(13) or Key = Chr(3) then 'when ENTER is pressed…
A = Val(TxtBoxTarget.Text) 'get the numerical value entered
TxtBoxTarget.Text = Format (A,"#.000000") 'put it back with 6 decimal places
TxtBoxTarget.SelLength = 0 'unselect the new value DOES NOT WORK
end

dim A as Double

if Key = Chr(13) or Key = Chr(3) then 'when ENTER is pressed...
A = Val(TxtBoxTarget.Text) 'get the numerical value entered
TxtBoxTarget.Text = Format (A,"#.000000") 'put it back with 6 decimal places
TxtBoxTarget.SelLength = 0 'unselect the new value DOES NOT WORK
RETURN TRUE ' <------ ADD THIS LINE
end if

Thanks very much. Can you explain why I have to return true, and simply declaring the SelLength equal to zero doesn’t do it?
It seems like saying:

The color is red
Really it is.

the “RETURN TRUE” basically says… “Really it is”. :slight_smile:

as in… “Hey Application… I have dealt with this situation, just do what I said, and don’t worry about this event anymore”

That being said… it only applies to specific events… MouseDown being a prime example as well

The system is saying,

I’ll give you a chance to handle this yourself.
Did you?
If not, I’ll do my normal thing by highlighting the text.

Return True says, “Yes, I did.”

Return True in MouseDown event enable all other MouseXxxx events.

[quote=89646:@Bryan Mumford]Thanks very much. Can you explain why I have to return true, and simply declaring the SelLength equal to zero doesn’t do it?
It seems like saying:

The color is red
Really it is.[/quote]

Possibly the missing piece here is that by default methods that return boolean will return false if nothing is explicitly returned (events are just methods). In the case of events returning a boolean, “false” means “It’s not really red, I was just kidding” in your example’s second line.

Returning true, accurately, confirms that you have dealt with the situation. Until then, you haven’t really handled the event, regardless of whatever actions you have actually done in it, as far as the event handler is concerned.

Okay, I’ll try to remember that I have to Return True for the code to be executed.

But I decided to move that bit of code to the Paint Event of the main window. I say “CommentField.SelLength = 0”, and it is not happening. The text in the field stays selected, and there’s no Return value to enter. I can set the Text property of the field, but I can’t set the SelLength.

I doubt the paint event is being called when you want it to. That’s kind of an unusual place to put that kind of code.

Are you really trying to get something to work, or to find the weirdest place to enter code ?

This deselects fine here …

Sub Paint(g As Graphics, areas() As REALbasic.Rect) dim A as Double = 3456789 T.Text = Format (A,"#.000000") 'put it back with 6 decimal places T.SelLength = 0 End Sub

What are you doing strange for it not to work ?