Reverse select a textbox

Posted on 2002-04-14
Last Modified: 2012-06-22

I have a single line text box. I would like to select the text in the text box so that when that text box receives focus, the text would be selected from right to left instead of left to right. Left to right selection if provided by :

txtBox1.SelStart = 0
txtBox1.SelLength = Len(txtBox1.Text)
Question by:dhwanilshah
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +5

Accepted Solution

Bahnass earned 100 total points
ID: 6939956
Sorry Don't understand U???
lines U wrote are selecting the hole textbox area (So no write or left)

no of char in text box is given by Len(txtBox1.Text)

if U want to select first 2 char
txtBox1.SelStart = 0
txtBox1.SelLength = 2

if U want last 2 char
txtBox1.SelStart = Len(txtBox1.Text)-2
txtBox1.SelLength = 2

textbox has righttoleft property to display contents in that order

Hope that helps!!!!!!    thaugh I don't understand Q!!

LVL 44

Expert Comment

ID: 6939961
in VB 6, you can change the RightToLeft property of the text box to TRUE, then text will be entered into the text box from Right To Left, (the default is Left to Right).  Is that what you are asking?

Expert Comment

ID: 6939987
one way....

Private Sub Text1_GotFocus()
Text1.SelStart = Len(Text1)
SendKeys "+{HOME}"
End Sub
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

LVL 45

Expert Comment

ID: 6940010
What are you trying to accomplish with this?  If all the text is selected, what difference does it make if it is selected from left-to-right or right-to-left?

jbil seems to have workable solution.  In a production environment, I would look at using the SendMessage API instead of SendKeys if feasable.

Expert Comment

ID: 6940296
I dont see any difference for a text selecting in what so ever order. btw, when a text is selected in a textbox, and if the text box loses the focus, the selection is also gone.

*****the text would be selected from right to left instead of left to right*****

What does it mean? could u Pls post some more info.

LVL 22

Expert Comment

ID: 6943028
Just observing...
Try this experiment and you'll understand the question:

Click on [Start]|Run...

In the run combobox if you don't have something selected, enter Notepad, click OK, then repeat until something is selected.

Look carefully at the selected text and notice that the cursor is at the END of the selected text.  Press the left arrow key and notice that the cursor ends up to the left of the last character.

Now press the following key sequence: END, SHIFT+HOME

Notice that everything is highlighted, but the cursor is now blinking at the beginning.  Try cursor left again and notice that the cursor ends up at the beginning of the text.

Similarly, using shift-cursor will give different results.

Why do you need this?  Convenience for some things, but ultimately I'd say that since no other applications do it, there's a good chance that this convenience will simply confuse many users and may not be worth the effort.
LVL 45

Expert Comment

ID: 6943471
Having your application automatically select the text is meant to be a convenience for the user to not have to delete text before typing completely new text.  

If the user wants to append new text, they must one of the following:
* press the End key
* press the right arrow key
* click to the right of the text with the mouse

If the user wants to prepend new text, they must one of the following:
* press the Home key
* click to the left of the text with the mouse
(Yes they can hold the left arrow key until the cursor reaches the start of the text, but the Home key is simpler and quicker.)

Without further information from you, we experts are at a loss to do anything other than advise you to avoid non-Windows-standard behavior.
LVL 49

Expert Comment

ID: 7654057
Hi dhwanilshah,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept Arthur_Wood@devx's comment(s) as an answer.

dhwanilshah, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
DanRollins -- EE database cleanup volunteer
LVL 45

Expert Comment

ID: 7655263

I disagree with your recommendation.  Bahnass mentioned the righttoleft textbox property before Arthur_Wood (by four minutes).

Expert Comment

ID: 7655604
Thank aikimark
    any How My comment was to help asker who is not there even to say thanks!!

Thanks all EE's    
LVL 49

Expert Comment

ID: 7659767
Thanks for the input.  I'm changing my recommendation to:

  Accept Bahnass's comment(s) as an answer.
DanRollins -- EE database cleanup volunteer

Expert Comment

ID: 7755045
per recommendation

Community Support Moderator @Experts Exchange

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question