Solved

McRider

Posted on 2000-03-08
11
271 Views
Last Modified: 2010-05-02
Hi!

Your code, the one with the ole objects drag and stuff is excellent.

But if I try to type any text between the images or press enter so that the image go down to the next line it looses its index. Is there anyway to work around this so that you can do anything in the rtf box and still make the images keep their indexes?

/Geo
0
Comment
Question by:Geo24
  • 6
  • 5
11 Comments
 
LVL 14

Expert Comment

by:mcrider
ID: 2598589
On the keypress event, you need to check where the richtextbox SelStart property is, then walk the chain of images I created.  If the .Start property of the chain item is > than the richtextbox SelStart property, add 1 to the .Start property of the chain item...


Does this make sense?


Cheers!®©
0
 

Author Comment

by:Geo24
ID: 2599774
Almost, but where in the code do I add this?
0
 

Author Comment

by:Geo24
ID: 2600074
Adjusted points to 620
0
 

Author Comment

by:Geo24
ID: 2600075
Can you put the code in there? Ive tried but failed.
0
 
LVL 14

Accepted Solution

by:
mcrider earned 620 total points
ID: 2600256
This is what your RichTextBox KeyPress Event should look like...


Cheers!



THE CODE:

    Private Sub RichTextBox1_KeyPress(KeyAscii As Integer)
        Dim iVal As Long
        Dim jVal As Long
        Dim kVal As Long
        Dim lDelItem() As Long
       
        jVal = RTobject.SelStart
        kVal = RTobject.SelLength
        If RTobject.SelLength = 0 Then
            For iVal = LBound(RTobjects) To UBound(RTobjects)
                With RTobjects(iVal)
                    If jVal > .Offset And jVal < .Offset + .Length Then
                        'INSIDE OBJECT, CANT TYPE THERE.
                        Beep
                        KeyAscii = 0
                        Exit For
                    End If
                    If .Offset >= jVal Then .Offset = .Offset + 1
                End With
            Next iVal
        Else
            ReDim lDelItem(0) As Long
            For iVal = LBound(RTobjects) To UBound(RTobjects)
                With RTobjects(iVal)
                    If .Offset >= jVal And .Offset < jVal + kVal Then
                        lDelItem(UBound(lDelItem)) = iVal
                        ReDim Preserve lDelItem(UBound(lDelItem) + 1) As Long
                    End If
                    If .Offset >= jVal Then .Offset = .Offset - kVal + 1
                End With
            Next iVal
            If UBound(lDelItem) > 0 Then
                For iVal = UBound(lDelItem) - 1 To LBound(lDelItem) Step -1
                    For jVal = lDelItem(iVal) To UBound(RTobjects) - 1
                        RTobjects(jVal) = RTobjects(jVal + 1)
                    Next jVal
                    On Error Resume Next
                    ReDim Preserve RTobjects(UBound(RTobjects) - 1) As RTobjType
                    If Not Err = 0 Then ReDim RTobjects(-1) As RTobjType
                Next iVal
            End If
        End If
    End Sub
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 14

Expert Comment

by:mcrider
ID: 2600349
Thanks for the points! Glad I could help!


Cheers!
0
 

Author Comment

by:Geo24
ID: 2600351
I think Im gonna post a question worth 80 points to you aswell, since you are the only one who can help me with this stuff:)

Cheers Mate!
0
 

Author Comment

by:Geo24
ID: 2600400
Everything works fine now, but you cant press enter cause then the image under the caret looses its index, is this easy to fix? And also if you delete a picture that over another one, the one below looses its index. Is there any easy way to fix this? Or is it not possible at all?
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2600404
;-)
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2600460
To fix it so the ENTER key works properly, change the KeyPress Event to look like this...


    Private Sub RichTextBox1_KeyPress(KeyAscii As Integer)
        Dim iVal As Long
        Dim jVal As Long
        Dim kVal As Long
        Dim lDelItem() As Long
        Dim lOffset As Long
       
        On Error Resume Next
        iVal = UBound(RTobjects)
        If Not Err = 0 Then Exit Sub
        If KeyAscii = 13 Then
            lOffset = 2
        Else
            lOffset = 1
        End If
       
        jVal = RTobject.SelStart
        kVal = RTobject.SelLength
       
        If RTobject.SelLength = 0 Then
            For iVal = LBound(RTobjects) To UBound(RTobjects)
                With RTobjects(iVal)
                    If jVal > .Offset And jVal < .Offset + .Length Then
                        'INSIDE OBJECT, CANT TYPE THERE.
                        Beep
                        KeyAscii = 0
                        Exit For
                    End If
                    If .Offset >= jVal Then .Offset = .Offset + lOffset
                End With
            Next iVal
        Else
            ReDim lDelItem(0) As Long
            For iVal = LBound(RTobjects) To UBound(RTobjects)
                With RTobjects(iVal)
                    If .Offset >= jVal And .Offset < jVal + kVal Then
                        lDelItem(UBound(lDelItem)) = iVal
                        ReDim Preserve lDelItem(UBound(lDelItem) + 1) As Long
                    End If
                    If .Offset >= jVal Then .Offset = .Offset - kVal + lOffset
                End With
            Next iVal
            If UBound(lDelItem) > 0 Then
                For iVal = UBound(lDelItem) - 1 To LBound(lDelItem) Step -1
                    For jVal = lDelItem(iVal) To UBound(RTobjects) - 1
                        RTobjects(jVal) = RTobjects(jVal + 1)
                    Next jVal
                    On Error Resume Next
                    ReDim Preserve RTobjects(UBound(RTobjects) - 1) As RTobjType
                    If Not Err = 0 Then ReDim RTobjects(-1) As RTobjType
                Next iVal
            End If
        End If
    End Sub






I'll have to work on the delete...  I'll get that to you later... Possibly on that 80 point question you were talking about??? ;-)


Cheers!®©
0
 

Author Comment

by:Geo24
ID: 2600578
Yes please:)

Thanx!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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 …
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…
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…

910 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

25 Experts available now in Live!

Get 1:1 Help Now