# VB printing program



## calibretto (Nov 1, 2001)

I need a VB program that will print the contents of a textbox. Very basic program. Honestly I just need a text box and a print button. I know a little about VB, but making it print is still new to me. I've checked out some tutorials online and they help, but it's still a bit shady. Can anyone here help me out with this? I'm not asking you guys to write the code for me, just a little advice and how to so that I can write it myself. Thanks in advance, guys.


----------



## draceplace (Jun 8, 2001)

This is what I came up with and it does work. If you want to change printer from default its a whole different game. Change file and folder to your own stuff.

No print button it automatically prints when you close the text box.

Const ForWriting = 2
TargetFolder = "C:\ascripts\"
TargetFile = "input.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:\ascripts\input.txt", ForWriting, True)

Input = InputBox("Enter your stuff here")
objTextFile.WriteLine Input
objTextFile.Close
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(TargetFolder)
Set colItems = objFolder.Items
For Each objItem in colItems
If objItem = TargetFile Then
objItem.InvokeVerbEx("Print")
Else
End If
Next


----------



## calibretto (Nov 1, 2001)

Thanks, but that's not really what I need. The program is for a friend of mine who runs a flower shop. It's more of a favor that I never should have agreed to try because my knowledge of programming isn't really that extensive. It's more of an every now and then hobby than anything else. Anyway... what they basically want is a text box that they can enter whatever is to be written on a card, click print and voila the manual feed on the printer pulls the card in and prints the text on it. Easy enough, except for I've never written a program that prints to a printer before. 

All I can find in tutorials online is the Printer object and using printer.print to print different things. I thought it was just be as easy as Printer.Print TextBox1.Text, but it doesn't seem to be. I'm getting an error saying that I need to declare Printer. I just want to print to the default printer and I'm sure there's something tiny that I'm overlooking or an easy way to decare Printer as the Windows default printer, but I"m not seeing it.


----------



## draceplace (Jun 8, 2001)

VB doesn't have a print function you kinda have to use what you can find. This "objItem.InvokeVerbEx("Print")" is actually the thing you get when you right click on a file, then select print. Thats why you have to go thru the gyrations in the code above.

I really don't see why it won't work for your purpose. You can control where the text lands on the card by throwing in line feeds or you could Throw up some more text boxes to enter the To: From: and Message: then format them to match the card.


----------



## calibretto (Nov 1, 2001)

Hmm... well far be it from me to argue over the matter with you because I'm sure you're knowledge on the subject is much more than mine. But why am I seeing all of these VB tutorials talking about the Print object and listing Printer.Print "text" as a way of printing to the Windows default printer? Is there something I'm missing?


----------



## draceplace (Jun 8, 2001)

VBscript doesn't have a printer function Visual Basic itself does sort of. If I remember its quirky to work with. I still want to say that you won't find 'Print' in an obj Browser. You may simply need a statement like 
Dim prnt As Printer
but not sure.
I have to admit my vast knowleged doesn't extend very far into Visual Basic. The code above is VBscript.


----------

