Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy first 5 words of textbox into another textbox 4

Status
Not open for further replies.

Ergo30

IS-IT--Management
Jun 22, 2007
10
GB
Hi

I need help again. I am trying to get the code to be able to read the first 5 words from a text box and copy them into another textbox.

Please help

Cheers

Simon
 
>FirstWords = Trim$(.Execute(strSource)(0))

strongm,


I have been learning regular expressions for a while after reading a post you had several months ago. Was just wondering what the 0 in the above string is for?


 
OOPS
>Was just wondering what the 0 in the above string is for?

Never mind I read further in these postings and got it "the index". My Bad
 
>What's the point of the WM_USER? Why can't you just define EM_GETOLEINTERFACE as &h43C?

You can, but the definition using WM_USER gives an important visual clue that this message is a user-defined message privately used by RichEdit control class, not a standard message recognized by all windows.

See the documentation of WM_USER which states the following.

MSDN said:
WM_USER Notification
The WM_USER constant is used by applications to help define private messages for use by private window classes, usually of the form WM_USER+X, where X is an integer value.
As per documentation, all messages in the range WM_USER to 0x7FFF are "Integer messages for use by private window classes".

Most header files follow this convention. EM_GETOLEINTERFACE is also defined in richedit.h as follows.
[tt]#define EM_GETOLEINTERFACE (WM_USER + 60)
[/tt]
All other user-defined messages are also defined in the same way. For example, the TTM_GETTOOLCOUNT message which returns the number of controls associated with a tooltip control, is defined in commctrl.h as:
[tt]#define TTM_GETTOOLCOUNT (WM_USER + 13)
[/tt]
VB API Viewer files are extracted from windows header files. Therefore the declaration format used by API Viewer is also the same.

The following declaration
[tt]#define EM_GETOLEINTERFACE (WM_USER + 60)[/tt]

gets translated to VB syntax as follows.
[tt]Const EM_GETOLEINTERFACE = (WM_USER + 60)[/tt]
 
>WM_USER gives an important visual clue that this message is a user-defined message
Thanks Hypetia, that makes good sense. Sort of like using vbObjectError when you raise errors in your own classes.

strongm, I'm not sure I get something here. First, it's clear that myIunknown supports the ITextDocument interface, once SendMessage is called. ("typeof myIunknown is ITextDocument" evaluates to true.) However, I can't send tomDoc instead of myIunknown to sendmessage; that hangs. Now, I'm seeing from the documentation that this particular sendmessage returns an IRichEditOLE object, which of course explains why SendMessage hangs when you send it an ITextDocument object. However, neither object returned true when I used QueryInterface to see if IRichEditOLE is implemented; of course it couldn't recognize the type. I thought I'd experiment with adding a reference to IRichEditOLE, and it turns out that IRichEditOLE isn't registered as a COM interface, but it implements the ITextDocument interface, which is.

So, is it not a COM class? And if that's so, is it also true that ITextDocument is a COM interface implementation of IRichEditOLE? And therefore, is the whole purpose of using the iUnknown object and then polymorphizing it into an ITextDocument object to circumvent the original return structure defined by EM_GETOLEINTERFACE which simply returns a reference to a (non-COM) IRichEditOLE object, which VB can't handle because it's not COM-based?
 
Yes, it is a COM class, just one that doesn't have an interface that is (easily) accessible or useable from VB.

TOM is an alternative interface that we can get access to
 

Dim a as string
Dim b as string

a = Text1.Text
b = Split(a, " ")

Dim i
For i = 0 To UBound(strAryWords)
Text2.Text = Text2.Text & b(i) & "" & " "
Next


use this code. very easy and flexible. u get your first five word in the Text2 at the end of the loop. Enjoy it !!!!!!

WaZda
 
sorry, there was a mistake in the previous one.

Dim a as string
Dim b as string

a = Text1.Text
b = Split(a, " ")

Dim i
For i = 0 To 4
Text2.Text = Text2.Text & b(i) & "" & " "
Next
 
Hypetia's code earlier in this thread is a leaner version of this approach
 
Which would you say is the most efficient, as in, fastest, with the least RAM/CPU usage.

I'd guess at the regular expression way, but I'd probably be wrong.
 
<just one that doesn't have an interface that is (easily) accessible or useable from VB.

Aha. I think I have it. iRichEditOLE doesn't have a dual interface and ITextDocument does.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top