Event-handling in VB

This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-XChange Printer Drivers SDK (only) - Please use the PDF-Tools SDK Forum for Library DLL assistance.

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Chris - Tracker Supp, Tracker Supp-Stefan, Ivan - Tracker Software, Andrew - Tracker Support, Tracker - Clarion Support, John - Tracker Supp, Support Staff, moderators

Post Reply
BertS
User
Posts: 17
Joined: Wed Sep 22, 2004 7:35 am

Event-handling in VB

Post by BertS » Wed Feb 02, 2005 8:15 am

Hi,

Is there an example of handling events under Visual Basic?
I can't find it in the SDK.

I tried declaring a variable 'withevents' (from CPXCControl), and then the IDE tells me the events. so far so good.
I set 'Active' to True.

But when I create a PDF-file, the events are not triggered.

thank you,
Bert

John - Tracker Supp
Site Admin
Posts: 8204
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada
Contact:

Post by John - Tracker Supp » Wed Feb 02, 2005 10:19 am

Hi Bert,

we do indeed - please see the example project :

VBExCOM located in the SDK install folder :

C:\Program Files\Tracker Software\PDF-XChange PRO 3 SDK\Examples\APIExamples\VBExample\VbExCOM

Assumes a default install.
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com

BertS
User
Posts: 17
Joined: Wed Sep 22, 2004 7:35 am

Post by BertS » Wed Feb 02, 2005 10:44 am

Tracker Support wrote:Assumes a default install.
...of a recent version ;)

thanx

BertS
User
Posts: 17
Joined: Wed Sep 22, 2004 7:35 am

Post by BertS » Wed Feb 02, 2005 12:22 pm

Ok, I tried with the examples.
In the vb-example it seems to work fine.
In the Access-example also, but when I rename the activex-object and instead use the variable 'withevents', it doesn't seem to work?
When I change back to the activex-object, the events are triggered.

I use this code:
As you can check, I've changed:
- variable-declarion
- variable initializing/terminating
- Activated code in event-handlers
- set Active to True instead of False.

Code: Select all

Option Compare Database
Option Explicit

Private WithEvents pxcSObject As pxc30COM.CPXCControl

Private Sub pxcSObject_OnPrintingFinished(ByVal dwJob As Long, ByVal dwState As Long)
    MsgBox "pxcSObject_OnPrintingFinished"
End Sub

Private Sub pxcSObject_OnPrintingStarted(ByVal dwJob As Long, ByVal lpszDocName As String, ByVal lpszAppName As String)
    MsgBox "pxcSObject_OnPrintingStarted"
    pxcSObject.ApplyParams dwJob
End Sub

Private Sub Form_Load()
    Set pxcSObject = New pxc30COM.CPXCControl
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set pxcSObject = Nothing
End Sub

Private Sub Command2_Click()
    Dim rptName As String
    Dim prtLoop As Printer
    For Each prtLoop In Application.Printers
        If prtLoop.DeviceName = "PDF-XChange 3.0" Then
            Exit For
        End If
    Next
    
    If prtLoop.DeviceName <> "PDF-XChange 3.0" Then
        MsgBox "You haven't PDF-XChange 3.0 printer installed!"
        Exit Sub
    End If
    Set Application.Printer = prtLoop
    ' Setting up PDF-XChange
    pxcSObject.SetParamLong 0, "Save.Type", 2
    pxcSObject.SetParamStr 0, "Save.ShowSaveDialog", "No"
    pxcSObject.SetParamStr 0, "Save.FullFileName", "c:\sample_access.pdf"
    pxcSObject.SetParamStr 0, "Save.WhenExists", "Overwrite"
    pxcSObject.SetParamStr 0, "App.Run", "false"
    '
    pxcSObject.SetParamStr 0, "Reg.Key", "Your Registration Key Here"
    pxcSObject.SetParamStr 0, "Reg.DevCode", "Your Developer Code Here"
    '
    pxcSObject.Active = True        ' DisAllow events for this object
    pxcSObject.AutoApply = True      ' Auto apply all passed parameters when printing started
    ' All parameters will be cleared after applying, so they must
    ' be specified before each printing.
    ' Don't use Events, because Access VB doesn't works good with multythreaded environment
    ' Now print report
    rptName = "SampleReport"
    DoCmd.OpenReport rptName
End Sub

John - Tracker Supp
Site Admin
Posts: 8204
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada
Contact:

Post by John - Tracker Supp » Wed Feb 02, 2005 2:29 pm

Hi,

I am a little confused as to why you want to rename - but in any case in Access you cannot have events called during "DoCmd" operation(s), because VB blocks external calls during such operations.

Have no idea why - but it is a fact.
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com

BertS
User
Posts: 17
Joined: Wed Sep 22, 2004 7:35 am

Post by BertS » Wed Feb 02, 2005 3:17 pm

It's not that I want to rename, but I don't want to use the activex-object (i.e. because that requires a form as 'host'). Instead, I want to use the control only in code, such as is commented in the default Access example.
...but it is a fact
Sorry, I don't agree fully ;)
It supports events that are triggered by a control (such as the 'physical' control on the form), because it works in that mode.

Now I understand that events from a withevents-declaration are not triggered if Access is executing a DoCmd-action? That's new for me, but it could be.

Ok, then I know that when I want to handle the events, that I've to use the 'physical' control.

thank you,
Bert

John - Tracker Supp
Site Admin
Posts: 8204
Joined: Tue Jun 29, 2004 10:34 am
Location: Vancouver Island - Canada
Contact:

Post by John - Tracker Supp » Wed Feb 02, 2005 3:41 pm

Clarification acknowledged :D
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com

Post Reply