Access violation

The program '*' has exited with code 3221225477 (0xc0000005) 'Access violation'.

I receive this error when there is a specific error in Report VB script (desktop designer).

Error occurs when I am using Mid or Left method on Text.

Is there a way to catch error before application crash?

Comments

  • Hello!

    To resolve this issue, you can use the String.Substring method (with a length check / String.IsNullOrEmpty) within a Try...Catch block:

    Private Sub Text1_BeforePrint(sender As Object, e As EventArgs)
      Try
        Dim s As String = CStr(Report.GetColumnValue(‘Data.Code’))
        If Not String.IsNullOrEmpty(s) Then
          Text1.Text = If(s.Length >= 8, s.Substring(0, 8), s)
        End If
      Catch ex As Exception
        Text1.Text = ‘’
      End Try
    End Sub
    

    For Mid(), use s.Substring(startIndex, length) in a similar way, checking s.Length first

This discussion has been closed.