none
How do I convert this from VB to C#. Not sure what a CType is RRS feed

  • Question

  • I believe I found the solution to a problem I'm having but the answer is in VB. And I don't understand part of it. I need 

    appAccess = CType(Marshal.GetActiveObject("Access.Application"), Microsoft.Office.Interop.Access.Application)

    converted to C#. Can anyone please help? Thanks

    Monday, February 10, 2020 9:01 PM

Answers

  • CType will covert the object before the comma to the type after the comma.

    In C# you put the final type of object you want in parenthesis before the object to covert:

    appAccess = (Microsoft.Office.Interop.Access.Application)Marshal.GetActiveObject("Access.Application");
    
    
    I think this will work, not really a VB guy anymore.

    • Proposed as answer by Castorix31 Monday, February 10, 2020 9:45 PM
    • Marked as answer by ASI Tech Monday, February 10, 2020 9:55 PM
    Monday, February 10, 2020 9:38 PM

All replies

  • CType will covert the object before the comma to the type after the comma.

    In C# you put the final type of object you want in parenthesis before the object to covert:

    appAccess = (Microsoft.Office.Interop.Access.Application)Marshal.GetActiveObject("Access.Application");
    
    
    I think this will work, not really a VB guy anymore.

    • Proposed as answer by Castorix31 Monday, February 10, 2020 9:45 PM
    • Marked as answer by ASI Tech Monday, February 10, 2020 9:55 PM
    Monday, February 10, 2020 9:38 PM
  • That's it! Thank you!
    Monday, February 10, 2020 9:55 PM