Why does (or how to detect when) my DDE conversation hang randomly from Excel?

1k Views Asked by At

Nature of the Problem:

I have a macro enabled excel sheet that successfully establishes a DDE connection and conversation with a terminal application for the ManMan database system, Minisoft. About 95% of the time the DDE works properly, however sometimes (~5%) there doesn't seem to be any data exchanged between Excel and Minisoft. When this happens the Minisoft shell hangs waiting for data essentially locking my sheet until it either crashes or the user terminates the Excel process in frustration. This hanging in conversation only ever happens at the begining of conversation after the shell is opened and it seems to happen randomly (I could execute the sheet's VBA three times and it hang or I could execute fifty times and it never hangs). Once hanging of DDE occurs, it will hang at every following execution attempt (even if I close Excel/Minisoft and re-open) until I either restart the machine or log out and log back into windows, nothing else seems to remedy this. If anyone has any insight into what might be causing this problem, please let me know. I need to be able to either prevent it or to detect when this hanging occurs.

Code and Addtional Information:

Public channel As Long

Public Sub StartManMan(login As String, HpPass As String, manPass As String, accountPass As String)

    Dim MiniPath As String
    Dim Retval

    MiniPath = ":\Minisoft\WS92-2\Ws92_32.exe"

    On Error Resume Next
    Retval = Shell("D" & MiniPath, vbNormalNoFocus)
    On Error Resume Next
    Retval = Shell("C" & MiniPath, vbNormalNoFocus)
    On Error Resume Next
    Retval = Shell("E" & MiniPath, vbNormalNoFocus)

    channel = 0

    While channel = 0
        channel = Application.DDEInitiate("MS92-2", "S92")
    Wend

    DDETimeQuick
    Application.DDEExecute channel, "WAITS ':^Q'"
    Application.DDEExecute channel, "KBSTRING  HELLO " & UCase(login) & ".UNITED"
    Application.DDEExecute channel, "DISPLAY '^[H^[J'"
    Application.DDEExecute channel, "KBSPEC HP_RETRNKEY"
    DDETimeQuick
    Application.DDEExecute channel, "WAITS ':^Q'"
    Application.DDEExecute channel, "KBSTRING " & UCase(accountPass)
    Application.DDEExecute channel, "KBSPEC HP_RETRNKEY"
    DDETimeQuick
    Application.DDEExecute channel, "WAITS ':^Q'"
    Application.DDEExecute channel, "KBSTRING " & UCase(HpPass)
    Application.DDEExecute channel, "DISPLAY '^[H^[J'"
    Application.DDEExecute channel, "KBSPEC HP_RETRNKEY"
    DDETimeQuick
    Application.DDEExecute channel, "WAITS '.^Q'"
    Application.DDEExecute channel, "KBSPEC HP_RETRNKEY"
    DDETimeQuick
    Application.DDEExecute channel, "WAITS ' ^Q'"
    Application.DDEExecute channel, "KBSTRING 1"
    Application.DDEExecute channel, "KBSPEC HP_RETRNKEY"
    DDETimeQuick
    Application.DDEExecute channel, "WAITS ' ^Q'"
    Application.DDEExecute channel, "KBSTRING " & UCase(manPass)
    Application.DDEExecute channel, "KBSPEC HP_RETRNKEY"
    DDETimeQuick
    Application.DDEExecute channel, "WAITS '^H^Q'"
End Sub

Public Sub DDETimeQuick()

    Application.DDEExecute channel, "TIMER 120"
    Application.DDEExecute channel, "ONTIMER"

End Sub

The strings passed by DDE to the Minisoft terminal are keywords to trigger desired outputs. The issue is not in what is being communicated but in the ability to communicate. When the issue happens, it happens in the StartManMan Sub, I believe. The terminal is launched, but it seems that none of the strings are passed to the terminal as it just sits in rest indefinately (waiting for key strokes - the user can directly interact with the terminal, the terminal itself is responsive) and Excel remains incapcitated busy executing the code. The issue only ever occurs when I don't see the output of "HELLO" from "KBSTRING HELLO". If I do see the "HELLO" then it always, 100% of the time, works perfectly.

I've read the following about hanging: http://www.angelfire.com/biz/rhaminisys/ddeinfo.html#DDEslow and realize that it might be thread related, but if so that just changes the point of my question (how do I prevent/detect this?). Also the bug article referenced, Q136218, is no longer avaliable.

0

There are 0 best solutions below