|
-
Apr 5th, 2008, 07:34 PM
#1
Thread Starter
Member
[resolved]printing values from notepad to the printer
hi i was wondering if someone can help me out. i wanted to print the values stored in the notepad file to the printer when i hit the command button. thx
Private Sub cmdlabel_Click()
Open "database.txt" For Output As #1
Print #1, txtnamest
Print #1, txtaddressst
Print #1, txtaddressst1
Print #1, txtcityst, txtstatest, txtzipcodest
Print #1, txtcountryst
Close #1
End Sub
Last edited by likewhoa; Apr 8th, 2008 at 07:00 PM.
-
Apr 5th, 2008, 07:42 PM
#2
Thread Starter
Member
Re: printing values from notepad to the printer
also for this line
Print #1, txtcityst, txtstatest, txtzipcodest
i was wondering if i can take out those spaces in between when it gets stored in notepad.
-
Apr 6th, 2008, 01:52 AM
#3
Re: printing values from notepad to the printer
try print #1, txtcityst & txtstatest & txtzipcodest
but if you want to separate the txts you will have to do that your self like
print #1, txtcityst & "," & txtstatest & "," & txtzipcodest
change the comma if you prefer some other separator, or put a space
to print the same to a printer
vb Code:
Print.print txtnamest Print.print txtaddressst Print.print txtaddressst1 Print.print txtcityst, txtstatest, txtzipcodest Print.print txtcountryst printer.enddoc ' finished so print and feed the paper out
if you want to set the font or font size etc do that before the code above
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Apr 6th, 2008, 04:47 AM
#4
Re: printing values from notepad to the printer
 Originally Posted by likewhoa
i was wondering if i can take out those spaces in between when it gets stored in notepad.
Wouldn't everything run together making it difficult to read?
-
Apr 6th, 2008, 12:04 PM
#5
Thread Starter
Member
Re: printing values from notepad to the printer
yess it worked thank you !!!
-
Apr 6th, 2008, 12:05 PM
#6
Thread Starter
Member
Re: printing values from notepad to the printer
actually those spaces were more like tabs in between so they were too far apart.
-
Apr 7th, 2008, 12:41 PM
#7
Thread Starter
Member
Re: printing values from notepad to the printer
hi i tested it but it does not print on the printer. but the spaces are ok now
-
Apr 7th, 2008, 01:26 PM
#8
Re: printing values from notepad to the printer
 Originally Posted by likewhoa
hi i tested it but it does not print on the printer. but the spaces are ok now
What does it do?
-
Apr 7th, 2008, 01:33 PM
#9
Re: printing values from notepad to the printer
My guess would be it doesnt print correct. 
This line with commas should be semi-colons will keep it on the same line.
Print.print txtcityst, txtstatest, txtzipcodest
Change to
Print.print txtcityst; txtstatest; txtzipcodest
Also, use ShellExecute API to print the text file just as if you did it manually from notepad.
Code:
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Const SW_HIDE As Long = 0
Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Const SW_SHOWMINIMIZED As Long = 2
Private Sub Command1_Click()
ShellExecute Me.hwnd, "print", "C:\Users\Public\Test1.txt", vbNullString, "C:\", SW_SHOWNORMAL
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 8th, 2008, 04:05 AM
#10
Re: printing values from notepad to the printer
Change to
Print.print txtcityst; txtstatest; txtzipcodest
you missed my error
all lines should be printer.print
the comma will just print in the next print position, so should work fine, otherwise you can just print the identicle line you print to the file
printer.print txtcityst & "," & txtstatest & "," & txtzipcodest
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Apr 8th, 2008, 10:49 AM
#11
Thread Starter
Member
Re: printing values from notepad to the printer
im getting a error when i use the printer.print on all the lines. for the shellexecute can i just type that or do i have to do something special.
-
Apr 8th, 2008, 04:38 PM
#12
Re: printing values from notepad to the printer
im getting a error when i use the printer.print on all the lines.
what error? it should work fine
are you working in vb6?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Apr 8th, 2008, 05:52 PM
#13
Thread Starter
Member
Re: printing values from notepad to the printer
ok now i got it to work it prints but im having trouble changing the font size can someone help me out thank you. this is what i have right now
Printer.Print txtnamest
Printer.Print txtaddressst
Printer.Print txtaddressst1
Printer.Print txtcityst & ","; txtstatest; " "; txtzipcodest
Printer.Print txtcountryst
Printer.EndDoc
End Sub
-
Apr 9th, 2008, 03:28 AM
#14
Re: [resolved]printing values from notepad to the printer
printer.font.size = 14
set the font, size, colour etc before printing the lines, you can change size between lines
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|