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?


  • If it "just works" with an added iterator, your chance for errors will be quite small, just verify that the iterator works, and then copy it into all the programs.

    As for Pascal, I don't think there's any free Delphi, but the FreePascal with Lazarus IDE is completely free, and almost the same as Delphi ( https://www.lazarus-ide.org/). Quite a big leap from Turbo Pascal, though, with all this fancy Object Orientation...
  • Using "Object" (late binding) has the additional plus effect of not being tied to a certain version of PC-DMIS. In theory, it should be slower than early binding, though.
  • It's been a very long time since I did this, but did you update the references (do you still have to do this?) in .NET? Tools...References, see if the PCDMIS library can be turned on, otherwise you need to browse for it. I honestly can't remember the name of the file (or files) you need to add to the references, someone knows, I'm sure.
  • Thanks for the suggestion. I did update the reference, used both pcdlrn.tlb and interop.pcdlrn.dll. My understanding is that we should be using the latter in .net
  • I'll have to remember to find this later, I always forget which files need to be linked.... Isn't there also an olb you need to bring in?
  • I've never used a .OLB in VB6. In vb .net - I have no idea. I'll have a look at what's in there on Monday. Thanks
  • 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
    



  • I guess you can say I'm a VB.NET user, I've never done anything with Object Oriented Programming yet other than follow along YT tutorials. You don't need OOP skills to develop PCD apps in .NET though it would be worth learning it.
  • I just need to learn enough to see if PCD collections can be made to work right. Declaring as Object makes everything work. I could easily just drop it. I can still keep my programming style intact. I just really really like and depend on intellisense.
  • Also agree that the OOP stuff isn't necessary for what I/we do. Just need to understand how to use available objects.