hexagon logo

Need help with VB6 .Net

Upgraded my workstation to Windows 10, so VB6 is no longer an option for my PC-DMIS software efforts.

I've got Visual Studio 2107 now, and I've run into a problem using PC-DMIS collections. In a nutshell, vb6 .net doesn't recognize them as collections. I have to declare the PC-DMIS application as "Object" in order to be able to enumerate through the collections. I was told that this means it's doing "late binding" - who cares. I need intellisense because I'm a terrible typist. In the screenshot below, if I change the declaration of the "app" variable to type "Object", the compile error goes away, and the code runs fine. But I don't see this as a solution.

I'll also point out that the Microsoft's File System Object collections work just fine when used in the same manner.

Has anyone got the solution to this problem?


Parents
  • Unfortunately I haven't done *any* work in VB.NET (I use the superb Delphi (Pascal) environment when not programming PC-DMIS Basic, Excel or other exotic languages). Actually, I haven't done anything .NET...

    I believe a collection must implement a certain interface/iterator to have "for each" to work - it looks like PC-DMIS is not doing it (or exporting it) in exactly the right way.

    In theory, it looks like you should be able to write an iterator in VB - https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/for-each-next-statement might give some clues for a workaround.


    A while back I downloaded "Visual Basic Express 2010" on my home laptop, because I knew that obsolescence was on the horizon. IT guys at work kept warning me. I found it sitting in my download folder, never installed. Was intending to use it to start learning vb .net - I'd downloaded it in 2013, installed it last night. What we have here is a lack of execution. Slight smile

    In this learning version, the "Iterator" keyword isn't recognized - much to my dismay. So I had to give up on that approach. I'll get back to that at work, where I've got a registered copy of .NET.

    I did look at another direction. This approach looked like it was going to work. It made the squiggly lines indicating compiler errors go away. But at runtime, it throws an exception: "Unable to cast COM object of type 'System.__ComObject' to interface type 'PCDLRN.Command'" I'm posting the code in case someone spots a mistake.

    I've also found that it's possible to add to existing classes using Extension(). This intrigues me because I can extend the functionality of the pc-dmis collection (maybe). To be honest, I'm having trouble connecting the dots on these object oriented concepts. They existed in VB6 as well, but I never needed to use them. Gave me a small headache reading about all this. Will forge ahead. I've also got Don Ruggieri helping. Not giving up...

    The green stuff is another attempt I made. The blue line is what gave me hope - spot anything that might make it work?

    Imports PCDLRN
    Imports System.Collections
    Imports System.Runtime.CompilerServices
    
    Module Module1
    
        Sub Main()
    
            Dim app As Application = CreateObject("PCDLRN.Application", "")
            Dim prg As PartProgram = app.ActivePartProgram
            Dim cmds As Commands = prg.Commands
    
    [COLOR=#0000CD] 'Dim cmds As List(Of Commands) = New List(Of Commands) From {app.ActivePartProgram.Commands}[/COLOR]
    
            '
    [COLOR=#008000]        'This doesn't work either
            'Dim cmds As Command = CTypeDynamic(Of System.Collections.IEnumerator)(app.ActivePartProgram.Commands)
            'Debug.Print(cmds("PNT1").typedescription)[/COLOR]
    
            ' Casting cmds to object here works, but may as well declare as Object
            For Each cmd As PCDLRN.Command In CObj(cmds)
                Debug.Print(cmd.TypeDescription)
            Next
    
        End Sub
    
    End Module
    



Reply
  • Unfortunately I haven't done *any* work in VB.NET (I use the superb Delphi (Pascal) environment when not programming PC-DMIS Basic, Excel or other exotic languages). Actually, I haven't done anything .NET...

    I believe a collection must implement a certain interface/iterator to have "for each" to work - it looks like PC-DMIS is not doing it (or exporting it) in exactly the right way.

    In theory, it looks like you should be able to write an iterator in VB - https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/for-each-next-statement might give some clues for a workaround.


    A while back I downloaded "Visual Basic Express 2010" on my home laptop, because I knew that obsolescence was on the horizon. IT guys at work kept warning me. I found it sitting in my download folder, never installed. Was intending to use it to start learning vb .net - I'd downloaded it in 2013, installed it last night. What we have here is a lack of execution. Slight smile

    In this learning version, the "Iterator" keyword isn't recognized - much to my dismay. So I had to give up on that approach. I'll get back to that at work, where I've got a registered copy of .NET.

    I did look at another direction. This approach looked like it was going to work. It made the squiggly lines indicating compiler errors go away. But at runtime, it throws an exception: "Unable to cast COM object of type 'System.__ComObject' to interface type 'PCDLRN.Command'" I'm posting the code in case someone spots a mistake.

    I've also found that it's possible to add to existing classes using Extension(). This intrigues me because I can extend the functionality of the pc-dmis collection (maybe). To be honest, I'm having trouble connecting the dots on these object oriented concepts. They existed in VB6 as well, but I never needed to use them. Gave me a small headache reading about all this. Will forge ahead. I've also got Don Ruggieri helping. Not giving up...

    The green stuff is another attempt I made. The blue line is what gave me hope - spot anything that might make it work?

    Imports PCDLRN
    Imports System.Collections
    Imports System.Runtime.CompilerServices
    
    Module Module1
    
        Sub Main()
    
            Dim app As Application = CreateObject("PCDLRN.Application", "")
            Dim prg As PartProgram = app.ActivePartProgram
            Dim cmds As Commands = prg.Commands
    
    [COLOR=#0000CD] 'Dim cmds As List(Of Commands) = New List(Of Commands) From {app.ActivePartProgram.Commands}[/COLOR]
    
            '
    [COLOR=#008000]        'This doesn't work either
            'Dim cmds As Command = CTypeDynamic(Of System.Collections.IEnumerator)(app.ActivePartProgram.Commands)
            'Debug.Print(cmds("PNT1").typedescription)[/COLOR]
    
            ' Casting cmds to object here works, but may as well declare as Object
            For Each cmd As PCDLRN.Command In CObj(cmds)
                Debug.Print(cmd.TypeDescription)
            Next
    
        End Sub
    
    End Module
    



Children