Solved

SelProtected property

Posted on 2001-07-30
12
255 Views
Last Modified: 2007-12-19
I have a RichTextBox and some zones in text are protected. I want to do that the protected zones are selected when the cursor moves over them. If the cursor is over a word that is protected, then all whole word must be selected and if i press SUPR key, the whole selection must be erased. That is, or the whole protected zone is erased or nothing, but i don't want that only a part of it where deleted...ok?

Sorry for bad english, i hope that you can understand fine what i want...

Thanks in advance,
0
Comment
Question by:FidoBoy
  • 7
  • 4
12 Comments
 
LVL 14

Expert Comment

by:wsh2
ID: 6334216
Questions Asked 7
Last 10 Grades Given C C C  
Question Grading Record 3 Answers Graded / 3 Answers Received

Open Questions dating back to April 23rd.
0
 
LVL 1

Author Comment

by:FidoBoy
ID: 6334792
I don't understand what u wanna mean... I posted 7 wuestions, but i only get answers for 3 of them... What's the problem?
0
 
LVL 1

Expert Comment

by:fparie
ID: 6337735
here goes,

- new standard exe project
  - 1 form with a richtextbox named RichTextBox1
  - classmodule named PRTZone
- paste code below
- save it
- try it

note that i made a short wordlist in the code, you may want to change that....

francois

''''''''''''''
'code for classmodule
''''''''''''''
Option Explicit

Public ZStart As Long
Public ZEnd As Long


''''''''''''''
'code for form
''''''''''''''
Option Explicit

Private Zones As Collection
Private protectString As New Collection
Private protectedmode As Boolean
Private inSelChangeCall As Boolean

Private Sub Form_Load()
   
    inSelChangeCall = False
   
    setprotect
   
    SetZones RichTextBox1.Text

End Sub

Private Sub SetZones(atString As String)
Dim scanstring As Variant
Dim tstring As String
Dim hit As Long
Dim tempPRT As PRTZone
Dim offset As Long
offset = 0
tstring = atString
    Set Zones = New Collection
    For Each scanstring In protectString
        tstring = atString
        offset = 0
        hit = InStr(1, tstring, scanstring)
        While hit
            Set tempPRT = New PRTZone
            tempPRT.ZStart = offset + hit
            tempPRT.ZEnd = offset + hit + Len(scanstring)
            Zones.Add tempPRT
            tstring = Right(tstring, Len(tstring) - ((hit - 1) + Len(scanstring)))
            offset = offset + hit + Len(scanstring) - 1
            hit = InStr(1, tstring, scanstring)
        Wend
    Next


End Sub

Private Sub setprotect()
Dim strpr As String
'
' build you own routine to fill the collection (ie read from file)
'
   
    strpr = "word"
    protectString.Add strpr
    strpr = "this"
    protectString.Add strpr
    strpr = "when"
    protectString.Add strpr
   
End Sub

Private Sub RichTextBox1_Change()
    SetZones RichTextBox1.Text
End Sub

Private Sub RichTextBox1_KeyDown(KeyCode As Integer, Shift As Integer)
    Debug.Print KeyCode
    If protectedmode Then
        If KeyCode = 39 Then
            RichTextBox1.SelStart = RichTextBox1.SelStart + RichTextBox1.SelLength
            RichTextBox1.SelLength = 0
            protectedmode = False
        End If
    End If
End Sub

Private Sub RichTextBox1_SelChange()
Dim SelItemN As Long
Dim d As Variant
    If Not inSelChangeCall Then
        inSelChangeCall = True
        For SelItemN = RichTextBox1.SelStart To RichTextBox1.SelStart + RichTextBox1.SelLength
            For Each d In Zones
                If SelItemN >= d.ZStart And SelItemN < d.ZEnd - 1 Then
                    RichTextBox1.SelStart = d.ZStart - 1
                    RichTextBox1.SelLength = d.ZEnd - d.ZStart
                    protectedmode = True
                Else
                    protectedmode = False
                End If
            Next
        Next
        inSelChangeCall = False
    End If
End Sub




0
 
LVL 1

Author Comment

by:FidoBoy
ID: 6340812
Many, many thanks for your code fpaerie, but i'm solved the question by myself in a (i think) better way... I will send u the code if you are interested. And now, for the judges like whs2... how can i close this post, without giving all the points or without doing anything wrong for this group??
0
 
LVL 1

Expert Comment

by:fparie
ID: 6341625
very much interested, Fido

francois.parie@giantsteps.be
0
 
LVL 1

Expert Comment

by:fparie
ID: 6343977
by the way, Fido, allow me to explain what makes this points system tick...

you SPEND 'question points' when you ask a question.
when you receive an answer that works, you grade it and the person who answered receives 'expert points' for it.

so basically it doesn't make a difference to the person who posted the question, the points are spent.
all this person needs to do is grade the answer and the person who answered will get the credit for time and effort spent on answering the question which in turn motivates them to keep answering questions.

francois
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Accepted Solution

by:
fparie earned 200 total points
ID: 6351507
Fido,

You spent the points, might as well grade the answer (and maybe get an answer next time too).

thanks,
francois
0
 
LVL 1

Author Comment

by:FidoBoy
ID: 6352098
ok, i'll accept your answer, but i'll send u my method that i think is a bit better... i will send u by e mail... if i have only a bit of time ;o) thanks!!
0
 
LVL 1

Expert Comment

by:fparie
ID: 6354095
Fido,

Thanks for accepting. Still very much interested in how you solved the issue.

Meanwhile i would like to clarify what some of us have been trying to tell you about grading.

Please have a look at:
http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp
and check out the topic "How Do I Know What Grade to Give?
"

Thanks in advance,
francois
0
 
LVL 1

Expert Comment

by:fparie
ID: 6363319
Fido, some comments on your code
(code can be found below)

1 when i use the cursor keys i can simply go through the protected text char by char
2 when i dragselect to the right into a protected area, it adds the protected area to my selection
3 when i dragselect to the left into a protected area it removes the protected area from my selection
4 in your question you speak of deleting the selection. how do you think you are going to accomplish that with the selprotected property set?

the code i provided you
- behaves well under any type of selection be it dragselection, cursor keys, doubleclick... anything
- allows deletion of protected zones, as you requested

if you were to provide this as an answer i would not be able to give you more than a B for your time and effort.

'''''''''''''''''''''''''''''''''''
' Code as sent By FidoBoy to fparie
'''''''''''''''''''''''''''''''''''
Option Explicit

Private Sub Form_Resize()
    rtbTexto.Width = Me.Width - 100
    rtbTexto.Height = Me.Height - 400

End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set frmPad = Nothing
End Sub

Private Sub rtbTexto_Click()
    Dim Principio As Long
    Dim Final As Long
    Dim Flag As Byte
   
    If rtbTexto.SelProtected Then
        Moviendo = True
        Do While rtbTexto.SelProtected And rtbTexto.SelStart - 1 >= 0
            rtbTexto.SelStart = rtbTexto.SelStart - 1
        Loop
        Principio = rtbTexto.SelStart
        rtbTexto.SelStart = rtbTexto.SelStart + 1
        Do While rtbTexto.SelProtected
            rtbTexto.SelStart = rtbTexto.SelStart + 1
        Loop
        Final = rtbTexto.SelStart
        rtbTexto.SelStart = Principio
        rtbTexto.SelLength = Final - Principio
       
        Moviendo = False
    End If
   
    If IsNull(rtbTexto.SelProtected) Then
        Moviendo = True
        Principio = rtbTexto.SelStart
        Final = rtbTexto.SelStart + rtbTexto.SelLength
        rtbTexto.SelLength = 0
        If Not rtbTexto.SelProtected Then
            rtbTexto.SelStart = Final
            If Not rtbTexto.SelProtected Then
                rtbTexto.SelStart = Principio
                rtbTexto.SelLength = Final - Principio
                Moviendo = False
                Exit Sub
            End If
        End If
        rtbTexto.SelStart = Principio
        If Not rtbTexto.SelProtected Then
            Do While Flag <> 2
                rtbTexto.SelStart = rtbTexto.SelStart + 1
                If rtbTexto.SelProtected And Flag = 0 Then
                    Flag = 1
                End If
                If Not rtbTexto.SelProtected And Flag = 1 Then
                    Flag = 2
                End If
            Loop
            Final = rtbTexto.SelStart
            rtbTexto.SelStart = Principio
            rtbTexto.SelLength = Final - Principio
        Else
            Do While rtbTexto.SelProtected
                rtbTexto.SelStart = rtbTexto.SelStart + 1
            Loop
            rtbTexto.SelLength = Final - rtbTexto.SelStart
        End If
       
        Moviendo = False
    End If

End Sub


0
 
LVL 1

Expert Comment

by:fparie
ID: 6363341
btw

just tried to protect multiple lines and your solution which obviously much better than mine went into an endless loop....

tip: if you're not prepared to let you own code crash, don't test it yourself.

0
 
LVL 1

Author Comment

by:FidoBoy
ID: 6363387
Ok, i will answer to your points...

1) This part of code are missing and i implemented it now..
2) and 3) This is the right behaviour of the program that i want, u can only select the whole protected or nothing, because i use this as as block, you can delete it, change font, etc.. to the whole protected area only (not only a part of it)
3) Ok, i forget to include a module that have a function (very easy to implement) that protect or unprotect the whole text when i call it (like: ProtectDoc (true) or ProtectDoc (False) after and before change the properties or deleting the selected protected area...

And about your code, i used it, but i have troubles... it doesn't work as i expected... I don't know why, but i've copied all exactly as you submited it.. Perhaps, i'm still developing my code to correct it and solve some issues...

Thanks for your help ;o)

Fido
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now