Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Creating a C# script to open and command a .VB script

Discussion in 'Scripting' started by twalker118, Mar 15, 2015.

  1. twalker118

    twalker118

    Joined:
    Mar 14, 2015
    Posts:
    4
    Hi, I need help with Creating a C# script to open and command a .VB script within Visual Studio 2013. The reason for this is because Im trying to command an external program through Unity, and the external program will only tie in to a .VB script. So is it possible to write C# script that then commands the .VB script? I attached a picture below of the VB code that needs to be commanded through a C# script.

    P.S. Im a beginner so please go easy on me.
    Capture.PNG
     
  2. shaderop

    shaderop

    Joined:
    Nov 24, 2010
    Posts:
    942
    What you want to do here is called "inter-process communication." Your Unity program is one process and your VB program is another. There are several ways to communication between processes, but the one that is probably the easiest to do in this particular scenario would be to send a custom Windows message through the Win32 API, which is not going to be easy because you'll have a lot of new concepts to wrestle with.

    There's a decent example of inter-process communication using Windows messages in Visual Basic on CodeProject. Jump through that rabbit hole and see where it leads you. If you work that example and refer to MSDN often, then you should be able to get it to work.

    Good luck.
     
    twalker118 likes this.
  3. twalker118

    twalker118

    Joined:
    Mar 14, 2015
    Posts:
    4
    Is there anyway in Unity to write function scripts in Visual basic? Or can you only write in C#?
     
  4. shaderop

    shaderop

    Joined:
    Nov 24, 2010
    Posts:
    942
    There is no way to write Visual Basic functions in Unity. I'm guessing that this AxVSAConsole1 is a ActiveX component that you're trying to control from Visual Basic, and in turn control that from Unity. It would be optimal to directly embed that ActiveX control in Unity, but as far I know that is not possible.

    What are you trying to do exactly? There are easier way to skin this cat if you just want to launch the VB application from Unity without controlling it after launch.
     
  5. twalker118

    twalker118

    Joined:
    Mar 14, 2015
    Posts:
    4
    You are correct this is an ActiveX component. What I have going on is I have an animatronic robot that is controlled and operated by a program called VSA or Visual Show Automation http://www.brookshiresoftware.com/index.htm . Which I then want to control using VSA Console http://www.brookshiresoftware.com/console_overview.htm . The VSA Console allows me to play, pause, move through frames etc. all from outside the program using Visual Basic.
     
  6. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,377
    Technically... there is a way to write VB.Net in Unity.

    You'd just have to write it in Visual Studio, compile it, and then stick the dll in your plugins folder.

    The writing of VB isn't the issue here though. OP, you want to have WinForms application running that is accessed from Unity. If you had written the WinForms application in C#, you'd have just as much of an issue accessing it from Unity as if it were written in VB.Net. The problem isn't the language, it's the fact you want two different programs running on two different frameworks (winforms vs unity) to access one another.

    Here's the other thing... you're VB.Net code is using ActiveX to set up a VSA Console interop session.

    You want unity to interop with this program, so it can interop with another program...

    How about this... what are you attempting to do? Maybe we can come up with a far better solution.
     
    MagicZelda likes this.
  7. twalker118

    twalker118

    Joined:
    Mar 14, 2015
    Posts:
    4
    What I have going on is I have an animatronic robot that is controlled and operated by a program called VSA or Visual Show Automation http://www.brookshiresoftware.com/index.htm . Which I then want to control using VSA Console http://www.brookshiresoftware.com/console_overview.htm . The VSA Console allows me to play, pause, move through frames etc. all from outside the program using Visual Basic. The reason im using Unity is to create an ipad app/game that then talks to VSA console through Visual Studio.
     
  8. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,377
    First and foremost, I'm going to explain that VSA Console is a ActiveX component. This means that it can ONLY run on Windows platforms. ActiveX is a windows specific thing.

    Next, you're not restricted to Visual Basic. ActiveX is supported by .Net in general, so you can code against it with whatever .Net language you'd like.

    This does NOT mean you can easily do so in Unity. Unity technically isn't .Net... it uses an augmented version of the Mono framework, which is the open source/cross platform version of .Net.

    From the looks of the documentation that I can get access to (this is a pay program, an old one at that, so finding the documentation is a bitch), this ActiveX control really just starts up the VSA program that is installed on your computer and interops with it, which IT then communicates to your robot. Talk about some daisy chaining... ugh. Unity to your winforms app to vsa to robot...

    I've gotten ActiveX controls to work in mono applications deployed to windows in the past, but I've never tried doing it with Unity directly. If you know of a demo version of the VSA Console ActiveX control that I could test with, I could see if I could load it up.

    Otherwise... I wonder if the VSA documentation describes the interface of their program. Because I mean honestly... if all this ActiveX control is doing is starting up an instance of VSA and accessing that! Well... that can easily be done in Mono as well. The only problem is that we'd need to know the interface of it so that we knew the format of the commands to throw at it.
     
  9. shaderop

    shaderop

    Joined:
    Nov 24, 2010
    Posts:
    942
    Then you can safely scrap most of the ideas thrown at you in this thread. That ActiveX control is a binary program compiled to run on a Windows operating system. You won't be able to run it on a iPad, iOS, Android, or even a Windows Phone device. So there won't anything for the Unity app to control.

    You might be able to get by with what would be effectively writing a server in Visual Basic that listens to command over a TCP/IP socket and uses those command to drive the ActiveX control.
     
    Last edited: Mar 16, 2015
    twalker118 likes this.