Results 1 to 9 of 9

Thread: using a print function in visual basics

  1. #1

    Thread Starter
    Member
    Join Date
    May 2002
    Posts
    44

    using a print function in visual basics

    hi, im having some real trouble getting my program to print my source code,

    here is the code im using

    Private Sub Print_Click()
    Dim BeginPage, EndPage, NumCopies, i
    ' Set Cancel to True
    CommonDialog1.CancelError = True
    On Error GoTo ErrHandler
    ' Display the Print dialog box
    CommonDialog1.ShowPrinter
    ' Get user-selected values from the dialog box
    BeginPage = CommonDialog1.FromPage
    EndPage = CommonDialog1.ToPage
    NumCopies = CommonDialog1.Copies
    For i = 1 To NumCopies
    ' Put code here to send data to the printer


    Next i
    Exit Sub
    ErrHandler:
    ' User pressed the Cancel button
    Exit Sub
    End Sub

    I have a commondialog box, i found out how to print the form, but I can not find out how to print my source code, if any of you could help, it would be greatly appriated

    thanks

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    u will have to open all the files that u'r project consists of and print it...

    frm, cls, clt, bas ...

    is that what u want to do?
    -= a peet post =-

  3. #3
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    If you want to print your source code of the current application directly from the VB IDE through your app (whoa, confusing), it's not going to work. You're going to have to open the .frm file through your app to get the text.

    As for how exactly to print: A search on these forums will give you many many examples.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4

    Thread Starter
    Member
    Join Date
    May 2002
    Posts
    44
    I have pull down menus in my program, it consists of 6 forms,

    I want to be able to start the program, go to the pull down menu file, go to print, and be able to print the entire source code I used for the lab. I just cant figure out how to print source in run time

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    are you typing the source into your program? or are you trying to get it from the VB IDE?

    You're going to have to load each file that's used by your project into a string and then print it. You can't just retrieve the source through code and print it.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6

    Thread Starter
    Member
    Join Date
    May 2002
    Posts
    44
    so what youre sayign is that there is no way I would be able to print my source code, by using the code I had used above, im some what a beginner so try not to use words or phrases I might not understand

  7. #7
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    You have to open the files that your project consist of, and then print it.

    VB Code:
    1. Private Sub Command3_Click()
    2.     CommonDialog1.ShowPrinter
    3.     Open "C:\MyApp\Form1.frm" For Binary As #1
    4.         s = Input(LOF(1), 1)
    5.     Close #1
    6.     Printer.Print s, CommonDialog1.hDC
    7.     Printer.EndDoc
    8. End Sub

    the sample will print source code (and some) of the From1 in the project located in C:\MyApp
    -= a peet post =-

  8. #8

    Thread Starter
    Member
    Join Date
    May 2002
    Posts
    44
    im still lost here, I put the code

    CommonDialog1.ShowPrinter
    Open "C:\Kyle\Computer Science and Design Grade 10\Lab 10\Form1.frm" For Binary As #1
    s = Input(LOF(1), 1)
    Close #1
    Printer.Print s, CommonDialog1.hDC
    Printer.EndDoc

    in every command and just everything in my form, then so I still need the code I used in the very first part, so when I click my print button it should print the code in what ever commands I put that code commondialog.showprint
    open.............

    please help

  9. #9
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Well if you compile your code into an exe then there is no code to print considering that it got compiled to machine lingo so the idea of printing code at runtime wont work. Having said that you can do like the others suggested and open the actually files (.frm, .mod, .prj) and print them OR even better from the IDE (since you'll need to print at desing time anyway) you can go to the menu at the top of the IDE and click FILE then PRINT, select 'Current Project', check 'Code' and hit Ok and it'll print all your source code for ya!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width