Method to access code of CFixPicture object

I've in the past used the following to access the objects of the current graphic:

Dim picCurrent As CFixPicture

' Assuming "CFixPicture" is your custom object representing the workspace application

' Set the active document's page to picCurrent (replace this with your application's object reference)
Set picCurrent = Application.ActiveDocument.Page

Then i can use methods like ContainedObjects to search the graphic for objects to manipulate. But now, i want to search the actual script within the Worksppace Application Object and can not find a suitable method to do so. Perhaps I need to define a different type than CFixPicture. I could use CFixPicture to still search objects, but when I want to search the text, I can define a separate object.

I am trying to do the following. Step 1 requires i search the script, I have the code written aside from figuring out how to access the graphics script

'1. Find frszFPExpert "MODULE"
'2. Identify which sub it is located in
'3. get sub name minus "_Click()"
'4. find object that contains name from 3.
'5. find ps_DataSource within object
'6. get current value of ps_DataSource minus "DVSYS."
'7. Replace "MODULE" in 1. with current value from 6.

  • As far as I am aware the VBA code behind a picture is not available as a single entity.

    Instead each object has a Procedures collection containing Procedure objects representing the individual procedures that apply to that object, eg Click, Edit etc. The Procedure object has a Lines collection containing ScriptLine objects representing each line of the procedure. The ProcedureStatement property of the ScriptLine gives a string which is the actual statement. All this is fairly easily worked out by looking at iFix Automation Help available from the Help menu in the VBA editor.

    Therefore to find where frszFPExpert "MODULE" has been used you need to work through all the objects and contained objects. Then for each object work through each line of each procedure in the procedures collection.

    The following shows the basic idea without any of the iteration required applied to the top level picture object :

    Sub ScriptEnumeration()
    Dim picCurrent As Object, objProcedures As Object, objScriptProc As Object, objScriptLine As Object
    If Application.ActiveDocument Is Nothing Then
    MsgBox "No picture open!", vbCritical
    Exit Sub
    End If
    If Application.ActiveDocument.Type <> "FIX.Picture" Then
    MsgBox "The document with the focus is not a picture", vbCritical
    Exit Sub
    End If
    Set picCurrent = Application.ActiveDocument.Page
    For Each objScriptProc In picCurrent.Procedures
    Set objScriptLine = objScriptProc.Lines.Item(1)
    Debug.Print objScriptLine.ProcedureStatement
    Next
    End Sub
  • In reply to Cedric Dawnhawk:

    Ended up doing this. which has to run from the VB editor since it's VBIDE library usage, but that worked fine for what i needed. I just run the Module script instead of cliciking a button on a custom toolbar to start the script. Thanks thouhg. I;ll keep this in mind if i ever need to try this again.

    Dim picCurrent as CFixPicture
    ' Set the active document's page to picCurrent (replace this with your application's object reference)
    Set picCurrent = Application.ActiveDocument.Page

    ' Use Application.ThisObjectName to get the (Name) of the Workspace Application Object
    Dim objectName As String
    objectName = picCurrent.Name

    ' Set the text you want to search for (use double double-quotes to escape the inner quotes)
    Dim searchText As String
    searchText = "frszFPExpert ""MODULE"""

    ' Access the VBComponent of the Workspace Application Object
    Dim vbProj As VBIDE.VBProject
    Dim vbComp As VBIDE.VBComponent
    Dim codeMod As VBIDE.CodeModule

    Set vbProj = VBE.ActiveVBProject

    Set vbComp = vbProj.VBComponents(objectName) ' Use the objectName as the VBComponent name

    ' Access the code of the module
    Set codeMod = vbComp.CodeModule
    Dim codeText As String
    codeText = codeMod.Lines(1, codeMod.CountOfLines)
  • In reply to TreyB:

    That's certainly easier than via the iFix object model! Thanks for sharing.