Solved

McRider

Posted on 2000-03-08
11
272 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

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
 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

803 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