Results 1 to 5 of 5

Thread: DDERequest

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2001
    Posts
    205

    DDERequest

    Having trouble with a dderequest. I'm using the following code to call data from an external app thru DDE into Excel with VBA. It works fine for the first request. Then the second request returns a lbound of 1 and a ubound of 17, but when I try to msgbox the results, I get "subscript out of range". Any ideas?

    Code:
        
        lchannel = DDEInitiate("GoldMine", "Data")
        sRet = DDERequest(lchannel, "&username")
        sUsername = sRet(1)
        sRet = DDERequest(lchannel, "&sysinfo")
        For x = LBound(sRet) To UBound(sRet)
             MsgBox sRet(x)
          Next x
    DDETerminate (lchannel)

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: DDERequest

    Arrays are zero based unless you designate it that way. Where are you dimensioning it?
    The second time around it may not be instanciated so it would contain no
    elements - subscript out of range, 91 error.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2001
    Posts
    205

    Re: DDERequest

    I am declaring the variable simply as:

    Dim sRet

    If I try to dimension it, I get errors on the dderequest. I did try using a different variable for the second call, in case the first call is doing something to the second dderequest, but it didn't help.

    Interestingly, I ran the same code in vb6. It returns a string, not an array. Both calls are fine and both return strings. The second call returns a string separated by vbCrLf's.

    Not sure what to try next...

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Apr 2001
    Posts
    205

    Re: DDERequest

    Oh, forgot. The array isn't starting at 0. It is starting at 1 itself. I'm not forcing it to do it.

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: DDERequest

    Ok, try checking for a vaild channel before the execute and addidng line
    numbers with an error trap. A quick ex.

    Code:
    On Error GoTo MyError
    
    100 lchannel = DDEInitiate("GoldMine", "Data")
    110 If lchannel <> 0 Then
    120     sRet = DDERequest(lchannel, "&username")
    130     sUsername = sRet(1)
    140     sRet = DDERequest(lchannel, "&sysinfo")
    150     For x = LBound(sRet) To UBound(sRet)
    160          MsgBox sRet(x), vbInformation+vbOkonly, "Item: " & x
            Next
        Else
    170     Msgbox "Failed to initiate channel!"
        Endif
    MyError:
    180 DDETerminate (lchannel)
    If Err.Number <> 0 Then
        Msgbox Err.Number & " - " & Err.Description & vbNewLine & "Error at line # " & Erl, vbOkonly+vbExclamation, "Item: " & x
    Endif
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width