Mihir Posted August 25, 2006 Share Posted August 25, 2006 Hello, I am using AcadDoc.sendCommand. I want to know the success or failure of sendcommand through VB.NET. I have used try catch also but sendcommand failure is not catched in .NET. Quote Link to comment Share on other sites More sharing options...
brengine Posted May 30, 2009 Share Posted May 30, 2009 Not exactly an elegant solution...but it works. Make a call to the 'GetTextWindowHistory' Function below. It copies all the text from the 'Text Window' and returns each row in an array. Hopefully from the last line returned you can decide success/failure? Note, you may need to pause your VBA execution if the SendCommand takes a while to process. I don't think the VBA waits for the SendCommand to finish (I believe it just starts the command in a parallel process). Hope this helps. Sub main() Dim sCmdLineWinHist() As String 'Some Code Here sCmdLineWinHist = GetTextWindowHistory 'Some More Code Here End Sub Function GetTextWindowHistory() As Variant 'Returns an Array of each line from the Text Window. 'Last Row in the Array will be the Response from the Last Issued Command. Dim sRetVal() As String Dim dCnt As Double Dim dLine_LastCommand As Double ThisDrawing.SendCommand "COPYHIST" & vbCr Dim MyData As DataObject Set MyData = New DataObject MyData.GetFromClipboard ReDim sRetVal(0) sRetVal(0) = MyData.GetText(1) For dCnt = 1 To Len(sRetVal(0)) If (Asc(Mid(sRetVal(0), dCnt, 1)) = 10) Then 'New Line ReDim Preserve sRetVal(UBound(sRetVal) + 1) 'If (dCnt > 1) Then ' Debug.Print sRetVal(UBound(sRetVal) - 1) 'End If ElseIf (Asc(Mid(sRetVal(0), dCnt, 1)) = 13) Then 'End of Line 'Nothing Else sRetVal(UBound(sRetVal)) = sRetVal(UBound(sRetVal)) & Mid(sRetVal(0), dCnt, 1) End If Next dCnt 'Discard 'Command: COPYHIST' line created by this function. ReDim Preserve sRetVal(UBound(sRetVal) - 1) 'Discard Blank Lines. dCnt = UBound(sRetVal) While (sRetVal(dCnt) = "") And (dCnt > 0) dCnt = dCnt - 1 ReDim Preserve sRetVal(dCnt) Wend GetTextWindowHistory = sRetVal() End Function Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.