Access 07 Rich Text - SelStart, SelLength (1 Viewer)

Vladimir

New member
Local time
Today, 05:49
Joined
Jul 29, 2014
Messages
3
Trying to post the links. Remove spaces to make the links work...
Sample app: h t t p : / / w w w . s t r e a m l i n e . c z / d o w n l o a d / a c c e s s / B l o g / R T F _ S e l S t a r t _ R e s o l v e d . z i p
Video: h t t p : / / w w w . s t r e a m l i n e . c z / d o w n l o a d / a c c e s s / B l o g / R T F _ S e l S t a r t _ R e s o l v e d . w m v

Note 3:
Also see fMain in sample app. There are a few procedures to simulate SelStart bug.
See the following:
h t t p : / / s o c i a l . m s d n . m i c r o s o f t . c o m /Forums/office/en-US/d06fa250-3732-41a7-ad9f-7ad3004a6b37/access-2007-bug-rtf-doesnt-handle-selstart-correctly?forum=accessdev
h t t p : / / w w w . s t r e a m l i n e . c z / d o w n l o a d / a c c e s s / B l o g / R T F _ S e l S t a r t 1 . w m v
h t t p : / / w w w . s t r e a m l i n e . c z / d o w n l o a d / a c c e s s / B l o g / R T F _ S e l S t a r t 2 . w m v
h t t p : / / w w w . s t r e a m l i n e . c z / d o w n l o a d / a c c e s s / B l o g / R T F _ S e l S t a r t 3 . w m v
 

spikepl

Eledittingent Beliped
Local time
Today, 14:49
Joined
Nov 3, 2010
Messages
6,142
@Vladimir

I tried your DB and it does insert text at the spot marked by the cursor, even if preceding text is full of mark up. Well done.

I am attaching your database here, for direct consumption.
 

Attachments

  • RTF_SelStart_Resolved.zip
    137.2 KB · Views: 174

Vladimir

New member
Local time
Today, 05:49
Joined
Jul 29, 2014
Messages
3
I'm glad I could help. Enjoy!

P.S. Thx for posting a direct link.
 
Last edited:

JMA92410

New member
Local time
Today, 14:49
Joined
Apr 19, 2019
Messages
4
Try this. If you send the RichTextBox control .SelStart property +1, it seems to work...

Code:
Public Function HTMLPosition(ByVal iintVisiblePosition As Integer, ByVal istrHTMLtext As String) As Integer
Dim boolSkipTag As Boolean, boolSkipCarSpec As Boolean
Dim intCar As Integer, intLen As Integer, intPos As Integer
Dim strCar As String * 1

'Initialisations
'***************
intCar = 0
intLen = Len(istrHTMLtext)
intPos = 0
boolSkipTag = False
boolSkipCarSpec = False

'Boucle sur les caractères de la ligne & décodage
'************************************************
Do
  intCar = intCar + 1
  'If intCar = 1370 Then Stop
  strCar = Mid(istrHTMLtext, intCar, 1)
  Select Case True
    Case strCar = "<"
      boolSkipTag = True
    Case strCar = ">"
      boolSkipTag = False
    Case boolSkipTag
    Case strCar = "&"
      If Mid(istrHTMLtext, intCar, 6) = " " Then
        intCar = intCar + 5
      Else
        boolSkipCarSpec = True
      End If
    Case strCar = ";"
      boolSkipCarSpec = False
      intPos = intPos + 1
    Case boolSkipCarSpec
    Case strCar = vbCr
      If Mid(istrHTMLtext, intCar, 4) = vbCrLf & vbCrLf Then
        intCar = intCar + 3
        intPos = intPos + 1
      End If
    Case strCar = vbLf
    Case Else
      intPos = intPos + 1
  End Select
  If intPos >= iintVisiblePosition Then
    HTMLPosition = intCar
    Exit Function
  End If
Loop Until intCar >= intLen
HTMLPosition = 0
End Function
 

CedarTree

Registered User.
Local time
Today, 08:49
Joined
Mar 2, 2018
Messages
404
I'm really struggling to figure out this code... what's the primary function/coding that determines the SelStart within a Rich Text field? Thanks!
I'm getting SelStart and Length on MouseUp and KeyUp. But... when I grab Mid(Textbox, SelStart, SelLength), it's still off by a few characters.
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 13:49
Joined
Jan 14, 2017
Messages
18,211
Post #24 was moderated and only discovered now.

@CedarTree
See if that post answers your question.
If not, please start a new thread with a link back to this one
 

CedarTree

Registered User.
Local time
Today, 08:49
Joined
Mar 2, 2018
Messages
404
That function works for I think basic RTF (bold, italics), but when I pick a position after some hrefs, it seems to go off. I suspect it might actually be CHR(10) or CHR(13) in my text box I need to account for.
 

isladogs

MVP / VIP
Local time
Today, 13:49
Joined
Jan 14, 2017
Messages
18,211
I have code to extract the code after href in a rich text memo field (HTMLDetails) so I can display that as a hyperlink on a form.
The text is very lengthy so I extract the info with code similar to this:

Code:
Mid([HTMLDetails],InStr([HTMLDetails],"href")+5,InStr([HTMLDetails],"</a>")-(InStr([HTMLDetails],"href")+5))

So for example, using this (comparatively short) record
Code:
<strong><em><font color="#000080" face="Arial">Reverse update year</font></em></strong> 
<p></p><font face="Arial">
<div><strong><em>Updating year groups </em></strong>is an essential part of the <strong><em>Annual Update </em></strong>routine which is used to update student, teacher and timetable data in School Data Analyser each year. </div>
<div> </div>
<div>This routine is normally done during the summer holiday to ensure all data is updated ready for the start of the new academic year.</div>
<div> </div>
<div>After deleting data for specified year groups no longer in the school (normally Y11 and/or 13), the remaining year group still in the school are promoted for the following year i.e. Year 10 becomes Year 11 etc</div>
<div> </div>
<div>This should be planned carefully in conjunction with the information in the <strong><em>Annual Update Routine Guide.</em></strong></div>
<div> </div>
<div>However in case of problems it is possible to reverse the Update Year process i.e Year 11 is returned to Year 10 etc</div>
<div> </div>
<div>
<div>Although this is done automatically as part of the Annual Update routine, it is possible to do this independently if necessary. If so, the main and leavers database files are first backed up to ensure no risk of data loss</div></div>
<div> </div>
<div>From the <strong>Admin Menu</strong>, go to <strong>Annual Update</strong> then <strong>Reverse Update Year</strong></div>
<div><strong></strong> </div>
<div><img align="baseline" alt="" src="file://G:/Programs/MendipDataSystems/CommonFiles/SDA/Images/AdminMenuAnnualUpdate.gif" border="0" hspace="0"></div>
<div> </div></font>
<div><font face="Arial">For more information, see the <strong><em>linked file</em></strong> below:</font></div>
<p><font face="Arial"><strong><em><a [B][COLOR="DarkRed"]href="file://colin-pc/G/Programs/MendipDataSystems/CommonFiles/SDA/Documentation/AnnualUpdateRoutineGuide.pdf">AnnualUpdateRoutineGuide.pdf</a>[/COLOR][/B]</em></strong></font></p>

correctly returns the following string:
Code:
"file://colin-pc/G/Programs/MendipDataSystems/CommonFiles/SDA/Documentation/AnnualUpdateRoutineGuide.pdf">AnnualUpdateRoutineGuide.pdf

In other words, I don't experience any issues with similar code to yours even though I use a wide range of HTML tags sprinkled throughout.
I can't think of any reason why SelText & SelLength would be different

Hope that helps
 
Last edited:

CedarTree

Registered User.
Local time
Today, 08:49
Joined
Mar 2, 2018
Messages
404
Seems to work... I tweaked the getting of SelStart to be on LostFocus event rather than MouseUp/KeyUp and that seems to fix it for some reason.
 

Users who are viewing this thread

Top Bottom