-
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)
-
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.
-
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...
-
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.
-
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