1

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?

Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
  • possible duplicate of [VB.Net equivalent for C# 'dynamic' with Option Strict On](http://stackoverflow.com/questions/2889974/vb-net-equivalent-for-c-dynamic-with-option-strict-on) – Hans Passant Jun 16 '11 at 08:57

2 Answers2

3

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

Wade73
  • 4,359
  • 3
  • 30
  • 46
0

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.

BertvanDorp
  • 93
  • 1
  • 9
  • I don't see how that would work because the .NET side will still not know what type of object is being passed – Matt Wilko Jun 16 '11 at 13:08