I have a number of rich text boxes on my application that print data received from a digital modem type device. At times it is necessary to copy a window to another window because some of the text in the RTF window is colored and formatted a certain way I thought the best way was to copy the RTF of the window to the other window. But when I run the program and I attempt to copy the text I get this same error either in run mode r if I break the code and try to manually read the RTF.
?Hostform.rtfRX(0).TextRTF
'Hostform.rtfRX(0).TextRTF' threw an exception of type 'System.MissingMemberException'
ClassName: Nothing
Data: {System.Collections.ListDictionaryInternal}
HResult: -2146233070
HelpLink: Nothing
InnerException: Nothing
MemberName: Nothing
Message: "Public member 'TextRTF' on type 'RichTextBox' not found."
Signature: Nothing
Source: "Microsoft.VisualBasic"
StackTrace: " at Microsoft.VisualBasic.CompilerServices.Symbols.Container.GetMembers(String& MemberName, Boolean ReportErrors)" & vbCrLf & " at Microsoft.VisualBasic.CompilerServices.NewLateBinding.ObjectLateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)" & vbCrLf & " at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)"
TargetSite: {System.Reflection.MemberInfo[] GetMembers(System.String ByRef, Boolean)}
The same error is shown it I use .RTF or .TextRTF I do not understand why the RTF can't be found when I'm using a Rich Text Box. I'm using a WinForm and made sure the correct type of RTF is being used.
Is there something special I need to turn on the RTF output?
It appears that what you have done is accessed your
RichTextBoxvia anObjectreference withOption Strict Off. That's bad to start with. You should haveOption Strict Onpretty much all the time and write your code accordingly. I added aRichTextBoxto my form and accessed it directly via the generated field in the Immediate window and I got this result:?RichTextBox1.Rtf "{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang2057{\fonttbl{\f0\fnil Segoe UI;}}" & vbCrLf & "{\*\generator Riched20 10.0.22621}\viewkind4\uc1 " & vbCrLf & "\pard\f0\fs18 Hello\par" & vbCrLf & "World\par" & vbCrLf & "}" & vbCrLf ?RichTextBox1.TextRTF NothingI then did this:
and used that
xvariable in the Immediate window and got this:?x.Rtf "{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang2057{\fonttbl{\f0\fnil Segoe UI;}}" & vbCrLf & "{\*\generator Riched20 10.0.22621}\viewkind4\uc1 " & vbCrLf & "\pard\f0\fs18 Hello\par" & vbCrLf & "World\par" & vbCrLf & "}" & vbCrLf ?x.RTF "{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang2057{\fonttbl{\f0\fnil Segoe UI;}}" & vbCrLf & "{\*\generator Riched20 10.0.22621}\viewkind4\uc1 " & vbCrLf & "\pard\f0\fs18 Hello\par" & vbCrLf & "World\par" & vbCrLf & "}" & vbCrLf ?x.TextRTF 'x.TextRTF' threw an exception of type 'System.MissingMemberException' ClassName: Nothing Data: {System.Collections.ListDictionaryInternal} HResult: -2146233070 HelpLink: Nothing InnerException: Nothing MemberName: Nothing Message: "Public member 'TextRTF' on type 'RichTextBox' not found." Signature: Nothing Source: "Microsoft.VisualBasic.Core" StackTrace: " at Microsoft.VisualBasic.CompilerServices.Symbols.Container.GetMembers(String& memberName, Boolean reportErrors)" & vbCrLf & " at Microsoft.VisualBasic.CompilerServices.NewLateBinding.ObjectLateGet(Object instance, Type type, String memberName, Object[] arguments, String[] argumentNames, Type[] typeArguments, Boolean[] copyBack)" & vbCrLf & " at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)" TargetSite: {System.Reflection.MemberInfo[] GetMembers(System.String ByRef, Boolean)}You should have
Option Strict Onto start with, so the code you have should not compile. Whether you have to or not, you should be casting thatObjectreference as the actual type of the object, then you can access members of that type directly, without late binding. Using my example: