Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 634
  • Last Modified:

Cannot implicitly convert type 'object' to 'QUANTUMAUTOMATIONLib.Browse2Class'

I am converting the following code from VB to C#. It works in VB but seems to be have some problem in C#. It is the limitation in C# ? Any expert advice ?


public frmMain()
{
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();

      //
      // TODO: Add any constructor code after InitializeComponent call
      //
                  
      // Declare global object
      SessionClass objSession;
      QDataAccessClass objDataAccess;
      Browse2Class objBrowser;
                  
      // Get a Session Object.
      objSession = new SessionClass();
                  
      // Get a DataAccess Object.
      objDataAccess = new QDataAccessClass();

      // Get the Browser Object from Session.
      objBrowser = objSession.Browser;   // <-- **** ERROR ****

      // Give the Session Pointer to the DataAccess object.
      objDataAccess.SetSession(objSession);

      }
0
bhchng
Asked:
bhchng
  • 3
1 Solution
 
TransBindCommented:
perhaps you need to cast it: examples

int newInt = (int) stuff [0];
string newString = (string) stuff [1];
Button button2 = (Button) stuff [2];

objBrowser = (Browse2Class)objSession.Browser;  




0
 
bhchngAuthor Commented:
It works ! Thanks. But why do we cast it ? 'Object' Type diffierence ?
0
 
bhchngAuthor Commented:
It does not give an error when compiling. But when running the program, it says "Specified cast is not valid". Doesnt seems to be the solution.
0
 
bhchngAuthor Commented:
Code in Visual Basic:

'=======================================================================
'Synopsis:      Declare global variables & objects
'-----------------------------------------------------------------------
Option Explicit
Dim objSession As QUANTUMAUTOMATIONLib.Session
Dim WithEvents objDataAccess As QUANTUMAUTOMATIONLib.QDataAccess
Dim objBrowser As QUANTUMAUTOMATIONLib.Browse2
Dim objQualityHelper As QUANTUMAUTOMATIONLib.QQualityHelper


'=======================================================================
'Synopsis:      User Interface Message Handlers
'-----------------------------------------------------------------------


'=======================================================================
'Synopsis:      Create global objects and set it ready for use
'-----------------------------------------------------------------------
Private Sub Form_Load()
' Get a session object for Live DataAccess
Set objSession = New QUANTUMAUTOMATIONLib.Session

' Get a QualityHelper object
Set objQualityHelper = New QUANTUMAUTOMATIONLib.QQualityHelper

' Get the Browser Object from Session.
Set objBrowser = objSession.Browser

End Sub
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now