Matt Wilko
Matt Wilko

Reputation: 27322

how to use Option Strict On and Late Binding

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?

Upvotes: 1

Views: 1392

Answers (2)

BertvanDorp
BertvanDorp

Reputation: 93

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.

Upvotes: 0

Wade73
Wade73

Reputation: 4509

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

Upvotes: 3

Related Questions