Prev: VB3 anyone...?
Next: rsidll32
From: mjimeno on 9 Jun 2005 10:44 Mike, thanks a lot for your help, suggestions and code. The code I was going to send you is a similar idea of what you posted, but I print a picture, not draw a line. I use barcode 39, I guess the most used barcode type, but just print it, I don't use some other lines you're using. Explain me please this 4 lines, I think they are the core of the solution: oldmode = Printer.ScaleMode Printer.ScaleMode = vbPixels xp = Printer.ScaleX(x, oldmode, vbPixels) yp = Printer.ScaleY(y, oldmode, vbPixels) I'll be testing some changes to see how it works. I'll send my code too. Thanx, M
From: mjimeno on 9 Jun 2005 10:59 THE CODE I USE, OR TRY TO USE: ------------------------------------------------- Dim bc_string As String bc_string = Text1.Text CurrentX = (1 / 16) + ((22 / 16)) 'FACTOR CORRECION ?? CurrentY = 5 Dim xpos!, Y1!, Y2!, Th!, tw, new_string$ Dim dw As Double 'If bc_string = "" Then obj.Cls: Exit Sub 'define barcode patterns. THis is for Barcode 39. I guess this are all the representable characters. Dim bc(90) As String bc(1) = "1 1221" 'pre-amble bc(2) = "1 1221" 'post-amble bc(48) = "11 221" 'digits bc(49) = "21 112" bc(50) = "12 112" bc(51) = "22 111" bc(52) = "11 212" bc(53) = "21 211" bc(54) = "12 211" bc(55) = "11 122" bc(56) = "21 121" bc(57) = "12 121" 'capital letters bc(65) = "211 12" 'A bc(66) = "121 12" 'B bc(67) = "221 11" 'C bc(68) = "112 12" 'D bc(69) = "212 11" 'E bc(70) = "122 11" 'F bc(71) = "111 22" 'G bc(72) = "211 21" 'H bc(73) = "121 21" 'I bc(74) = "112 21" 'J bc(75) = "2111 2" 'K bc(76) = "1211 2" 'L bc(77) = "2211 1" 'M bc(78) = "1121 2" 'N bc(79) = "2121 1" 'O bc(80) = "1221 1" 'P bc(81) = "1112 2" 'Q bc(82) = "2112 1" 'R bc(83) = "1212 1" 'S bc(84) = "1122 1" 'T bc(85) = "2 1112" 'U bc(86) = "1 2112" 'V bc(87) = "2 2111" 'W bc(88) = "1 1212" 'X bc(89) = "2 1211" 'Y bc(90) = "1 2211" 'Z 'Misc bc(32) = "1 2121" 'space bc(35) = "" '# cannot do! bc(36) = "1 1 1 11" '$ bc(37) = "11 1 1 1" '% bc(43) = "1 11 1 1" '+ bc(45) = "1 1122" '- bc(47) = "1 1 11 1" '/ bc(46) = "2 1121" '. bc(64) = "" '@ cannot do! 'A Fix made by changing 65 to 42. bc(42) = "1 1221" '* bc_string = UCase(bc_string) new_string = "*" & bc_string & "*" 'add pre-amble, post-amble largo = GetBarCodeLength(new_string) 'I resize the bars depending on how many lines do I need to print If dw < 1 Then dw = 1 dw = Text2.Text 'just for testing, I asign the width of the bars manually. Picture3(0).Width = dw frmReader.Picture3(0).Picture = frmReader.Picture3(0).Image Picture3(0).Refresh Picture3(1).Width = dw * 2 frmReader.Picture3(1).Picture = frmReader.Picture3(1).Image Picture3(1).Refresh Picture3(2).Width = dw frmReader.Picture3(2).Picture = frmReader.Picture3(2).Image Picture3(2).Refresh 'draw each character in barcode string xpos = 10 Printer.ScaleMode = 2 For n = 1 To Len(new_string) c = Asc(Mid$(new_string, n, 1)) If c > 90 Then c = 0 bc_pattern$ = bc(c) 'draw each bar For i = 1 To Len(bc_pattern$) Select Case Mid$(bc_pattern$, i, 1) Case " " 'space 'obj.Line (xpos, Y1)-(xpos + 1 * dw, Y2), &HFFFFFF, BF Printer.PaintPicture frmReader.Picture3(2).Picture, xpos, CurrentY * 1440 xpos = xpos + dw Case "1" 'space 'obj.Line (xpos, Y1)-(xpos + 1 * dw, Y2), &HFFFFFF, BF Printer.PaintPicture frmReader.Picture3(2).Picture, xpos, CurrentY * 1440 xpos = xpos + dw 'line Printer.PaintPicture frmReader.Picture3(0).Picture, xpos, CurrentY xpos = xpos + dw Case "2" 'space 'obj.Line (xpos, Y1)-(xpos + 1 * dw, Y2), &HFFFFFF, BF Printer.PaintPicture frmReader.Picture3(2).Picture, xpos, CurrentY * 1440 xpos = xpos + dw 'wide line Printer.PaintPicture frmReader.Picture3(1).Picture, xpos, CurrentY xpos = xpos + (2 * (dw)) End Select Next Next '1 more space xpos = xpos + dw ' Send it to print Printer.NewPage Printer.EndDoc End Sub ------------------------------------------------- Mike, I'll try your code. This is only to show you what I'm doing. But, any suggestion is welcome. M
From: mjimeno on 9 Jun 2005 13:18 Another question, mike: explain me please in words the line where you call the sub: pixwide = 1.5 PrintBarCode "639382000393", 1, 6.5, pixwide I'm testing with a few modifications to make it work for Barcode 39, and at least the first one I printed, about 1.2 inches width the whole code, was readed by the barcode reader. Yeah! Thanks man. I'll do some testing more and I'll ask you any part I can't get.
From: Gaga on 9 Jun 2005 21:30 "mjimeno" <miguelangeljimeno(a)hotmail.com> wrote in message news:c50951bfe1711fb8af93f5eb81f8aaba(a)localhost.talkaboutprogramming.com... > Mike, thanks a lot for your help, suggestions and code. The code > I was going to send you is a similar idea of what you posted, but > I print a picture, not draw a line. I use barcode 39 As I said earlier, I don't know much about barcodes. I read somewhere that the UPC barcode that I used in the code sample I posted yesterday is the most common type of barcode that you find on products you buy in the shops, and I got the details of it from a web site and I just wrote the VB code from reading that explanation of how a UPC barcode is constructed. I don't know anything at all about the "barcode 39" that you mention, although I may look into it when I get some time. The UPC barcode can contain just ten symbols (the digits 0 to 9), which is all that is needed for products that are sold in shops. Your "barcode 13" seems to contains digits and characters, so it is obviously constructed differently. I'll propbably check it out when I get time. In the meantime, have a look at the following link that deals with UPC barcodes, and check out the fifth page entitled "Can I decode the bars", which explains how a UPC barcode is constructed: http://electronics.howstuffworks.com/upc.htm > Explain me please this 4 lines, I think they are the > core of the solution: > oldmode = Printer.ScaleMode > Printer.ScaleMode = vbPixels > xp = Printer.ScaleX(x, oldmode, vbPixels) > yp = Printer.ScaleY(y, oldmode, vbPixels) Those lines are required because I use a main ScaleMode of vbInches in the click event that calls the barcode drawing routine (I use inches rather than pixels so that I can position the barcode on the page in such a way that it will be at the same position on all printers, regardless of their resolution (pixels per inch). The calling code passes the variables x and y as inches and the above four lines convert those values to the nearest pixel position (for the specific printer that is in use). They are not really "the core of the solution". The real "solution" is the fact that the barcode drawing routine itself uses whole pixel values for the thickness and position of all of the lines that it draws, which means that the printer can actually deposit the ink at the exact pixel positions, which avoids all of the problems that you can get when you instead use True Type barcode fonts. > Another question, mike: explain me please in words > the line where you call the sub: > pixwide = 1.5 > PrintBarCode "639382000393", 1, 6.5, pixwide Actually, that section of my code contains a mistake (the 1.5 should read 1). It is intended to draw a barcode using "1 pixel" as the width of the thinnest line that the barcode contains. So (with the 1.5 amended to 1) the above line effectively says, "Print a barcode at position (1, 6.5) inches on the page, using 1 pixel as the width of of the thinnest line in the barcode". The trick is to write your code (as I have done) such that the first line of the barcode is at an exact "whole pixel" position and also so that the width of every bar and space in the barcode is a whole number of pixels. In that way every bar and every space will be at a "whole pixel" position on the page. This is important, because printers generally cannot draw "half a pixel" and they cannot position anything at a "half a pixel" position (or any other fraction of a whole pixel). This is not really too important if you are using a high resolution printer (or if you are drawing a very large barcode), where the width of even the thinnest line or bar in the barcode will be many times greater than the width of a single pixel. It is, however, very important on relatively low resolution printers. It is even important on high resolution printers when you are drawing very small barcodes. I'm on holiday at the moment, so I probably won't get time to look at your own code or to look any further into your "barcode 39" stuff for some time, but I think you'll probably be able to sort it out yourself if you remember to stick to the "whole pixel" values for the position and the thickness of all of the bars and spaces. Most barcodes (from what I can gather) have a number of different thickness of bars and spaces, but the thickness of all of them is a "whole multiple" of the thickness of the thinnest bar or space. So if you make the thinnest bar or space a "whole printer pixel" value then all of the others will be too. Mike
From: Gaga on 9 Jun 2005 23:45
"Gaga" <Gaga(a)momo.com> wrote in message news:42a8ed3a$0$12103$afc38c87(a)news.optusnet.com.au... > "mjimeno" <miguelangeljimeno(a)hotmail.com> wrote in message > Actually, that section of my code contains a mistake (the 1.5 > should read 1). It is intended to draw a barcode using "1 pixel" > as the width of the thinnest line that the barcode contains. By the way, that mistake would have caused the Long variable "pixwide" to have a value of 2, instead of 1. So when you correct the mistake (as mentioned in my previous post) you should find that you can print a barcode half the size of the one you printed before, which I think should be the smallest you will ever need. Mike |