K8061 low success rate

dear velleman;
pls. take a minute to read the following:-

thisform.text1.setfocus
messagebox(......)
declare opendevice in k8061.dll
    atlong=opendevice()
    thisform.text1.value=atlong
    messagebox(......)
declare outputpwm in k8061.dll integer cardaddress, integer data
    outputpwm(0, 1023)
    messagebox(......)
declare outputpwm in k8061.dll integer cardaddress, integer data
    outputpwm(0, 0)
declare outputpwm in k8061.dll integer cardaddress, integer data
    outputpwm(1, 1023)
    messagebox(.....)
declare outputpwm in k8061.dll integer cardaddress, integer data
    outputpwm(1, 0)
if messagebox("DO YOU WANT TO CLOSE DEVICES?",4+32,"REQUEST")=6
declare setdigitalchannel in k8061.dll integer cardaddress, integer channel
    setdigitalchannel(0, 2)
    messagebox(......)
declare cleardigitalchannel in k8061.dll integer cardaddress, integer channel
    cleardigitalchanne(0, 2)
declare closedevices in k8061.dll


all these are codes for me to control a no. of relays. but the success rate
(which means only the desired pwm/channels are triggered, while the rest
remain unchanged.) is no more than 70per cent(less than 95 is not acceptable).
2 vm140 are installed.
13 analogue/digital channels are employed.
if there is/are something wrong with the hardware/codes, the success rate should be
much lower than 70(should be zero).
the os is windows xp pro. the driver pack is k8061-driver-v4-0; k8061.dll 4.0.0.0
is in windows system32 file while mpusbapi.dll is removed.
can you give me some hints to improve this?
Thanks.

It would help if you didn’t re-declare every external library function before each and every call. At the very least it would make your code more readable.

Regards,
Jan

It would help as well to know the programming language and evironment…