I am working on the “Excel and Data Table” module, third Practice exercise. There is a piece of logic that goes through a table For Each row and basically says, if the list of months doesn’t contain the month from this row, then add the current month to the list of months. While I can see no difference between my command and that in the solution, mine is throwing the error “If: Object reference not set to an instance of an object.” I believe this has something to do with the list being null on the first iteration, but it’s null on the first iteration of the solution as well. Any idea why mine is not working? Thank you!
can you share your workflow?
I suppose your list is empty before you run your process, right? You can do 2 things here:
Add row(0) from your DT to the list before checking if the month exists so, your list won’t be empty.
Add a temporary item to the list, use the if condition as normal to check if the month exists, if not add it and later after your for-loop ends, remove that temporary item from the list.
Try it and let me know if you are facing any issues!
To my embarrassment, I don’t know how to properly share a workflow. Copy/Paste is clearly not the answer! The best I seem to be able to do is a picture
I tried an “Add To Collection” before checking to see if the month exists. This also gave me an error:
“Add To Collection: The property ‘Collection’ of ‘Add To Collection’ is not initialized.”
I also tried Assign Months(1)=expMonth and got another error:
“Assign: Cannot create an L-value from the given expression with property ‘set_Item’ because the target object is null.”
Sorry, I know these are newbie questions, but that’s what the training modules are supposed to be for, right?
Figured it out… when I created the variable “Months” of type “List” I did not set a default value. Once I added “new List(of string)” to the default, the error went away.
Glad you found the solution! Cheers @cora.knutson!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.