Option Strict On disallows late binding error.

S

Scott Howell

How can I do this without turning Strict Off!!!!
Sub GetBatchInfo()

Dim oARGet As Object = CreateObject("ProtrackAR.ARGet"), aBatchInfo
As String()

If CStr(ARStatusOldBatchID) = "0" Then

aBatchInfo = oARGet.GetActiveBatchForUser(ARStatusUserID) <--
Error HERE!

If IsArray(aBatchInfo) Then
If aBatchInfo(1) <> "" Then
ARStatusBatchID = DirectCast(aBatchInfo(1), Integer)
End If

If Trim(aBatchInfo(0)) <> "" Then
ARStatusPostingDate = FormatGMTDate(aBatchInfo(0))
bARStatusBatchHasPostingDate = True
End If
End If
End If

If CStr(ARStatusBatchID) = "0" Then
ARStatusBatchIDDisplay = "None"
Else
ARStatusBatchIDDisplay = CStr(ARStatusBatchID)
ARStatusBatchTextTitle = "Click here to toggle out of BatchID "
& ARStatusBatchID
End If

End Sub
 
O

OmegaSquared

Hello, Scott,

You need to declare oARGet as whatever type it is that CreateObject actually
returns. For example, make your declarations something like:

Dim oARGet As WhatEverTypeThisIs =
DirectCast(CreateObject("ProtrackAR.ARGet"), WhatEverTypeThisIs)
Dim aBatchInfo As String()

where "WhateverTypeThisIs" is the type that supports the
GetActiveBatchForUser method (which presumably returns a String array).

BTW. I recommend making your declarations on a individual lines. Makes it
easier to document with comments. :)

Cheers,
Randy
 
B

Branco Medeiros

Scott said:
How can I do this without turning Strict Off!!!!
   Sub GetBatchInfo()

        Dim oARGet As Object = CreateObject("ProtrackAR.ARGet"), aBatchInfo
As String()

        If CStr(ARStatusOldBatchID) = "0" Then

            aBatchInfo = oARGet.GetActiveBatchForUser(ARStatusUserID)  <--
Error HERE!
<snip>

Maybe you could use CallByName (not sure if it is available with
Option Strict On):

<example>
Dim oARGet As Object = CreateObject("ProtrackAR.ARGet")
Dim aBatchInfo As String()
If CStr(ARStatusOldBatchID) = "0" Then

aBatchInfo = CallByName( _
oARGet, _
"GetActiveBatchForUser", _
CallType.Method, _
ARStatusUserID _
)
'...
</example>

HTH.

Regards,

Branco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top