Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reflection 2008, Visual Basic 2010 .dll, and Excel 2007

Status
Not open for further replies.

npburns

Technical User
Feb 2, 2012
1
US
I had created a .dll file to work with EXTRA! Enterprise 2000 which I then referenced in Excel, and other applications. Our IT is in the process of upgrading our Attachmate, and I and several others are now using Reflections 2008, so I need to update my DLL. I am looking to either open an existing Session, or open a new session as needed. My prior code is below:
Code:
    Private System As Object
    Private Session As Object
    Private Screen As Object

    Private Sub ExtraSessionCheck(Optional ByVal SessionNumber As Integer = 0)
        Dim temp As String


        System = CreateObject("EXTRA.System")
        If (System Is Nothing) Then
            MsgBox("Could not create the EXTRA System object.  Aborting macro playback.", 48, "Capture32")
            InitFlag = False
            Stop
        End If

        ' Get the necessary Session Object
        If SessionNumber >= 1 And SessionNumber <= 3 Then
            On Error GoTo ErrorCatch
            temp = Environ("ProgramFiles") & "\Attachmate\E!E2K\Sessions\SESSION" & Trim(Str(SessionNumber)) & ".EDP"
            Session = System.Sessions.Item(temp)
            On Error GoTo 0
        Else
            Session = System.ActiveSession
        End If

        If (Session Is Nothing) Then
            On Error GoTo ErrorCatch
            temp = Environ("ProgramFiles") & "\Attachmate\E!E2K\Sessions\SESSION" & Trim(Str(SessionNumber)) & ".EDP"
            Session = System.Sessions.Item(temp)
            On Error GoTo 0
            If (Session Is Nothing) Then
                MsgBox("Could not create the Session object.  Aborting macro playback.", 48, "Capture32")
                InitFlag = False
                Stop
            End If
        End If
        Screen = Session.Screen
        If Session.Visible = False Then Session.Visible = True

        If Screen.GetString(25, 2, 1) = " " Then
            Session.Connected = True
        End If

        InitFlag = True
        Exit Sub

ErrorCatch:
        Session = System.Sessions.Open(temp)
        Resume

    End Sub

I tried tweaking the code, using things like ExtraCOM and ReflectionCOM, but had no luck. With enough searching around the web, I found an entirely different way to do things, and it works great in Visual Studio with a test program, and with a standalone .exe test program:
Code:
    Private System08 As Attachmate.Reflection.Framework.Application 
    Private Session08 As Attachmate.Reflection.Emulation.IbmHosts.IIbmTerminal 
    Private Screen08 As Attachmate.Reflection.Emulation.IbmHosts.IIbmScreen 

 Private Sub ReflectionSessionCheck(Optional ByVal SessionNumber As Integer = 0)
        Dim viewFrame As Attachmate.Reflection.UserInterface.IFrame 
        Dim view As Attachmate.Reflection.UserInterface.IView 

        InitFlag = False
        Try
            'Capture an open Reflection Session, on error, it will open an new session
            System08 = Attachmate.Reflection.Framework.MyReflection.CreateApplication(50000)
            Windows.Forms.Application.DoEvents()
            Try
                'Open an exsisting session, if the session is not available, the error will open a new session
                viewFrame = System08.GetObject("Frame")
                If SessionNumber >= 1 And SessionNumber <= 3 Then   'If a specific view is requested, it opens that view, if not, it opens the active view
                    view = viewFrame.AllViews(SessionNumber - 1)
                Else
                    view = viewFrame.SelectedView
                End If
                Session08 = view.Control
                Windows.Forms.Application.DoEvents()
                If Session08.IsConnected = False Then
                    Session08.Connect()
                    Windows.Forms.Application.DoEvents()
                End If
                InitFlag = True
                Exit Try
            Catch ex As Exception
                'Open a new session, if none is specified, it will open session 1
                If SessionNumber < 1 Or SessionNumber > 3 Then SessionNumber = 1
                Session08 = System08.CreateControl(Environ("ProgramFiles") & "\Attachmate\Reflection2008\Setup\SESSION" & Trim(Str(SessionNumber)) & ".rd3x")
                Windows.Forms.Application.DoEvents()
                viewFrame = System08.GetObject("Frame")
                Windows.Forms.Application.DoEvents()
                view = viewFrame.CreateView(Session08)
                Windows.Forms.Application.DoEvents()
                InitFlag = True
                Exit Try
            End Try
            InitFlag = True
            Exit Try
        Catch ex As Exception
            Try
                'Open a new Reflection Program, and a new session.  If none is specified, it will open session 1.  On Error, open Extra
                Attachmate.Reflection.Framework.MyReflection.Start(50000, True)
                Windows.Forms.Application.DoEvents()
                System08 = Attachmate.Reflection.Framework.MyReflection.CreateApplication(50000)
                Windows.Forms.Application.DoEvents()
                If SessionNumber < 1 Or SessionNumber > 3 Then SessionNumber = 1

                Session08 = System08.CreateControl(Environ("ProgramFiles") & "\Attachmate\Reflection2008\Setup\SESSION" & Trim(Str(SessionNumber)) & ".rd3x")
                Windows.Forms.Application.DoEvents()
                viewFrame = System08.GetObject("Frame")
                Windows.Forms.Application.DoEvents()
                view = viewFrame.CreateView(Session08)
                Do While Session08.IsConnected = False
                    Windows.Forms.Application.DoEvents()
                Loop
                Windows.Forms.Application.DoEvents()
                InitFlag = True
                Exit Try
            Catch ex2 As Exception
                Call MsgBox(ex2.Message.ToString, MsgBoxStyle.Critical)
                InitFlag = False
                Exit Sub
            End Try
        End Try

        'Set the screen
        Screen08 = Session08.Screen

    End Sub

The problem I am having is when I try to run this code from Excel 2007 VBA, I get the following error “Unable to cast transparent proxy to type ‘Attachmate.Reflection.Framework.IBase’” when I run line:
Code:
 Session08 = System08.CreateControl(Environ("ProgramFiles") & "\Attachmate\Reflection2008\Setup\SESSION" & Trim(Str(SessionNumber)) & ".rd3x")
I am willing to throw everything I have out the window if needed, but I need to find a way to bridge from Excel 2007 VBA to Attachmate Reflection 2008 with a VB .net DLL. Please forgive any poor coding practices, since I am Mechanical Engineer, not a computer programmer, but I need this to help with data mining.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top