Question

I am trying to get some code to compile after switching Option Strict On. However I am using some Interop with VB6 and passing in a form object ByRef so Form.Caption fails and I can't convert it to type Form because a VB.NET Form doesn't have a caption property.

How can I can get the following to compile with Option Strict ON:

Public Sub EditFormLegacy(ByRef objForm As Object)

    objForm.Caption = objForm.Caption + " Edited"

End Sub

Is there any way to switch option strict off for specific methods?

Was it helpful?

Solution

You can't turn it off for a method, but you can turn if off for a form or class. Just put "option strict off" at the top of the form. Per MSDN - "If used, the Option Strict statement must appear in a file before any other source code statements." HTH

OTHER TIPS

You really want to leave option Strict on, so I guess you should try a workaround. For example, get the form (with the caption) to store it's Caption in a seperate string, which can be recalled by the new class loading in the form.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top