|
-
Dec 19th, 2004, 02:13 PM
#1
Thread Starter
Addicted Member
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)
-
Dec 19th, 2004, 09:20 PM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Dec 20th, 2004, 12:17 PM
#3
Thread Starter
Addicted Member
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...
-
Dec 20th, 2004, 12:19 PM
#4
Thread Starter
Addicted Member
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.
-
Dec 20th, 2004, 01:54 PM
#5
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|