Obscurity Late binding

Hello everyone.

I use MapGisWin OCX in VBA Excel.
When I set Reference to file MapGisWin.OCX, this sub work fine:

Sub test1()

Dim SF1 As New MapWinGIS.Shapefile
SF1.Open ("D:\D1.shp")
Debug.Print SF1.NumShapes

End Sub

But when I remove reference to MapGisWin.OCX and I want to use Late binding, I receive error:

Sub test2()

Dim SF1 As Object, z
Set SF1 = CreateObject("MapWinGIS.Shapefile")
z = SF1.Open("D:\D1.shp", Null)      ' - this line error: Run-time '13' Type mismatch
Debug.Print SF1.NumShapes

End Sub

When I use late binding for other lib, all work fine.
What’s my mistake?


It’s been a while (over a decade) since I used VBA, but can you check if SF1 is properly created?

Hello @Clapter

I was able to reproduce the problem. The second parameter of the Open function would be an address to a Callback function, which if not specified in VBA, should be set to Nothing rather than Null. This is the original “Type Mismatch” error.

Additionally, if you refer to the documentation, the Open function returns a Boolean value. And you will get an “Object variable or With block variable not set” if you attempt to set the Boolean result into ‘z’, which is an Object variable.

I changed the code as follows:

If SF1.Open("D:\D1.shp", Nothing) Then
    Debug.Print SF1.NumShapes 
End If


Hello Jerry!
Your remark about Nothing helped a lot and now everything works without errors!
Thanks a lot!