Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Beginner
Aug 6, 1997



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Print A Single Sub Or Function

The problem? You want to print a single sub but VB always prints all the subs that are in the current form. You could copy it to the clipboard and print it with the MS-Editor or Notepad. You could buy expensive tools to do this seemingly simple task. Here's a less annoying solution to the problem. Generate a small form. Add a command button. The caption may be "Print Sub." Then, add this code to the module:
 Sub Command1_Click ()
	' Make sure that VB has the focus
	AppAcitvate "Microsoft Visual Basic"
	' Move the cursor to the upper left corner. 
	' The sub can contain a maximum of 500 lines.
	' send SHIFT together with the DOWN key 
	' to mark the whole sub.
SendKeys "{Home}{UP 500} + ({DOWN 500}) % (EC)", True 
	' Copy SUB to the clipboard
Printer.Print Clipboard.GetText()
	' Print Clipboard
	' Un-mark the SUB
SendKeys "{HOME}"
End Sub
Generate the EXE and run it together with VB. Move the Print-Sub form to a convenient desktop position. If you want a single sub of your project to be printed, set the cursor to any position in this SUB and click on the Print-Sub button. I've tested the code with VB3 Pro. In other VB Versions (such as the German Standard edition) you might have to change the "%(EC)" portion. "EC" refers to the VB menu bar.
Andreas Schilling
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date