McRiders RichTextBox OLE

Hi I read McRiders answer to a question about OLE and RTF.
Cant u just use:

'Text1.Text contains the address to the Image, like C:\image.jpg



Sub Form_Load
Label1.Caption="-1"
End Sub

Command1_Click
Label1.Caption=Label1.Caption+1
Clipboard.Clear
Clipboard.Setdata=Picture1.Picture
RichTextBox1.Setfocus
Sendkeys "+{INSERT}",True
RichTextBox1.OLEObjects.Item(Label1.Caption).Key=Text1.Text
ClipBoard.Clear
End Sub

Command2_Click
Dim CountOle As String
Dim CountObj As Long
Dim Info As String
Again:
CountOle=RichTextBox1.OLEObjects.Count-1
For CountObj = 0 To CountOle
On Error Resume Next
Info=RichTextBox1.OLEObjects.Item(CountObj).Key

MsgBox(Info)
Goto Again
Next CountObj

End Sub

This Works For me. But if anyone can modify the code to leave the image address (key) where the Image where in the exact same place, that would be great.
It has to work even tough the text between and over the images has been modified or the Images has been dragged to another position. I dont need a msgbox to come up when someone click them. Just basicly replace them with its address. To remove an image use the RichTextBox1.OLEObjects.Remove(??).

I have also noticed that the Objects looses its Key when draged to another position in the RTF-Box. Any suggestions on how to work around this problem?

Im writing a WYSIWYG html editor for my final exscam in school. Any Help would be Great.

Thanks a lot Jenny!



JennyFlowerAsked:
Who is Participating?
 
mcriderConnect With a Mentor Commented:
Are you still there??? Did the information I gave you work??


Cheers!®©
0
 
Geo24Commented:
Nope, you stole me question  :)
I dont think anyone here knows how to do that, Its probobly impossible.

0
 
Geo24Commented:
Why didnt you just post this as a comment to my question? grrr
What you need is to figure out their position like .selstart or whatever, but the OLE in RTF dosent support theese methods. Tried that been there done that.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
JennyFlowerAuthor Commented:
Adjusted points to 180
0
 
JennyFlowerAuthor Commented:
Im sure someone will be able to actually answer my question, not only barely suggest a comment to it.

0
 
Geo24Commented:
Try this, it should work better than your code, since it deletes the oles and leave the keys. Not in the right order tough, depending on if you move them around or not.

'---------------------------------------'Just add a picture to picture1
Private Sub Command1_Click()
Clipboard.Clear
Label1.Caption = Label1.Caption + 1
Clipboard.SetData Picture1.Picture
RichTextBox1.SetFocus
SendKeys "+{INSERT}", True
RichTextBox1.OLEObjects.Item(Label1.Caption).Key = Text1
Clipboard.Clear
End Sub
Private Sub Command2_Click()
Dim CountOle As Long
Dim VarOle As Long
Dim Info As String
CountOle = RichTextBox1.OLEObjects.Count - 1
For VarOle = 0 To CountOle
On Error Resume Next
Info = RichTextBox1.OLEObjects.Item(VarOle).Key
MsgBox (Info)
Next VarOle
End Sub
Private Sub Command3_Click()
Dim CountOle As Long
Dim VarOle As Long
Dim Info As String
Again:
CountOle = RichTextBox1.OLEObjects.Count - 1
For VarOle = 0 To CountOle
On Error Resume Next
Info = RichTextBox1.OLEObjects.Item(VarOle).Key
RichTextBox1.OLEObjects.Remove (VarOle)
RichTextBox1.SelText = Info
RichTextBox1.SelText = vbCrLf
GoTo Again
Next VarOle
End Sub

Private Sub Form_Load()
Command1.Caption = "&Add OLE"
Command2.Caption = "&Show Keys"
Command3.Caption = "&Remove OLE Objects"
Text1.Text = "Unique Key, has to be different each time you add an OLE OBJ."
Label1.Caption = "-1"
Form1.Caption = "OLE DEMO"
End Sub
'---------------------------------------
0
 
Geo24Commented:
Try this, it should work better than your code, since it deletes the oles and leave the keys. Not in the right order tough, depending on if you move them around or not.

'---------------------------------------'Just add a picture to picture1
Private Sub Command1_Click()
Clipboard.Clear
Label1.Caption = Label1.Caption + 1
Clipboard.SetData Picture1.Picture
RichTextBox1.SetFocus
SendKeys "+{INSERT}", True
RichTextBox1.OLEObjects.Item(Label1.Caption).Key = Text1
Clipboard.Clear
End Sub
Private Sub Command2_Click()
Dim CountOle As Long
Dim VarOle As Long
Dim Info As String
CountOle = RichTextBox1.OLEObjects.Count - 1
For VarOle = 0 To CountOle
On Error Resume Next
Info = RichTextBox1.OLEObjects.Item(VarOle).Key
MsgBox (Info)
Next VarOle
End Sub
Private Sub Command3_Click()
Dim CountOle As Long
Dim VarOle As Long
Dim Info As String
Again:
CountOle = RichTextBox1.OLEObjects.Count - 1
For VarOle = 0 To CountOle
On Error Resume Next
Info = RichTextBox1.OLEObjects.Item(VarOle).Key
RichTextBox1.OLEObjects.Remove (VarOle)
RichTextBox1.SelText = Info
RichTextBox1.SelText = vbCrLf
GoTo Again
Next VarOle
End Sub

Private Sub Form_Load()
Command1.Caption = "&Add OLE"
Command2.Caption = "&Show Keys"
Command3.Caption = "&Remove OLE Objects"
Text1.Text = "Unique Key, has to be different each time you add an OLE OBJ."
Label1.Caption = "-1"
Form1.Caption = "OLE DEMO"
End Sub
'---------------------------------------
0
 
JennyFlowerAuthor Commented:
Adjusted points to 200
0
 
JennyFlowerAuthor Commented:
No, Im sorry but I cant except your answer since I need it to leave the picture keys in the exact same place as the Object removed.
Like for instance if I use your code to insert an image with the key="one" and the next one with the key="two" and then try to add picture number three with the key="three" between them, it doesnt display the correct order. I dont mean to be rude, but I dont think you can help me with this.

0
 
Geo24Commented:
!#@#!! :(
0
 
mcriderCommented:
JennyFlower,

I was going back through unanswered questions and saw this one... Basically, what you're going to have to do is keep track of the position of the objects as you add them. An Ole object takes up 1 character in a richtextbox.

Let's say you have an Ole object at position 105 in the richtextbox... To replace the OLE object with text, you would do this:

   RichText1.SelStart=105
   RichText1.SelLength=1
   Clipboard.SetData RichText1.SelText
   RichText1.SelText="Your text goes here"

   You have to also keep track of the length of the data you inserted...
You OLE is now on the clipboard and has been replaced with the text... You would then save the clipboard data so you could put it back over the text you inserted...

Does this make sense?


Cheers!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.