For a project I have to be able to read infromation from an Excel sheet and then pass that information on to a PLC. Sadly I have a problem when I use 'Dim App As New Excel.Application' For some reason this make my application crash before the form shows itself on the screen, so that I end up with no form. The Error I get is:
An unhandled exception of type 'System.InvalidOperationException' occurred in OpHoopVanZegen.exe
This happens in the 'Application.Designer.vb'
Protected Overrides Sub OnCreateMainForm()
Me.MainForm = Global.OpHoopVanZegen.Form1
End Sub
^^^Where the error happens^^^
Additional info: Cannot convert COM-object from type System.__ComObject to interfacetype
Anyone that could explain me what's going on and /or what I'm doing wrong?
------------------------------------ My Form Code:
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Dim App As New Excel.Application
Dim svrOPC As New OPCAutomation.OPCServer
Dim WithEvents grpOPC As OPCAutomation.OPCGroup
Private Sub connectToOPC_Click(sender As Object, e As EventArgs) Handles connectToOPC.Click
If svrOPC.ServerState = OPCAutomation.OPCServerState.OPCDisconnected Then
Call svrOPC.Connect("Kepware.KEPServerEX.V5")
End If
Me.TBStatusOPC.Text = udfOPCServerState(svrOPC.ServerState)
End Sub
Private Sub Form1_Activated(sender As Object, e As EventArgs) Handles Me.Activated
Me.TBStatusOPC.Text = udfOPCServerState(svrOPC.ServerState)
End Sub
Private Function udfOPCServerState(ByVal intOPCServerState As Integer) As String
Select Case intOPCServerState
Case OPCAutomation.OPCServerState.OPCRunning
udfOPCServerState = "Running"
Case OPCAutomation.OPCServerState.OPCFailed
udfOPCServerState = "Failed"
Case OPCAutomation.OPCServerState.OPCNoconfig
udfOPCServerState = "No Config"
Case OPCAutomation.OPCServerState.OPCSuspended
udfOPCServerState = "Suspended"
Case OPCAutomation.OPCServerState.OPCTest
udfOPCServerState = "Test"
Case OPCAutomation.OPCServerState.OPCDisconnected
udfOPCServerState = "Disconnected"
Case Else
udfOPCServerState = "Unknown"
End Select
End Function
Private Sub LoadOrderToPLC_Click(sender As Object, e As EventArgs) Handles LoadOrderToPLC.Click
End Sub
End Class