Solved

McRiders RichTextBox OLE

Posted on 2000-02-21
11
364 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
  • 5
  • 4
  • 2
11 Comments
 

Expert Comment

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

0
 

Expert Comment

by:Geo24
Comment Utility
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
Comment Utility
Adjusted points to 180
0
 

Author Comment

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

0
 

Expert Comment

by:Geo24
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Expert Comment

by:Geo24
Comment Utility
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
Comment Utility
Adjusted points to 200
0
 

Author Comment

by:JennyFlower
Comment Utility
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
Comment Utility
!#@#!! :(
0
 
LVL 14

Expert Comment

by:mcrider
Comment Utility
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 200 total points
Comment Utility
Are you still there??? Did the information I gave you work??


Cheers!®©
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

728 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

11 Experts available now in Live!

Get 1:1 Help Now