Keith Adamson 07-10-2000, 11:06 AM I've written a small program that allows you to choose items from three (3) separate options. Then, I use three (3) text lines (i.e. text1, text2, text 3), one right on top of the other, to print my output. Everything prints fine on a standard piece of paper, however, I want to print on a Seiko Smart Label Printer. I've changed the default printer which gets the output to the correct printer, however, it will only print one partial line of my output per label.
I've tried messing around with the X and Y coordinates, but no luck. Can someone help me figure out how to get all of text1, text2 and text3 to print on a label? My thanks in advance. (p.s., I am very new at this)
Keith Adamson
Glade 07-10-2000, 11:55 PM Hey,
Printing in vb can be a pain. I'm a little bit unclear about some things mentioned in your description of the problem. What do you mean by "Then, I use three (3) text lines (i.e. text1, text2, text 3), one right on top of the other, to print my output."? On top of each other how? Are they on separate lines? If you print a line of text using .Print, and then you move the CurrentY coordinate up and print another line of text on top, the one on top will replace the one underneath. But I'm not sure if this is what you mean, especially since this would be evident on a normal printer as well.
When you say that only a partial line of the output is printing, what part? The first part? Do you mean that the text goes off the edge of the label? This can be a problem, in situations like this you will need to use a word wrap.
Give a more detailed description of what is going on and I will try to help you. Or post your code, although I don't have one of those label printers, I may be able to get an idea of the problem... I sympathize with printing problems, I hate writing print routines. I am still trying to figure out how to print white text on a black background (or box), so if you figure that out, we'll trade. :)
Good luck,
-Glade
Keith Adamson 07-11-2000, 11:05 AM Glade,
Thanks for responding to my problem. I am a novice at this, so please excuse my inexperience.
I have listed my routines below. Actually, I have four (4) lines of text that I am trying to print, not three (3) as mentioned in my "call for help".
Before I go any further, please let me describe what I am trying to do. I work in a medical office where prescriptions are written. I am trying to streamline this process by writing a simple program where we can point and click the medication, dosage, instructions and refill information. After clicking your choice from four (4) separate "options", your choices are entered below on the (same) screen in an area that you will be able to review before hitting the "Print" button. The output would be printed on a label which would then be pealed and attached to a prescription pad.
The text output should look like the following example:
Anaprox DS (Text 1)
Take One Every 12 Hours As Needed For Pain (Text 2)
Qty. #60 (Text 3)
Refill 3 Times (Text 4)
When I print on regular 8 ½ x 11 paper, everything is perfect. However, when printing to the default printer (Seiko Smart Label Printer 200), the output looks like this:
Anapr (First label)
Take (Third label)
Qty. #
Refill (Fifth label)
Labels #2 and #4 are skipped. Anyway, I want it all to print on one (1) label.
The part that does print does not go off the label. It starts printing somewhere near the middle of the label, but there is still room for more text - it just stops as shown above. The label measures 2 x 3 ¼.
Plus, I want to be able to print in landscape, it only prints in portrait mode.
I really appreciate your assistance. It is really frustrating to be almost there, but not quite.
Regards, Keith Adamson
Option Explicit
____________________
Private Sub Combo1_Change()
End Sub
____________________
Private Sub List1_Click()
End Sub
____________________
Private Sub Command1_Click()
Printer.Print ""
Printer.Print Text1.Text
Printer.Print Text2.Text
Printer.Print Text3.Text
Printer.Print Text4.Text
Printer.EndDoc
End Sub
____________________
Private Sub Option1_Click(Index As Integer)
Select Case Index
Case 0
Text1.Text = "Anaprox DS"
Case 1
Text1.Text = "Darvocet N-100"
Case 2
Text1.Text = "Estrace 0.5mg"
Case 3
Text1.Text = "Estrace 1mg"
Case 4
Text1.Text = "Estrace 2mg"
Case 5
Text1.Text = "FemHRT"
Case 6
Text1.Text = "Lotrisone 45mg"
Case 7
Text1.Text = "Midrin"
Case 8
Text1.Text = "Othro - Prefest"
Case 9
Text1.Text = "Ponstel 250mg"
Case 10
Text1.Text = "Premarin 0.3mg"
Case 11
Text1.Text = "Premarin 0.625mg"
Case 12
Text1.Text = "Premarin 0.9mg"
Case 13
Text1.Text = "Premarin 1.25mg"
Case 14
Text1.Text = "Prempro .625 / 2.5mg"
Case 15
Text1.Text = "Prempro .625 / 5mg"
End Select
End Sub
____________________
Private Sub Option2_Click(Index As Integer)
Select Case Index
Case 0
Text2.Text = "Take One Daily."
Case 1
Text2.Text$ = "Take One Every 12 Hours As Needed For Pain."
Case 2
Text2.Text = "Take 2 Three Times Daily With Menstual Flow."
Case 3
Text2.Text = "Take 1-2 Capsules Every 4 Hours As Needed For Pain, Not To Exceed 6 Capsules In A 24 Hour Period."
Case 4
Text2.Text = "Take 2 Capsules At Once Followed By 1 Capsule Every Hour Until Relieved, Up To 5 Capsules Within 12 Hours."
Case 5
Text2.Text = "Apply Externally To Affected Area Twice Daily For 14 Days."
End Select
End Sub
____________________
Private Sub Option3_Click(Index As Integer)
Select Case Index
Case 0
Text3.Text = "Qty. #30"
Case 1
Text3.Text = "Qty. #60"
Case 2
Text3.Text = "Qty. #90"
Case 3
Text3.Text = "Qty. Three Cycles"
End Select
End Sub
____________________
Private Sub Option4_Click(Index As Integer)
Select Case Index
Case 0
Text4.Text = "No Refills"
Case 1
Text4.Text = "Refill 3 Times"
End Select
End Sub
____________________
Glade 07-11-2000, 01:02 PM Keith,
there is no need to apologize for inexperience, fortunately, it is a temporary condition. i have to say right off the bat that i was hoping you were doing something terribly wrong so i could provide you with an easy solution, but it looks like you are doing everything right. if worse comes to worse, you may need to write to the manufacturers of the printer to figure out in what way you have to treat it differently from a normal printer to make it print properly.
here are a couple of ideas anyway:
1. to get all the lines to print on the same label, try printing like:
Printer.Print Text1.Text & vbCrLf & Text2.Text & vbCrLf etc. (i think vbCrLf will work, if not, there are other vb constants like it that should do the trick).
2. the problem with the text being cut off may be because of your margins. there are a variety of printer properties that begin with Scale (ScaleLeft, ScaleWidth, etc.) that let you modify the margins. this applies to your problem with the printing starting in the middle of the label as well.
3. you can change landscape/portrait using the Orientation property, once again for the printer object.
You seem experienced enough with vb to understand what I mean by modifying the printer object's properties, but here's an example anyway:
<CODE>
Printer.ScaleLeft = -1000
Printer.Orientation = vbPRORPortrait
Printer.Print "This is a test" & vbCrLf & "Line 2"
</CODE>
and so on. congratulations on coming up with such a handy program, by the way. it is an excellent idea that applies well to a real-life problem - a lot of useless programs get made everyday, yours will not be one of them.
good luck, and don't hesitate to post again with more problems,
-Glade
Keith Adamson 07-12-2000, 10:03 AM Glade,
It worked!!! I'm pretty excited.
I was able to get the label to print "almost" prefectly. I used the vbPRORPortrait and then fiddled with with the ScaleLeft to fine tune it.
My only problem now is that I do not yet know how to do a "word wrap"; therefore, some of my text is too long to fit on the label. I think I may have seen some other posts with the same problem that I can look for, unless, of course, you can get me there sooner.
I really appreciate your help in getting my labels to print correctly. It is soooo good that there are others, like you, willing to lend assistance to those, like me, who need it.
A million thanks!
Keith
Jim Hardin 07-12-2000, 04:11 PM You may have to find out what the maximum number of characters is for a line, then break the string.
I would suggest a long string of uppercase M's. That is the longest character within a font/typeface.
Print one and count them. That will be you breakpoint.
Glade 07-13-2000, 01:21 AM Keith,
Check out this nifty word wrap written by karimahta, a member of this forum who is as helpful as he is knowledgeable. I use this function in one of my programs and it works very well. Take some time to play with the different settings for the user-defined variable PageData (or PData, or whatever it is), you will find that some of the settings (like .Right) give you possibly unanticipated results. (I can't exactly remember what they were, something like making .Right larger made the margin change size in the opposite way I was expecting - just a warning. This is not an error, just a conceptual thing.)
You're new to this forum, so I'll point out the obvious, just in case. To get to the attached function, click on the word "Attachment" underneath my name on the left side of the screen.
Glad to help,
-Glade
Keith Adamson 07-27-2000, 11:59 AM Glade,
After taking some needed time off, I'm back. Thank you for directing me to Karimahta. If you don't mind, I have some questions (which show my inexperience with VB).
I've printed out Karimahta's code and studied it to the best of my ability. Is this a free-standing program that I would use in addition to my program, or is it something that I would incorporate into mine?
Given your help, my program works very well with the exception of printing the "longer text" items. Can you spare some more assistance and help me get going on the (hopefully) final problem? I don't know where to start.
Regards,
Keith
Glade 07-27-2000, 12:23 PM Keith,
All you need is the procedure PrintWrappedText(ByRef objPrint As Object, PData As PageData) and the user-defined type Private Type PageData. The rest of the project is just there to demonstrate how it works.
You are familiar with data types. When you declare a variable:
Dim intCounter as Integer
you are declaring the variable intCounter as type Integer. A user-defined type is a type of variable that you define for yourself. Once you have defined it you are free to declare other variables as that type. i.e.
Dim myVariable as PageData.
In a sense, you are not really defining a new variable type, the user-defined type is sort of a mixture of standard variable types combined into one variable. If you declare a variable like above, you can access its "subparts" using the "." like:
myVariable.Text = "Hello World"
The procedure PrintWrappedText(ByRef objPrint As Object, PData As PageData) expects two things: the first, "objPrint as Object" is expecting an object that has print methods. This includes the Printer object and the PictureBox object. In your case, you will be passing it the printer object. For your purposes, the procedure could be declared as PrintWrappedText(ByRef objPrint As Printer, PData As PageData), but then the example project would not work, since it uses a picturebox.
The second is a variable of type "PageData". As you can see from the project, karimahta has defined this type at privately at module-level, which means this type is available to all procedures in the same module, and nowhere else. You need to do the same thing (just cut and paste). In the procedure that is calling the wordwrap procedure, you need to declare a variable of this type and then fill its "subparts" (or fields, or whatever - subparts is a bad word :) ) with the information required to wordwrap it properly. In the sample project, karimahta does this:
<CODE><PRE>
With udtData
.Text = txtLongText.Text
.Indent = 240
.Left = 120
.Top = 120
.Right = 120
.Bottom = 120
.ParaAfter = Me.picShow.ScaleY(6, vbPoints, vbTwips)
End With
</PRE></CODE>
(the "With" statement lets you avoid a lot of typing, look it up in your help, if you don't know how to use it).
Then he passes this variable (udtData) and the object that he needs to print on (in his case, a picture box) to the wordwrap procedure:
PrintWrappedText Me.picShow, udtData
in your case, it would look like:
PrintWrappedText Printer, myVariable
and it gets printed, wordwrapped! you don't need to know how the word wrap procedure actually works, which is a good thing. In a previous post in this thread, I mentioned that you may get unexpected results from the values you put into the PageData variable. Just play around with the example project to get an idea of what values are good for you. Things printed to a picture box are approximately the same size as things printed to the printer, so you can get good starting values using the example project, and save yourself a lot of paper.
I hope this is clear to you, if not, post.
Good luck,
-Glade
Keith Adamson 07-27-2000, 04:21 PM Glade,
Thanks for responding so timely, and thanks for the 'heads-up' on the "With" statement - it is a time saver.
I embarrassed to ask the following (but if you don't ask ....):
1. Where do I put the "PrintWrappedText(ByRef objPrint As Printer, PData As PageData)"? In my "Private Sub Command1_Click ()"?, or somewhere else.
2. When you say that all I need is the procedure "PrintWrappedText(ByRef objPrint As Printer, PData As PageData", does this mean I can skip Karimahta's "Option Explicit" statements?
I have always enjoyed challenges, and again, thanks for for your help.
Regards,
Keith
Glade 07-28-2000, 03:02 PM Keith,
1. Where do I put the "PrintWrappedText(ByRef objPrint As Printer, PData As PageData)"? In my "Private Sub Command1_Click ()"?, or somewhere else.
Well that depends. I don't know what your Command1_Click is supposed to do, so I can't tell you that. (quick note: don't use vb's default names, like "Command1": give your controls meaningful names, like "cmdPrint"). You should put this code in whatever procedure you are using to print the label.
2. When you say that all I need is the procedure "PrintWrappedText(ByRef objPrint As Printer, PData As PageData", does this mean I can skip Karimahta's "Option Explicit" statements?
"Option Explicit" is just a statement that means you have to declare variables explicitly before you can use them. If you don't use this you can just use variables "on the fly" without declaring them. This is bad programming practice and can lead to problems, for instance if you misspell a variable name vb will not cause an error, since it will just assume it is another variable. So you should be using this statement, but it is not that important.
As I give your problem more thought I am able to foresee some of the problems you will face or perhaps are already facing. If you like, you can send me your project, either as an attachment to your post or straight to my e-mail. If you do this keep in mind that your project is more than the ".vbp" file, it is that file plus all your form files (".frm"), modules (".mod"), etc. Zip it all up and send it to me, I will take a look at it and if it is not too lengthy I should be able to get you on track.
Glad to help,
-Glade
loquin 11-27-2001, 04:36 PM But if you're using variable width font (most of them) you can achieve a better effect by adding characters one at a time to a temp text variables till you hit a word break, then check the textwidth of the string to make sure it will fit into the allotted space. If so. store this much & continue as above until the textwidth won't fit. Then print the stored total value, flush it, & continue until no more text.
|