usb cash drawer vb codes...help me pls (1 Viewer)

i'm still trying...was able to find this link

http://en.allexperts.com/q/Visual-Basic-1048/Call-dll-procedure-MS-1.htm

so, this is what my code looks like right now, but still not working...

Code:
Public Declare Function OpenUSBcr Lib "usbcr.dll" () As Long
Public Declare Function DrawerOpen Lib "usbcr.dll" (ByVal ID As Long) As Long
Public Declare Function CloseUSBcr Lib "usbcr.dll" () As Long
Public Declare Function DrawerState Lib "usbcr.dll" (ByVal ID As Long) As Long
Public Declare Function RetrieveStatistics Lib "usbcr.dll" (ByVal ID As Long, ByVal idx As Long, ByRef buf As Any, ByVal size As Long) As Long
Public Declare Function OpenUSB Lib "usbcr.dll" () As Long
Public Declare Function CloseUSB Lib "usbcr.dll" () As Long

Private Sub Image0_Click()
Dim trythis As Long
    trythis = OpenUSB
    trythis = DrawOpen(7)
    trythis = CloseUSB
End Sub
the error i get reads: the expression on click you entered as the event prop...following error: constants, fixed-length strings, arrays, user-defined types and declare statments not allowed as public members of object modules...


...what does that mean?
 
then there's this >> http://www.access-programmers.co.uk/forums/archive/index.php/t-25172.html

...so it seems like i'm on the right track.

In the Declarations Section of your module add this:

Private cMyDLL as THEDLLNAME


Then in the code that will use the dll add this.

Set cMyDLL = New THEDLLNAME
x = cMyDLL.FunctionName(Parameter1,Parameter2)

You can make cMyDLL Public if you want. Just remember to Set cMyDLL = Nothing when your done or you could leave Access in a point that is not completly shut down.


so the declare, and the call seem to be right. why would i get that error as i did above?


b_c
 
then there's this >>> http://bytes.com/topic/access/answers/609069-how-use-dll-ms-access-vba


Private Declare Function apiJFWSayString Lib "C:\SourceCode\JAWS\JFWAPI.DLL"
_
Alias "JFWSayString" (ByVal lpszStrinToSpeak As String, bInterrupt As
Boolean) As Boolean
>
Private Sub cmdPlaySound_Click()
On Error GoTo Err_cmdPlaySound_Click
>
Dim s As String
s = "Hello, wow, you are a Good Looking Guy!"
s = s & s & s & s
Set JW = Me.ActiveXCtl0.Object ' JFWApi
' JW.Enable 0
Dim blRet As Boolean
>
blRet = apiJFWSayString(s, True)
'JW.SayString s, False
>
'Me.ActiveXCtl0.Object.SayString s, True
>
Exit_cmdPlaySound_Click:
Exit Sub
>
Err_cmdPlaySound_Click:
MsgBox Err.Description
Resume Exit_cmdPlaySound_Click
>
End Sub
>
Private Sub Form_Load()
'Dim JW As JFWApi
>
End Sub


so, should i be defining the c:\windows\system\usbcr.dll ... or would windows automatically pick up the location in the "system" directory?


b_c
 
Hi,

seeing as there are various download options for prolific usb cash drawer drivers & dll's, i thought it might have a bit more obvious than it seems to be. you are looking for a usb cash drawer solution are you not?


Nidge
 
Hi,

seeing as there are various download options for prolific usb cash drawer drivers & dll's, i thought it might have a bit more obvious than it seems to be. you are looking for a usb cash drawer solution are you not?


Nidge


yes, sir, i am...i will look harder on that site, for all i saw were .exe's and other stuff.

my true problem is bringing in and utilizing a .DLL file in access. know anywhere i can go for this info?


b_c
 
still trying...i have an "access expert" calling me this afternoon to give me a quote on making the code for me to use the .dll to open the register.


other than that. i contacted Posiflex again with this email:

hey chad...

...is there any other documentation or anything other than the opos demo program that would've been on that disk? i'm at an impasse, and i can't figure out where to go w/ the programming of the functions into access 2007 (vba). ...i'm no pro to start with.

if anyone there could help w/ some info on how to call the functions w/ vba-coding, i'll buy them a case of beer! ...and i'll get you one for helping out, too.


thanks, man.


here's his response this morning:

Hi,

Unfortunately we do not have any further documentation for the USB cash drawer. The only programmers guide is what I have already sent, this is what is sent to all POS software developers for integrating the USB Cash drawer.

Thank you,
Chad N.


so...there's still hope for al gore's internet to pull through for me and save me some money before the "expert" calls this afternoon.

wut to do...wut to do? how do i use this code (or a symblence of it) through vba?

*****************************************************************
* *
* Posiflex CR-4xx5-II Series USB CR DLL v1.03 Programming Guide *
* *
*****************************************************************

The driver required to control the Posiflex USB Cash Drawer
is called "USBCR.DLL". When the Posiflex USB Cash Drawer Test
Program is installed, this driver is stored in folder
"C:\Windows\System" if the default Windows folder is
"C:\Windows". Please preserve this file "USBCR.DLL" in the
system folder for your software to control the Posiflex USB
Cash Drawer even if you want to uninstall the Posiflex test
program.

The driver "USBCR.DLL" provides 7 function calls:
The 1--5 functions are for CR-4XX5-II series to use.
The 6--7 functions are for CR-4XX5 series to use.
The examples of Visual Basic are list below.


1. Public Declare Function OpenUSBcr LIB "usbcr.dll" () As Long
=========
' must be called before calling other functions
' return 0 on success


2. Public Declare Function CloseUSBcr Lib "usbcr.dll" () As Long
==========
' call this function before exiting your program
' return 0 on success


3. Public Declare Function DrawerOpen Lib "usbcr.dll" (ByVal ID As Long) As Long
==========
' return 0 on sending commands successfully, -1 on error
' 'ID' is the drawer number from 0 to 7


4. Public Declare Function DrawerState Lib "usbcr.dll" (ByVal ID As Long) As Long
===========
' return the drawer status
' high nibble is the drawer ID, and
' low nibble is 0 if drawer is open, 1 if drawer is closed
' return -1 on error


5. Public Declare Function RetrieveStatistics Lib "usbcr.dll" (ByVal ID As Long, ByVal idx As Long, ByRef buf As Any, ByVal size As Long) As Long
==================
' return 0 on sending commands successfully, -1 on error
' 'size' is the number of bytes which can be held by 'buf'
' 'buf' will hold the value read from memory in cash drawer
' This function used to Retrieve the device statistics of Unified POS1.8.

6. Public Declare Function OpenUSB Lib "usbcr.dll" () As Long
=======
' must be called before calling other functions
' return 0 on success
' This function is for CR-4xx5 Series to use,
' and it can drive CR-4xx5-II too.


7. Public Declare Function CloseUSB Lib "usbcr.dll" () As Long
========
' call this function before exiting your program
' return 0 on success
' This function is for CR-4xx5 Series to use.
' and it can drive CR-4xx5-II too.


Note : For C++ programs: use __stdcall compiler option


b_c
 
so drumroll please...


...wanna know how to make the cash drawer open via access? i bet you do. it cost me $30, plus i gave the guy a $20 tip, so $50 all together. here you go:

the codes from the cr programmers reference are the functions that need to be declared.

you need to declare some dimensions to capture the return values.


the trick, and it took my "pro" a little while to figure it out (trust me, the error code is cryptic enough to where i wasn't even thinking about the right thing)...anyway, the trick is to declare the functions in a separate module. DO NOT declare them in your form or report or whatever. you can refer to them in your form by calling them, but do not declare them in the form module...they need to be in their own module.

other than that...simple coding will get you through the rest.

for reference, here's my code (simple to check drawer operation...add if/thens to ensure operational stability):

Code:
Private Sub Image27_Click()
    Dim stepONE As Long
    Dim stepTWO As Long
    Dim stepTHREE As Long
    Dim stepFOUR As Long
   
    stepONE = OpenUSBcr
    stepTWO = DrawerOpen(7)
    stepTHREE = DrawerState(7)
    stepFOUR = CloseUSBcr
End Sub
copy and paste the declarations into a separate module, like i said, and the rest should be easy-cheesy.


thanks nigel and others for all your help...

CHARLIE, you are the man!!!


b_c
 
Hi B_c,
I have done exactly as you said.
But I still got error "Run-time error '453': can't find dll entry point OpenUSBcr in USBCR.DLL"
Can you sent me your Access program you done.
looking forward to hearing from you.
Thank you.
 

Users who are viewing this thread

Back
Top Bottom