checking if an object exists before using it

If you are a VB developer and have questions about using our products from VB, here is the place to post them.
Post Reply
urbanfox
Posts: 5
Joined: Wed Nov 17 2004

checking if an object exists before using it

Post by urbanfox » Mon Nov 22 2004

I know I can read in all the objects on a page and cycle through them to see if any of them have the right name, but is there a more efficient way to check if an object exists before attempting to update it?

e.g. something like

Code: Select all

if PDF1.Object("name1") is not null then
    PDF1.ObjectAttribute("name1", "Left") = 200
end if
Can that be done?

Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan » Tue Nov 23 2004

Hello,

You can call something like:

Code: Select all

If PDF.ObjectAttribute( "ObjectType","ObjectName" ) <> ""  Then
      'Make the Needed changes to the Object
else
       Messagebox "Object Not found"
End if
Last edited by Joan on Tue Nov 23 2004, edited 1 time in total.

urbanfox
Posts: 5
Joined: Wed Nov 17 2004

Post by urbanfox » Tue Nov 23 2004

Do you mean like:

Code: Select all

If PDF1.ObjectAttribute(acObjectTypeText, "name1") <> "" Then
    'Make the Needed changes to the Object
    PDF1.ObjectAttribute("name1", "Text") = "new text"
Else
    Call DebugTextBox("Object Not found")
End If
I am still getting problems with that code. I'm not sure I have the first line right or what exactly you meant by it.

urbanfox
Posts: 5
Joined: Wed Nov 17 2004

Post by urbanfox » Fri Nov 26 2004

I still need help with this. Can anyone give me an exact code sample that definitely works in the demo version 1.50i?

Joan
Amyuni Team
Posts: 2799
Joined: Wed Sep 11 2002
Contact:

Post by Joan » Mon Nov 29 2004

Please find here a Visual Basic code that checks for a given object if it exists or not:

Code: Select all

Dim CreatorRef As New ACPDFCREACTIVEX.PDFCreactiveX 
Dim obj As New ACPDFCREACTIVEX.acObject

Private Sub GetObject_Click()

With CreatorRef
    .Open inDirectory + "simplePDF.pdf", ""
    .SetLicenseKey Licensee, ActivationCode

Set obj = .GetObjectByName("acText1")
    If obj Is Nothing Then
        MsgBox "Unable to find object"
    Else
        MsgBox "Object found"
    End If
    
End With
 
End Sub
Hope this helps.

urbanfox
Posts: 5
Joined: Wed Nov 17 2004

Post by urbanfox » Mon Nov 29 2004

Thanks Joan, with a wee bit of tweaking to suit my own code, I was able to get that working.

Post Reply