Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Runtime error: Object expected not working inside of an if statement

When I remove the outside if statement, addmessage will create a link that will jump to the txtBillTxtSetSrc field when clicked. Inside of the if statement the link displays

Microsoft JScript runtime error: Object expected".

It works without the if statement. Why does it not work with it?

If Me.txtBillTxtSetSrc.Text.Trim.Length > 0 Then
  validateExpression = "^[BCGHJSR][0-9][0-9]"
  ismatch = Regex.IsMatch((txtBillTxtSetSrc.Text).ToUpper, validateExpression)

  If ismatch = False Then
    tempErrorMsg = LASPBS_Classes.Errors.MainframeError.getError("281W") ' Text Set Must be B01-B99, etc.
    Me.MessageCenter.addMessage(tempErrorMsg, "#", "txtBillTxtSetSrc", "form1", "E")
    Me.MessageCenter.Visible = True
  End If
End If
like image 704
William Henry Avatar asked Nov 26 '12 15:11

William Henry


1 Answers

check to make sure txtBillTxtSetSrc is valid at the time of usage. If it is Nothing(null) then you cant access the .Text property and so on. Also if it is something it could be one of the properties. I would check them on by one.

 If Not (Me.txtBillTxtSetSrc is Nothing) andalso (Me.txtBillTxtSetSrc.Text.Trim.Length > 0) Then 
    validateExpression = "^[BCGHJSR][0-9][0-9]"
    ismatch = Regex.IsMatch((txtBillTxtSetSrc.Text).ToUpper, validateExpression)

    If ismatch = False Then
      tempErrorMsg = LASPBS_Classes.Errors.MainframeError.getError("281W") ' Text Set Must be B01-B99, etc.
      Me.MessageCenter.addMessage(tempErrorMsg, "#", "txtBillTxtSetSrc", "form1", "E")
      Me.MessageCenter.Visible = True
  End If
 End If
like image 186
coolblaze03 Avatar answered Nov 13 '22 11:11

coolblaze03