Opening a cash drawer in vb6

Closed Posted Mar 23, 2003 Paid on delivery
Closed Paid on delivery

I have a small module witin a large program written in vb6 written by a coder who is no longer available. He was very good so I suspect he was on the right track. The actual code can be found in the next section called "Deliverables"

The purpose of this module is to open a cash register drawer hooked to a Star Micronics 8340 receipt printer by sending a control code (chr$(7)) to the printer which sent it to the cash drawer which is tehn supposed to open.

The 8340 printer has NT drivers so that data can be spooled and then sent to the printer. Therefore opening com ports and send the control creates conflicts and errors. That is wy the coder went in the direction he did.

I want you to tell me what is wrong with the attached code. since you don't have a cash drawer, it may be a hit and miss proposition since I will have to make the changes and testing here. If you have had any experience with 8340 printers please let me [url removed, login to view] for a coder at least with 5 years vb6 experience for this and other vb6 projects involving receipt printers..

## Deliverables

Public Function OpenCashDrawer(PrinterName) As Boolean

On Error GoTo Whoops

Dim lhPrinter As Long

Dim lReturn As Long

Dim lpcWritten As Long

Dim lDoc As Long

Dim sWrittenData As String

Dim MyDocInfo As DOCINFO

lReturn = OpenPrinter(PrinterName, lhPrinter, 0)

'NOTE1 At this point lReturn always = 0; which will exit the function in next code.

'NOTE2 I have experiment with putting "lreturn =1" at this point in the code to bypass next lines but drawer does not open.

If lReturn = 0 Then

OpenCashDrawer = False

Exit Function

End If

[url removed, login to view] = "Register" & CStr(Timer)

[url removed, login to view] = vbNullString

[url removed, login to view] = vbNullString

lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)

Call StartPagePrinter(lhPrinter)

sWrittenData = Chr(7)

lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, _

Len(sWrittenData), lpcWritten)

lReturn = EndPagePrinter(lhPrinter)

lReturn = EndDocPrinter(lhPrinter)

lReturn = ClosePrinter(lhPrinter)

OpenCashDrawer = True

Exit Function

Whoops:

On Error Resume Next

lReturn = EndPagePrinter(lhPrinter)

lReturn = EndDocPrinter(lhPrinter)

lReturn = ClosePrinter(lhPrinter)

OpenCashDrawer = False

End Function

The following code is in a variety of places in the program to invoke the above function:

Dim oPrint As [url removed, login to view]

If HasCashDrawer = False Or LapTop = True Then

Exit Sub

End If

Set oPrint = New [url removed, login to view]

[url removed, login to view] LocalPrinter

Set oPrint = Nothing>

Dim oPrint As [url removed, login to view]

If HasCashDrawer = False Or LapTop = True Then

Exit Sub

End If

Set oPrint = New [url removed, login to view]

[url removed, login to view] LocalPrinter

Set oPrint = Nothing

The following code is in a separate class module which has relevance to the avove codes.

Option Explicit

Private RegFont As String

Private RegFontColor As String

Private ExpFont As String

Private ExpFontColor As String

Private RegFontMaxChar As Integer

Private ExpFontMaxChar As Integer

Private PrinterName As String

Private PrintStarted As Boolean

Private Type DOCINFO

pDocName As String

pOutputFile As String

pDatatype As String

End Type

Private Declare Function ClosePrinter Lib "[url removed, login to view]" (ByVal _ hPrinter As Long) As Long

Private Declare Function EndDocPrinter Lib "[url removed, login to view]" (ByVal _ hPrinter As Long) As Long

Private Declare Function EndPagePrinter Lib "[url removed, login to view]" (ByVal _ hPrinter As Long) As Long

Private Declare Function OpenPrinter Lib "[url removed, login to view]" Alias _ "OpenPrinterA" (ByVal pPrinterName As String,

phPrinter As Long, _ ByVal pDefault As Long) As Long

Private Declare Function StartDocPrinter Lib "[url removed, login to view]" Alias _ "StartDocPrinterA" (ByVal hPrinter As Long, ByVal

Level As Long, _ pDocInfo As DOCINFO) As Long

Private Declare Function StartPagePrinter Lib "[url removed, login to view]" (ByVal _ hPrinter As Long) As Long

Private Declare Function WritePrinter Lib "[url removed, login to view]" (ByVal _ hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, _ pcWritten As Long) As Long

Private PrinterFound As Boolean

1) Complete and fully-functional working program(s) in executable form as well as complete source code of all work done.

2) Installation package that will install the software (in ready-to-run condition) on the platform(s) specified in this bid request.

3) Complete ownership and distribution copyrights to all work purchased.

## Platform

NT 4 workstation

Engineering Microsoft MySQL PHP Software Architecture Software Testing Visual Basic Windows Desktop

Project ID: #2918490

About the project

12 proposals Remote project Active Apr 22, 2003

12 freelancers are bidding on average $99 for this job

gribfritz

See private message.

$85 USD in 14 days
(486 Reviews)
7.6
snowsoftvw

See private message.

$85 USD in 14 days
(30 Reviews)
5.4
peterjl

See private message.

$85 USD in 14 days
(75 Reviews)
5.3
nullconsulting

See private message.

$85 USD in 14 days
(36 Reviews)
5.2
pigheaded

See private message.

$85 USD in 14 days
(2 Reviews)
3.3
mattskr

See private message.

$42.5 USD in 14 days
(1 Review)
1.1
vw253713vw

See private message.

$85 USD in 14 days
(4 Reviews)
1.1
paulstaplehurst

See private message.

$127.5 USD in 14 days
(1 Review)
0.0
kashifwinn

See private message.

$170 USD in 14 days
(1 Review)
0.0
vw705497vw

See private message.

$85 USD in 14 days
(0 Reviews)
0.0
AhemMGT

See private message.

$127.5 USD in 14 days
(0 Reviews)
0.0
relician

See private message.

$127.5 USD in 14 days
(2 Reviews)
0.0