?
Solved

VB6 RichTextBox SelStart Problem

Posted on 2011-05-12
13
Medium Priority
?
1,294 Views
Last Modified: 2012-05-11
Dear Experts,

In a VB6 RichTextbox, I need to obtain the current insert point (SelStart) with the MouseDown event. Although a standard textbox does this without a problem, the RichTextbox returns a 0 for the SelStart value on the first mouse click, then on each subsequent mouse click, it returns the previous click point. Strange, and not useful.

I have used a timer to obtain the actual SelStart point but this complicates things.

Is there a good way to obtain the actual SelStart/cursor position in a RichTextbox with the MouseDown event?

Thanks!
0
Comment
Question by:ttobin333
  • 7
  • 4
  • 2
13 Comments
 
LVL 46

Expert Comment

by:aikimark
ID: 35756085
capture/save the selstart value in the mousemove() event for the RTF textbox.
0
 
LVL 20

Expert Comment

by:hes
ID: 35756208
I just tested with this code and it returned the correct value each time I did a mouse down
Private Sub RichTextBox1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
MsgBox RichTextBox1.SelStart
End Sub
0
 

Author Comment

by:ttobin333
ID: 35756642
Aikimark: I will try the mousemove suggestion.

Hes:  the process you describe is what did not work for me. Please try again with some text in the RTB, clicking different locations.  When I do this, the 1st click gives me a value of 0, and the next click gives me the value of the 1st click.

Thanks!
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Expert Comment

by:hes
ID: 35756691
I did... My first click gave me a value of 10 (there were was 1234567890 in the rtb) I added 20 more characters and the value was 30 I clicked on the first 5 and the value was 5
0
 

Author Comment

by:ttobin333
ID: 35758867
Hes, maybe you have a newer/different richtextbox control? Mine is definitely retuning the prior mousedown value each time. Are you using VB6?
0
 

Accepted Solution

by:
ttobin333 earned 0 total points
ID: 35777717
Giving up on this...will use click event rather than mousedown. Thanks for the comments.
0
 
LVL 46

Expert Comment

by:aikimark
ID: 35777737
what about the mousemove event?
0
 
LVL 20

Expert Comment

by:hes
ID: 35778347
Yes I am using VB6 sp6
0
 

Author Comment

by:ttobin333
ID: 35799390
Regarding the mousemove event, using the click event is much simpler.

Regarding the difference in SelStart behavior, I don't know what the answer is. The behavior Hes describes is indeed what one would expect, and is the way a standard textbox behaves, but mine is not working that way.
0
 

Author Comment

by:ttobin333
ID: 35799399
Is there an updated RichTextbox control for VB6?
0
 
LVL 20

Expert Comment

by:hes
ID: 35801148
This is a new pc I just installed VB6 then applied sp6 nothing else updated in VB6
0
 

Author Comment

by:ttobin333
ID: 35803583
I also have VB6 SP6, on 2 machines, Win7 and XP.

To test this issue again, I did as follows:
1. Created a new project, new form, new RichTextbox
2. In the mousedown event, I entered the code: msgbox str(richtextbox1.SelStart).
3. I ran the project
4. I entered 12345 into the RichTextbox
5. I clicked between the characters 1 and 2
6. The mousedown value = 5, the prior value
7. I clicked between the characters 3 and 4
8. The mousedown value = 1, again the prior value

When the RichTextbox has pre-loaded text upon opening, mousedown returns 0 on the first click because the default SelStart is at zero when it first opens.

This appears to be an inherent problem with the RichTextbox control, and at this point it is not productive to further pursue the issue, because the click event is a satisfactory workaround.
0
 

Author Closing Comment

by:ttobin333
ID: 35810065
Will use click event rather than mousedown, as a work-around.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

750 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