Excel crashing

Post your VB and VBA discussions here
Post Reply
Malone
Newbie
Posts: 0
Joined: Thu Nov 26, 2015 8:20 pm

Excel crashing

Post by Malone »

I'm using DrDAQ with Excel 2000 VBA on a Windows 7 computer. I'm measuring the voltage at the scope input every two seconds, continuously. This voltage is normally zero. That's all the program does except when the voltage is >2V, which might occur every few days, then other things happen.

This works fine except that every so often - about once a day, randomly - Excel crashes. Not a normal Excel error - the whole application crashes with the "Microsoft Excel has stopped working...." message. The Windows event log identifies ntdll.dll as the faulty module (see below). My fault-finding indicates the crash occurs whilst executing the UsbDrDaqGetSingle routine when the input voltage is zero.

I'm using Excel 2000 on Window 7 systems (but not with DrDAQ) on several different computers in similar continuous applications without problem. (And even with Windows 8 and 10)

The code I'm using is relatively simple (see below). I suspect a Windows problem rather than any inadequacy in my coding or problem with the DrDAQ unit. But I was wondering whether anyone might have seen this sort of thing before, or could suggest what might be going on or perhaps suggest some further diagnostic techniques?

Many thanks.

Code

Declare Function UsbDrDaqOpenUnit Lib "USBDrDAQ.dll" (ByRef handle As Integer) As Long
Declare Function UsbDrDaqCloseUnit Lib "USBDrDAQ.dll" (ByVal handle As Integer) As Long
Declare Function UsbDrDaqGetSingle Lib "USBDrDAQ.dll" (ByVal handle As Integer, ByVal channel As Long, ByRef value As Integer, ByRef overflow As Integer) As Long

Function USBmeasurement()
Dim handle As Integer
Dim status As Long
Dim overflow As Integer
Dim value As Integer

status = UsbDrDaqOpenUnit(handle)

If status <> 0 Then
MsgBox "Unit not opened", vbOKOnly, "Error Message"
Exit Function
End If

Call UsbDrDaqGetSingle(handle, 4, value, overflow)
Call UsbDrDaqCloseUnit(handle)
USBmeasurement = value / 1000

End Function
______


Windows event log

Faulting application name: EXCEL.EXE, version: 9.0.0.3822, time stamp: 0x38b691e8
Faulting module name: ntdll.dll, version: 6.1.7601.19045, time stamp: 0x56258dbb
Exception code: 0xc0000005
Fault offset: 0x00052dd7
Faulting process id: 0x1098
Faulting application start time: 0x01d12724a9a2072f
Faulting application path: C:\Program Files\Microsoft Office\Office\EXCEL.EXE
Faulting module path: C:\Windows\SYSTEM32\ntdll.dll
Report Id: a16a3133-9470-11e5-b9ad-896f678cf549

Hitesh

Re: Excel crashing

Post by Hitesh »

Hi Malone,

The UsbDrDaqGetSingle and UsbDrDaqCloseUnit functions output a status code. Instead of:

Code: Select all

Call UsbDrDaqGetSingle(handle, 4, value, overflow)
Call UsbDrDaqCloseUnit(handle)
try:

Code: Select all

status = UsbDrDaqGetSingle(handle, 4, value, overflow)
status = UsbDrDaqCloseUnit(handle)
Does the crash occur at any particular line in the code? Which version of the usbdrdaq.dll are you using (right-click and select Properties, then select the Details tab).

Regards,

Malone
Newbie
Posts: 0
Joined: Thu Nov 26, 2015 8:20 pm

Re: Excel crashing

Post by Malone »

Thanks Hitesh, sorry for the delay in replying, but as these crashes occur up to 24hrs after the program starts I need to wait.

I replaced "Call " by "status= " and also I've tried two versions of usbdrdaq.dll (version 1.0.1.1 10 July 2014 and version 1.0.5.4 8 June 2015) but Excel still crashes within 24hrs. I've tried it on a different computer running Windows 7 and Excel also crashes - even more frequently on that computer.

It seems that the offending command is Call UsbDrDaqCloseUnit(handle) (or status = UsbDrDaqCloseUnit(handle)).

But I think I have a work-around. Instead of calling a procedure which performs the measurement and which involves Call UsbDrDaqOpenUnit(handle) and Call UsbDrDaqCloseUnit(handle) every two seconds. I loop the measurement inside these commands and only leave that procedure when the measurement value indicates I need to (which is very infrequently). This means that Call UsbDrDaqOpenUnit(handle) and Call UsbDrDaqCloseUnit(handle) are not invoked every two seconds because the unit is open the whole time. I've been running this for three days with no crash.

I hope this makes sense. It's not the way I'd prefer to do it but it appears to be the only way I can do what I need to do without the crashing.

Hitesh

Re: Excel crashing

Post by Hitesh »

Hi Malone,

No problem with the delay in response.

Is there any particular reason why you would want to open and close the connection to the device every two seconds?

It would be better to open the connection, perform all the tasks that you need to and when the data collection session is finished to close the connection to the device.

I am running a test here using C code with a driver that is a slightly later version so I will see if the problem can be reproduced.

Regards,

Malone
Newbie
Posts: 0
Joined: Thu Nov 26, 2015 8:20 pm

Re: Excel crashing

Post by Malone »

Yes Hitesh - you're right - there's no reason why I shouldn't keep the unit open all the time. For some inexplicable reason I thought that if one left a procedure after invoking UsbDrDaqOpenUnit(handle) from within it the unit would not like it unless the unit was closed before leaving. But that was wrong. So now I leave the unit open 24/7 and measure every 2 seconds. I'm still a bit baffled why my previous approach (opening and closing the unit every two seconds) crashed - may be a freak of my particular configuration - Windows 7 and Excel 2000. But now I have a perfectly satisfactory work-around I'm happy! Thanks for that.

Hitesh

Re: Excel crashing

Post by Hitesh »

Hi Malone,

No problem - good to hear that it is working :D That is a better approach to take.

Regards,

Post Reply