[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

McRider

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
Geo24
Asked:
Geo24
  • 6
  • 5
1 Solution
 
mcriderCommented:
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
 
Geo24Author Commented:
Almost, but where in the code do I add this?
0
 
Geo24Author Commented:
Adjusted points to 620
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Geo24Author Commented:
Can you put the code in there? Ive tried but failed.
0
 
mcriderCommented:
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
 
mcriderCommented:
Thanks for the points! Glad I could help!


Cheers!
0
 
Geo24Author Commented:
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
 
Geo24Author Commented:
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
 
mcriderCommented:
;-)
0
 
mcriderCommented:
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
 
Geo24Author Commented:
Yes please:)

Thanx!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now