Jump to content

How to know success or failure of sendcommand through VB.NET


Mihir

Recommended Posts

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.

 

 

:)

Link to comment
Share on other sites

  • 2 years later...

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

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...