Solved

McRider

Posted on 2000-03-08
11
270 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
Comment Utility
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
Comment Utility
Almost, but where in the code do I add this?
0
 

Author Comment

by:Geo24
Comment Utility
Adjusted points to 620
0
 

Author Comment

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

Accepted Solution

by:
mcrider earned 620 total points
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 14

Expert Comment

by:mcrider
Comment Utility
Thanks for the points! Glad I could help!


Cheers!
0
 

Author Comment

by:Geo24
Comment Utility
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
Comment Utility
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
Comment Utility
;-)
0
 
LVL 14

Expert Comment

by:mcrider
Comment Utility
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
Comment Utility
Yes please:)

Thanx!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…

763 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

9 Experts available now in Live!

Get 1:1 Help Now