[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 365
  • Last Modified:

Checking String Value in vb.net

What is the issue in the if clause below??I am getting 'Object reference not set to an instance of an object.'
This is the clause I need to implement    'if Risk Assessment Type is NOT Equal to "ManualUnderwriting" or Null (or Blank), a valid value is required.  '


Dim inRiskAssmtType As String = GetSafeParsedString(Row.inRISKASSMTTYPE).ToUpper()

If Row.inRISKASSMTTYPE_IsNull = True OrElse inRiskAssmtType <>"MANUALUNDERWRITING" Then
                Throw New Exception("  value is required for ,risk assessment type  '" + Row.inRISKASSMTTYPE.ToString() + "'")
            End If

Thanks in advance!!!!
0
onebite2
Asked:
onebite2
4 Solutions
 
Jared_SCommented:
Your exception uses Row.inRISKASSMTTYPE.ToString() in a scenario where Row.inRISKASSMTTYPE can be null.
0
 
onebite2Author Commented:
@Jared_S

how should we change the if statement to match the clause I had??I appreciate if you can change it and give here.


Thanks!!
0
 
YZlatCommented:
Dim inRiskAssmtType As String = GetSafeParsedString(Row.inRISKASSMTTYPE).ToUpper()

If (Row.inRISKASSMTTYPE Is Nothing OrElse inRiskAssmtType <>"MANUALUNDERWRITING") Then
                Throw New Exception("  value is required for ,risk assessment type  '" + Row.inRISKASSMTTYPE.ToString() + "'")
            End If

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Jared_SCommented:
Try this...

Dim inRiskAssmtType As String = GetSafeParsedString(Row.inRISKASSMTTYPE).ToUpper()

If String.IsNullorEmpty(inRiskAssmtType) = True Then

  Throw New Exception("  value is required for ,risk assessment type  ")

else if inRiskAssmtType <>"MANUALUNDERWRITING" Then

  Throw New Exception("  value is required for ,risk assessment type  '"_ 

+Row.inRISKASSMTTYPE.ToString() + "'")

End If

Open in new window



If you need to use this in other places you might consider writing it as a function.
Then you would call this in your sub after you assign a value to your variable with this...    

stringTest(inRiskAssmtType)

Public Function stringTest(inRiskAssmtType as string) as string

If string.IsNullOrEmpty(inRiskAssmtType) Then

  Throw New Exception("  value is required for ,risk assessment type  ")
  
  else if inRiskAssmtType <>"MANUALUNDERWRITING" Then

  Throw New Exception("  value is required for ,risk assessment type  '" _

+ Row.inRISKASSMTTYPE.ToString() + "'")

  else 
  
return

End If
  
End Function

Open in new window

0
 
Alan WarrenCommented:
Hi onebite2,
Maybe have a look at the Error Provider validation control.
VB.NET Validation Controls Page - 2

controlname.text.length will most always return a value even if null, few exceptions such as a guid may need to refer guid.tostring in order to evaluate .length.

Alan
0
 
CodeCruiserCommented:
I think source of problem is this line

>Dim inRiskAssmtType As String = GetSafeParsedString(Row.inRISKASSMTTYPE).ToUpper()

What is GetSafeParsedString doing?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now