VB6 Code Help..

Discussion in 'Programmer's Corner' started by Engr, Apr 16, 2010.

  1. Engr

    Thread Starter Member

    Mar 17, 2010
    114
    5
    Hi Guys,

    I am making a code in VB6 that will combine the 2 PDF Files. This is the code that I just copied in the internet:

    Private Sub Command1_Click()
    Me.MousePointer = 11
    Dim origPdfDoc As Acrobat.CAcroPDDoc
    Dim newPdfDoc As Acrobat.CAcroPDDoc
    Dim path As String
    Dim path2 As String
    Dim varNewTotalPages As Long

    path = "C:\Users\joem\Desktop\Databook\New Folder\3.pdf"
    path2 = "C:\Users\joem\Desktop\Databook\New Folder\4.pdf"
    Set origPdfDoc = CreateObject("AcroExch.PDDoc")
    Set newPdfDoc = CreateObject("AcroExch.PDDoc")

    If origPdfDoc.Open(path) Then
    If newPdfDoc.Open(path2) Then
    'Get total # of pages too insert
    varNewTotalPages = newPdfDoc.GetNumPages
    'Insert pages into original pdf
    origPdfDoc.InsertPages True, newPdfDoc, 0, varNewTotalPages, False
    'Save doc
    origPdfDoc.Save PDSaveIncremental, path
    Else
    MsgBox "Failed to open doc " & path2
    End If

    'Close docs
    origPdfDoc.Close
    newPdfDoc.Close
    MsgBox "Pages added to " & path
    Else
    MsgBox "Failed to add pages to " & path
    End If

    Set origPdfDoc = Nothing
    Set newPdfDoc = Nothing
    Me.MousePointer = 0
    End Sub

    I already check the "Adobe Acrobat 9.0 Type Library" but every time I run the program I am always getting this error "ActiveX component can't create object"...Can anybody help me how to solve this?....See attached file for the actual error
     
  2. kingdano

    Member

    Apr 14, 2010
    377
    19
    :eek:

    i never thought id see someone using VB6 for that...people who i have spoken to tend to talk down the capabilities of VB in general - at least up until the latest release which ive heard is more like C++

    i cant help you with that particular problem - but maybe you should try writing a program to simply combine two static .pdf files instead of opening them, and dealing with all of the processing of page numbers...just try to break the program down into more manageable chunks before throwing it all together...that seems to work well for me.
     
  3. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    Is the DLL you are using properly registered? And are you licensed (or does it have a free license) for you to use it in your own program??

    B. Morse
     
  4. bluebrakes

    Active Member

    Oct 17, 2009
    245
    7
    try putting at the very top after the private sub line...

    on error resume next

    and see what it does, does it do anything?

    Also you have stated what the final file name should be? is that right?
     
  5. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    BMorse may be on to something. If the license isn't valid, it may not create a file.
     
  6. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    I actually use VB6 for a lot of tasks people say can only be done with C or C++.... I write almost all my PC based automation software in VB6, which is installed and running all over Michigan, and other states (and a few parts of Canada)...

    B. Morse
     
    kingdano likes this.
  7. Engr

    Thread Starter Member

    Mar 17, 2010
    114
    5
    Yes, my VB6 is licensed. I place the "on error resume next" command and placed a msgbox after getting the number of pages to be added command but it is displaying "0"...See below for the updated program....

    Private Sub Command1_Click()
    On Error Resume Next 'remove this once the program is ready
    Me.MousePointer = 11
    Dim origPdfDoc As Acrobat.CAcroPDDoc
    Dim newPdfDoc As Acrobat.CAcroPDDoc
    Dim path As String
    Dim path2 As String
    Dim path3 As String
    Dim varNewTotalPages As Long

    path = "C:\Users\joem\Desktop\datasheet.pdf"
    path2 = "C:\Users\joem\Desktop\Boolean.pdf"
    path3 = "C:\Users\joem\Desktop\Sample.pdf"
    Set origPdfDoc = CreateObject("AcroExch.PDDoc")
    Set newPdfDoc = CreateObject("AcroExch.PDDoc")

    If origPdfDoc.Open(path) Then
    If newPdfDoc.Open(path2) Then
    'Get total # of pages too insert
    varNewTotalPages = newPdfDoc.GetNumPages
    'varNewTotalPages = origPdfDoc.GetNumPages
    MsgBox varNewTotalPages 'added to get the value of varNewTotalPages
    'Insert pages into original pdf
    origPdfDoc.InsertPages True, newPdfDoc, 0, varNewTotalPages, False
    'Save doc
    origPdfDoc.Save PDSaveIncremental, path3
    Else
    MsgBox "Failed to open doc " & path2
    End If

    'Close docs
    origPdfDoc.Close
    newPdfDoc.Close
    MsgBox "Pages added to " & path3
    Else
    MsgBox "Failed to add pages to " & path3
    End If

    Set origPdfDoc = Nothing
    Set newPdfDoc = Nothing
    Me.MousePointer = 0
    End Sub
     
  8. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    Do us a favor and use the code tags around your code, It helps keep everything easy on the eyes, and brain.

    http://forum.allaboutcircuits.com/showthread.php?t=37117

    you can edit your previous posts and easily edit them.. Also if you click 'Go Advanced' there will be a '#' option in the editor that will auto code-tag your highlighted code, or you can press it then paste the code between the open and close CODE tags.
     
  9. Engr

    Thread Starter Member

    Mar 17, 2010
    114
    5
    Private Sub Command1_Click()
    On Error Resume Next 'remove this once the program is ready
    Me.MousePointer = 11
    Dim origPdfDoc As Acrobat.CAcroPDDoc
    Dim newPdfDoc As Acrobat.CAcroPDDoc
    Dim path As String
    Dim path2 As String
    Dim path3 As String
    Dim varNewTotalPages As Long

    path = "C:\Users\joem\Desktop\datasheet.pdf"
    path2 = "C:\Users\joem\Desktop\Boolean.pdf"
    path3 = "C:\Users\joem\Desktop\Sample.pdf"
    Set origPdfDoc = CreateObject("AcroExch.PDDoc")
    Set newPdfDoc = CreateObject("AcroExch.PDDoc")

    If origPdfDoc.Open(path) Then
    If newPdfDoc.Open(path2) Then
    'Get total # of pages too insert
    varNewTotalPages = newPdfDoc.GetNumPages
    'varNewTotalPages = origPdfDoc.GetNumPages
    MsgBox varNewTotalPages 'added to get the value of varNewTotalPages
    'Insert pages into original pdf
    origPdfDoc.InsertPages True, newPdfDoc, 0, varNewTotalPages, False
    'Save doc
    origPdfDoc.Save PDSaveIncremental, path3

    Else
    MsgBox "Failed to open doc " & path2​
    End If

    'Close docs
    origPdfDoc.Close
    newPdfDoc.Close
    MsgBox "Pages added to " & path3

    Else
    MsgBox "Failed to add pages to " & path3
    End If

    Set origPdfDoc = Nothing
    Set newPdfDoc = Nothing
    Me.MousePointer = 0

    End Sub



    .......Hope this helps
     
  10. kingdano

    Member

    Apr 14, 2010
    377
    19
    **not trying to thread-jack**

    i love vb6 beacuse it is easy, and error-friendly (re-naming of variables, built in functionality etc)

    i have done parallel port comms, serial comms and basic user front-ends with it myself.

    it really is good for a software beginner like me.

    again, sorry for the OT post
     
  11. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    I am talking about the Adobe Acrobat DLL or OCX that you are using in your application, this has to be a registered activex or DLL file in order for you to use it in your program....

    B. Morse
     
  12. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    Thats what I was speaking of also... I thought it was obvious, but I guess we should have clairified. Without the licenced Adobe DLL, it WILL NOT create a pdf. You can open for view all day long. But cannot write to them.
     
  13. Engr

    Thread Starter Member

    Mar 17, 2010
    114
    5
    Where can I get a licensed Adobe DLL.?
     
  14. kingdano

    Member

    Apr 14, 2010
    377
    19
    In order to use the adobe .dll properly you'll need to purchase adobe acrobat professional. by having this software, you have the right (from adobe) to create new .pdf files.

    Do you understand what we are saying?
     
  15. Engr

    Thread Starter Member

    Mar 17, 2010
    114
    5
    Yup...I understand what you are saying..
     
  16. 52735

    New Member

    May 1, 2010
    1
    0
    Thank you.
     
  17. bluedraco20

    New Member

    May 6, 2010
    5
    0
    Did you include the library in the project references and are you licensed to use the library? I'm asking if you have the license for the library itself, not VB.

    *Edit* N/m someone already asked.
     
  18. Engr

    Thread Starter Member

    Mar 17, 2010
    114
    5
    No..I don't have the license for the library
     
Loading...