Program code is not executed

A batch process loads an image, creates a thumbnail, and saves it to another folder. I want to override ImagePro settings (image dimensions, export path, etc.) with program code. If I integrate this particular program code (method SaveImageAsThumbnail), the entire program code is no longer executed (button: "Create and Export Thumbnail"). When I comment out part of the program code ("from here" to "to here"), the program no longer runs. Only if I remove the program code ("from here" to "to here") will the rest of the program be executed again.

Public Sub SaveImageAsThumbnail

    Dim newSaveFileName As String
    Dim window1, doc1, varList1

    newSaveFileName = "C:\temp\Thumbnail.png"

    With MediaCy.Automation.Application.WindowCommands.Active(Nothing)
        .Run(window1)
    End With

    With MediaCy.Automation.Application.DocumentCommands.Activate(Nothing)
        .Run(window1, doc1)
    End With

    ' from here
    With MediaCy.Automation.Application.ApplicationCommands.SetOption(Nothing)
        .Module = "QuickSave"
        .Section = "Publication"
        .Key = "Extension"
        .Value = "PNG"
        .Run()
    End With

    With MediaCy.Automation.Application.ApplicationCommands.SetOption(Nothing)
        .Module = "QuickSave"
        .Section = "Publication"
        .Key = "Reopen"
        .Value = False
        .Run()
    End With

    With MediaCy.Automation.Application.ApplicationCommands.SetOption(Nothing)
        .Module = "QuickSave"
        .Section = "Publication"
        .Key = "UseCurrentZoom"
        .Value = False
        .Run()
    End With

    With MediaCy.Automation.Application.ApplicationCommands.SetOption(Nothing)
        .Module = "QuickSave"
        .Key = "PlaySound"
        .Value = False
        .Run()
    End With

    With MediaCy.Automation.Application.ApplicationCommands.SetOption(Nothing)
        .Module = "QuickSave"
        .Section = "Publication"
        .Key = "ImageSize"
        .Value = 1000
        .Run()
    End With

    With MediaCy.Automation.Application.ApplicationCommands.SetOption(Nothing)
        .Module = "QuickSave"
        .Section = "Publication"
        .Key = "Path"
        .Value = newSaveFileName
        .Run()
    End With
    ' to here

    With MediaCy.Automation.Application.WindowCommands.QuickSaveSelectedForPublication(Nothing)
        .Run(varList1)
    End With

End Sub


What do I have to consider? Why does not this work?
A simple example is attached.

Thanks in advance
fsup

Best Answer

  • Accepted Answer
    Hi fsup,

    It looks like some strange behavior of VB interpreter in App code that's related to formatting (or reserved keywords).
    What I've found is that if you remove spaces in Module lines, like this: .Module="QuickSave"
    (instead of .Module = "QuickSave") everything works fine.

    Another solution would be to move your function into a Module (not App), just "Add new Module" to your project  (e.g. Module1.vb) and move the function there, then call it like this:
        Private Sub button1_Click_1(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles button1.Click
            MsgBox "Save Image as Thumbnail."
    
           Module1.SaveImageAsThumbnail()
        End Sub
    

    We will investigate this problem further, for now you can use these workarounds.

    Yuri

Answers

Sign In or Register to comment.