cancel
Showing results for 
Search instead for 
Did you mean: 

Internal : Could not execute code stage because exception thrown by code stage: The operation completed successfully

ManojPatidar
Level 3
Dim startPoint As New Point(StartX, StartY)
Dim endPoint As New Point(EndX, EndY)
Dim size As New Size(endPoint.X - startPoint.X, endPoint.Y- startPoint.Y)
Dim capture As New Bitmap(size.Width, size.Height)
Dim g As Graphics = Graphics.FromImage(capture)
 
g.CopyFromScreen(startPoint, Point.Empty, size)
FullSavedScreenshotPath = OutputFolderPath & Format(now, "dd-MMM-yy hh-mm-ss") & ".png"
capture.Save (FullSavedScreenshotPath, System.Drawing.Imaging.ImageFormat.Png)
ScreenshotImage = capture
 
g.Dispose()
I am using above code to capture screenshot of the screen, where i am passing parameters startX, endX, startY, endY, OutputFolderPath. 
this code was working fine for last couple of months but today when i run the bot got this error:
Internal : Could not execute code stage because exception thrown by code stage: The operation completed successfully
please help with this.
Thanks and Regards
Manoj Patidar
1 REPLY 1

jsantiago08
Level 4

I worked on the code to capture screenshots, made some tweaks, and gave it a test spin and it worked from my end. It looks good now. 

35951.png

Dim startPoint As New Point(StartX, StartY)
Dim endPoint As New Point(EndX, EndY)
Dim ScreenshotImage As Bitmap
Dim FullSavedScreenshotPath As String

If startPoint = endPoint Then
    Exit Sub
End If

Dim size As New Size(Math.Abs(endPoint.X - startPoint.X), Math.Abs(endPoint.Y - startPoint.Y))

If size.Width <= 0 OrElse size.Height <= 0 Then
    Exit Sub
End If

Dim capture As New Bitmap(size.Width, size.Height)
Dim g As Graphics = Graphics.FromImage(capture)

Try
    g.CopyFromScreen(startPoint, Point.Empty, size)
    FullSavedScreenshotPath = OutputFolderPath & Format(Now, "dd-MMM-yy hh-mm-ss") & ".png"
    capture.Save(FullSavedScreenshotPath, System.Drawing.Imaging.ImageFormat.Png)
    ScreenshotImage = capture
    
Catch ex As Exception
    Error_Messages = ("Error capturing screenshot: " & ex.Message)
Finally
    g.Dispose()
End Try

Output:

35952.png