473,385 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

VB code to control HP printer (suppress page throw)

24
please help me to write a code that allows to fire commands to be fired to the printer from vb 6.0 programm.


please reply urgent.
Aug 29 '07 #1
6 3345
hariharanmca
1,977 1GB
please help me to write a code that allows to fire commands to be fired to the printer from vb 6.0 programm.


please reply urgent.

Explain your problem properly.
Aug 29 '07 #2
suvarna
24
Explain your problem properly.
Hi

I want to write a VB code that will control the HP printer. I want to use the HP printer commands so that the printer prints the document but does not eject page out and continues the next document on the same page with a page break.

Eject page only when required or when page is over.


Can you help me at the earliest...
Aug 30 '07 #3
hariharanmca
1,977 1GB
hi

i want to write a vb code that will controll the hp printer. i want to use the hp printer commands so that the printer prints the document but does not eject page out and continues the next document on the same page with a page break.

eject page only wen required o wen page is over.


can u help me at the earliest...

You have to post what you had tryed. So that i can guide you.
Aug 30 '07 #4
suvarna
24
You have to post what you had tryed. So that i can guide you.
Expand|Select|Wrap|Line Numbers
  1. 'module 2 code
  2.  
  3. Option Explicit
  4.  
  5. Public iStartHour As Integer
  6. Public buffer As String
  7. Public textFile As String
  8. Public graphFile As String
  9.  
  10.  
  11. Public Type TCharacterString
  12.     CharacterID As Integer
  13.     arrayCharacterMap(rowCount, colCount) As Boolean
  14. End Type
  15.  
  16. Public Type TParaProp
  17.     mCharacterString() As TCharacterString
  18. End Type
  19.  
  20. Public mParaProp(5)  As TParaProp
  21.  
  22.  
  23. Public iGraphBufferCount As Integer
  24. Public ArrayGraphBuffer(GraphBufferCount) As String
  25.  
  26.  
  27. Public gFso As New FileSystemObject, gFil As File, gTs As TextStream
  28. Public LineCount As Long 'local copy
  29.  
  30. Public iTextBuffer(89) As Integer
  31. Public iCmdBuffer() As Integer
  32. Public iGraphBuffer() As Long
  33. Public lGraphData As Long
  34.  
  35. Public mvarPrinterID As Integer
  36. Public mvarPrinterName As String
  37.  
  38.  
  39. Private Sub OpenTextFile()
  40.  
  41.     Set fso = CreateObject("Scripting.FileSystemObject")
  42.     If fso.FileExists(textFile) = True Then
  43.         fso.DeleteFile (textFile)
  44.         fso.CreateTextFile (textFile)
  45.     Else
  46.         fso.CreateTextFile (textFile)
  47.     End If
  48.     Set fil = fso.GetFile(textFile)
  49.     Set ts = fil.OpenAsTextStream(ForWriting)
  50.  
  51. End Sub
  52.  
  53. Private Sub CloseTextFile()
  54.  
  55.     ts.Close
  56.     Set ts = Nothing
  57.     Set fil = Nothing
  58.     Set fso = Nothing
  59.  
  60. End Sub
  61.  
  62. Public Sub InitialisePrinter()
  63. Dim i As Integer
  64. Dim t As Integer
  65.  
  66.     iStartHour = 0
  67.     LineCount = 0
  68.  
  69.     lGraphData = 2800
  70.     ReDim iGraphBuffer(lGraphData)
  71.     'ReDim iCmdBuffer(rsCmdMaster.RecordCount + lGraphData)
  72.  
  73.  
  74.  
  75.  
  76.     textFile = "C:\f" & mvarPrinterName & "." & "txt"
  77.     graphFile = "C:\g" & mvarPrinterName & "." & "txt"
  78.  
  79.     iGraphBufferCount = 0
  80.  
  81.  
  82. End Sub
  83.  
  84. Public Sub ExitPacketMode()
  85.  
  86.     OpenTextFile
  87.     buffer = Chr(0) + Chr(0) + Chr(0) + Chr(27) + Chr(1) + "@EJL" + Chr(32) + "1284.4" + Chr(10) + "@EJL" + Chr(32) + Chr(32) + Chr(32) + Chr(32) + Chr(32) + Chr(10)
  88.     ts.Write buffer
  89.     CloseTextFile
  90.     Test (textFile)
  91.  
  92.     OpenTextFile
  93.     buffer = Chr(27) + "@"
  94.     ts.Write buffer
  95.     CloseTextFile
  96.     Test (textFile)
  97.  
  98. End Sub
  99.  
  100. Public Sub TerminatePrinter()
  101.  
  102. End Sub
  103. Public Sub ResetPrinter()
  104.  
  105.     OpenTextFile
  106.     buffer = Chr(27) + "E"
  107.     ts.Write buffer
  108.     CloseTextFile
  109.     Test (textFile)
  110.  
  111. End Sub
  112. Public Sub MoveVertical()
  113. Dim i As Integer
  114.  
  115.     OpenTextFile
  116.     buffer = Chr(27) + "J" + Chr(4)
  117.     ts.Write buffer
  118.     CloseTextFile
  119.     Test (textFile)
  120.  
  121. End Sub
  122.  
  123.  
  124.  
  125.  
  126.  
  127. Public Sub MoveHorizontal()
  128. Dim i As Integer
  129.  
  130.     OpenTextFile
  131.     buffer = Chr(27) + Chr(38) + Chr(108) + Chr(48) + Chr(72)
  132.     ts.Write buffer
  133.     CloseTextFile
  134.     Test (textFile)
  135.  
  136. End Sub
  137.  
  138. Public Sub Home()
  139. Dim i As Integer
  140.  
  141.     OpenTextFile
  142.     buffer = Chr(13)
  143.     ts.Write buffer
  144.     CloseTextFile
  145.     Test (textFile)
  146.  
  147. End Sub
  148.  
  149. Private Sub outputBuffer()
  150. Dim i As Integer
  151.  
  152.     Set fso = CreateObject("Scripting.FileSystemObject")
  153.     If fso.FileExists(textFile) = True Then
  154.         fso.DeleteFile (textFile)
  155.         fso.CreateTextFile (textFile)
  156.     Else
  157.         fso.CreateTextFile (textFile)
  158.     End If
  159.     Set fil = fso.GetFile(textFile)
  160.     Set ts = fil.OpenAsTextStream(ForWriting)
  161.  
  162.     buffer = Chr(iTextBuffer(0))
  163.     For i = 1 To 79
  164.         buffer = buffer + Chr(iTextBuffer(i))
  165.     Next i
  166.     ts.Write buffer
  167.  
  168.     ts.Close
  169.     Set ts = Nothing
  170.     Set fil = Nothing
  171.     Set fso = Nothing
  172.  
  173. End Sub
  174.  
  175.  
  176. Private Sub Test(ByVal FileName As String)
  177. Dim i As Integer
  178.  
  179.     i = vbSendPrnToPrinter(FileName, mvarPrinterName)
  180.  
  181. End Sub
  182.  
  183. Private Sub FillBufferBlank()
  184. Dim i As Integer
  185.  
  186.     For i = 0 To 89
  187.         iTextBuffer(i) = 32
  188.     Next i
  189.  
  190. End Sub
  191.  
  192. Private Sub FillGraphBufferBlank()
  193. Dim i As Integer
  194.  
  195.     For i = 0 To 2000
  196.         iGraphBuffer(i) = 0
  197.     Next i
  198.  
  199. End Sub
  200.  
  201.  
  202. Private Sub outputGraphBuffer()
  203. Dim i As Integer
  204. Dim GraphBuffer As String
  205.  
  206.     If iGraphBufferCount = (GraphBufferCount - 1) Then
  207.  
  208.         Set gFso = CreateObject("Scripting.FileSystemObject")
  209.         If gFso.FileExists(graphFile) = True Then
  210.             gFso.DeleteFile (graphFile)
  211.             gFso.CreateTextFile (graphFile)
  212.         Else
  213.             gFso.CreateTextFile (graphFile)
  214.         End If
  215.         Set gFil = gFso.GetFile(graphFile)
  216.         Set gTs = gFil.OpenAsTextStream(ForWriting)
  217.  
  218.         GraphBuffer = ArrayGraphBuffer(0)
  219.         For i = 1 To GraphBufferCount - 1
  220.             GraphBuffer = GraphBuffer & ArrayGraphBuffer(i)
  221.         Next i
  222.  
  223.         gTs.Write GraphBuffer
  224.         gTs.Close
  225.         Set gTs = Nothing
  226.         Set gFil = Nothing
  227.         Set gFso = Nothing
  228.         iGraphBufferCount = 0
  229.         Test (graphFile)
  230.     Else
  231.         ArrayGraphBuffer(iGraphBufferCount) = Chr(iCmdBuffer(0))
  232.         For i = 1 To rsCmdMaster.RecordCount + lGraphData - 1
  233.             ArrayGraphBuffer(iGraphBufferCount) = ArrayGraphBuffer(iGraphBufferCount) + Chr(iCmdBuffer(i))
  234.         Next i
  235.         iGraphBufferCount = iGraphBufferCount + 1
  236.     End If
  237. End Sub
  238.  
  239.  
  240.  
  241. 'module 1 code
  242.  
  243. Public ColumnWidth As Long
  244. Public Const PageWidth = 360
  245. Public Const rowCount = 7
  246. Public Const colCount = 4
  247. Public Const GraphBufferCount = 60
  248. Public Const StartPos = 5
  249.  
  250. 'Return codes
  251. Public Const ERR_NOERROR = 0     'No error
  252. Public Const ERR_DEFPRINTER = 1  'Error obtaining default printer
  253. Public Const ERR_OPENFILE = 2    'Error opening file
  254. Public Const ERR_OPENPRINTER = 3 'Error opening printer
  255. Public Const ERR_PRINT = 4       'Error sending date to printer
  256. Public Const ERR_FILE = 5        'Error reading file
  257.  
  258. 'Function declarations
  259. Public Declare Function vbSendPrnToPrinter Lib "BINPRN32.DLL" (ByVal pFilename As String, ByVal pPrinterName As String) As Integer
  260. Public Declare Function vbGetDefPrinterName Lib "BINPRN32.DLL" (ByVal pPrinterName As String) As Integer
  261. Public Declare Function vbSendPrnToDefPrinter Lib "BINPRN32.DLL" (ByVal pFilename As String) As Integer
  262. Public fso As New FileSystemObject, fil As File, ts As TextStream
  263.  
  264. Public Function CNull(Variable As Variant, Value As Variant)
  265. On Error Resume Next
  266.     If IsNull(Variable) Then
  267.         CNull = Value
  268.     Else
  269.         If IsNull(Variable) = False Then
  270.             CNull = Variable
  271.         Else
  272.             CNull = Value
  273.         End If
  274.     End If
  275. End Function
  276.  
  277. 'form code
  278.  
  279. Private Sub cmbPrinters_Click()
  280.  
  281.     mvarPrinterName = cmbPrinters.Text
  282.     InitialisePrinter
  283.     ExitPacketMode
  284.  
  285. End Sub
  286.  
  287. Private Sub Command1_Click()
  288.  
  289.     'MoveHorizontal
  290.     MoveVertical
  291. End Sub
  292.  
  293. Private Sub Form_Load()
  294.  
  295.     UpdateCmbPrinters
  296.  
  297. End Sub
  298.  
  299.  
  300.  
  301. Private Sub UpdateCmbPrinters()
  302. Dim i As Integer
  303.  
  304.     i = 0
  305.     For Each X In Printers
  306.         cmbPrinters.List(i) = X.DeviceName
  307.         i = i + 1
  308.     Next
  309.     cmbPrinters.ListIndex = 0
  310.  
  311. End Sub
the printer does not print any file but stores the file in c drive with the name "EPSON Stylus C90 Series" how can i test the printer for printing a simple text file from the program
Aug 30 '07 #5
hariharanmca
1,977 1GB
I think you posted twise?
Aug 30 '07 #6
suvarna
24
I think you posted twise?

the code worked for epson c90 it eject the page wen used only the move vertical but not for horizontal...

movevertical

the asme code does not work for hp when i modified the string to movehorizontal and placed hp command in it.

i also want to set the printer to print a part of graph after every 1 hour without forwarding the page for epson... cud u pls tell me how to do this??
Aug 30 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Iain Porter | last post by:
Hi all, I have a usercontrol (a textbox with dropdown calendar that fills the textbox with the selected date) that I implement in a datagrid in a webform. On first loading the page, the datagrid's...
2
by: msnews.microsoft.com | last post by:
It appears myButton_OnClick is triggering in my user control AFTER its parent's Page_Load already runs. Is there a way to make the parent Page_Load to run afterwards? I'm changing a session...
2
by: eagle | last post by:
How do I access a control, like a placeholder, from another page, or another user control that may be on the same page. For instance, I have a web page with 2 user controls. One user controls...
1
by: Anthony Nystrom | last post by:
I need to within code control some printer settings before raising the print dialog... I need to set some properties for the printer such as "The Printer to Print too", Page settings such as paper...
0
by: Yog | last post by:
How to make a Printer friendly page in ASP.Net...???? If you could help....it wud be great....! Thanks, Yog
2
by: weetat.yeo | last post by:
Hi all , I have a print button in PHP page which using javascript window.print() to print web page. However , when user click "print" , the print preview display that the page cut-off and...
5
by: weetat.yeo | last post by:
Hi all , I have php page which the data in the page are extracted from MYSQL database. The data are retrieved when user click submit button . In the php page , there is a print button for user...
2
by: daydreaming | last post by:
Hi all, I need some help. I have the index html page which has many <a> tags linking to other html pages. There is a need to create the printer friendly page by putting the contents of index file...
7
by: Andy B | last post by:
I have a class I am creating for data access. I need to access controls from inside the class that are on a particular page. How do I do this? or is creating an instance of the page class and using...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.