?
Solved

McRiders RichTextBox OLE

Posted on 2000-02-21
11
Medium Priority
?
406 Views
Last Modified: 2008-02-20
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!



0
Comment
Question by:JennyFlower
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 

Expert Comment

by:Geo24
ID: 2543878
Nope, you stole me question  :)
I dont think anyone here knows how to do that, Its probobly impossible.

0
 

Expert Comment

by:Geo24
ID: 2544013
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
 

Author Comment

by:JennyFlower
ID: 2544065
Adjusted points to 180
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:JennyFlower
ID: 2544066
Im sure someone will be able to actually answer my question, not only barely suggest a comment to it.

0
 

Expert Comment

by:Geo24
ID: 2544155
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
 

Expert Comment

by:Geo24
ID: 2544157
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
 

Author Comment

by:JennyFlower
ID: 2544176
Adjusted points to 200
0
 

Author Comment

by:JennyFlower
ID: 2544177
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
 

Expert Comment

by:Geo24
ID: 2544203
!#@#!! :(
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2577051
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
 
LVL 14

Accepted Solution

by:
mcrider earned 800 total points
ID: 2608060
Are you still there??? Did the information I gave you work??


Cheers!®©
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…
Suggested Courses

770 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