Cannot index in to a null array error... using 2 arrays??

Determined a fix:

Before referencing the index to an index… make it a string first:

$c=$MergeColHeaders[$i]; write-host $ct:t $Update[0].$c

 

Typing:

PS C:\Projects\mySQL\HardWay> $Primary.gettype()

IsPublic IsSerial Name BaseType


True True Object[] System.Array

PS C:\Projects\mySQL\HardWay> $MergeColHeaders.gettype()

IsPublic IsSerial Name BaseType


True True Object[] System.Array

Hard-coded Test:

PS C:\Projects\mySQL\HardWay> $MergeColHeaders[1]
TRACKING

PS C:\Projects\mySQL\HardWay> $Primary[0].tracking
resp

Desired Attempt:

PS C:\Projects\mySQL\HardWay> $Primary[0].$MergeColHeaders[1]
Cannot index into a null array.
At line:1 char:1

  • $Primary[0].$MergeColHeaders[1]
  • CategoryInfo : InvalidOperation: (:slight_smile: [], RuntimeException
  • FullyQualifiedErrorId : NullArray

 

I’m a “recovering programmer” and think my coding days are tainting my ability to understand PS.

I feel like the above samples should prove ‘if A=B and B=C then A=C’ but, clearly, PS says otherwise.

My assumption is I’m missing something obvious (which is usually my case!) but, I’ve googled for 1.5 days and have gotten no closer to unraveling this mystery. This is part of a larger conundrum but, I think it starts here.

Please let me know what else you may need from me.

That way won’t work as $MergeColHeaders is an array. it should be done like below

$Primary[0].($MergeColHeaders[1])

But the safer way to always do id like below which is error proof.

If($MergeColHeaders[1]){
   $Primary[0].($MergeColHeaders[1])
}

Thank you! It’s always all about the syntax!!