Blue Prism Product

 View Only
last person joined: 10 hours ago 

This community covers the core Blue Prism RPA product.

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

Manoj Patidar's profile image
Manoj Patidar posted 11-29-2023 06:09
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
Jerome Santiago's profile image
Jerome Santiago

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. 

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: