-2
Dim policy_key() As RenewalClaim.PolicyKeyType
policy_key(0).policyEffectiveDt = date_format_string(ld_EffectiveDate)

Getting error at Line2.

An Error occured - Object reference not set to an instance of an object.

Pikoh
  • 7,582
  • 28
  • 53
Mugdha
  • 5
  • 2
  • 3
    Possible duplicate of [What is a NullReferenceException, and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Pikoh Feb 03 '17 at 10:37

2 Answers2

0

Each element of object arrays also needs to be declared as a new object too.

Dim policy_key() As RenewalClaim.PolicyKeyType
Redim policy_key(0)
policy_Key(0) = new RenewalClaim.PolicyKeyType
policy_key(0).policyEffectiveDt = date_format_string(ld_EffectiveDate)

QUICK TIP: When declaring classes structures etc, it is useful to name them so you can see what type they are....

e.g. cls_Policy_Key for a class

str_Policy_Key for a structure etc.

When you come back to your code after a year.. you will thank yourself for doing so.

Trevor_G
  • 1,331
  • 1
  • 8
  • 17
0
Dim policy_key() As RenewalClaim.PolicyKeyType 

is part of your problem. When you are declaring policy_key() you are actually declaring it as an array with no elements. If you don't particularly need to use an array, for example, if you don't need to add objects to a particular element number, you might be better using a list and declaring it like this

Dim policy_key As New List(Of RenewalClaim.PolicyKeyType)

This way, you can add items easily without having to resize your array each time - The code is a little longer than Trevor's answer, but less prone to errors when you extend your code -

dim newPolicy_Key as RenewalClaim.PolicyKeyType
newPolicy_Key.policyEffectiveDt = date_format_string(ld_EffectiveDate)
policy_Key.add(newPolicyKey)
David Wilson
  • 4,369
  • 3
  • 18
  • 31
  • Array is one of webservice's request parameter, and I have to pass it as it is with filling elements. So can you please suggest me a way out using it as an array only. – Mugdha Feb 03 '17 at 15:09