patternMinor
Still pulling information from XML to insert into Word Document inside 3rd party application
Viewed 0 times
insertpullingapplication3rdintopartyxmlworddocumentinside
Problem
Follow up to This Question
I took some very good advice and changed my code around a little bit and eliminated some
I am not retrieving very much information but it looks so skinny now.
Is this a good thing? Is there something that I should add to the code?
This code is very readable and simple. Is there anything that I can do to make it shorter, and should I make it shorter? it is a Script and not a fully compiled code.
I took some very good advice and changed my code around a little bit and eliminated some
If statements.I am not retrieving very much information but it looks so skinny now.
Is this a good thing? Is there something that I should add to the code?
Dim phoneNode
Dim phoneNodeList
ReturnData = ""
Set phoneNodeList = XmlDoc.SelectNodes("/Record/Case/CaseFormsLoad/PartyLoad/Party/PartyPhones/Phone")
If phoneNodeList.Length > 0 Then
For Each phoneNode In phoneNodeList
If phoneNode.GetAttribute("ConfidentialFlag") = "True" Then
ReturnData = ReturnData & phoneNode.Getattribute("PhoneNum") & VbCrLf
End If
Next
End IfThis code is very readable and simple. Is there anything that I can do to make it shorter, and should I make it shorter? it is a Script and not a fully compiled code.
Solution
I see one point that seems almost obvious enough that I'm worried I might be missing something. A
For Each is "smart" enough that its body isn't executed at all for an empty collection, so you can eliminate the test for the list having a length of 0:Dim phoneNode
Dim phoneNodeList
ReturnData = ""
Set phoneNodeList = XmlDoc.SelectNodes("/Record/Case/CaseFormsLoad/PartyLoad/Party/PartyPhones/Phone")
For Each phoneNode In phoneNodeList
If phoneNode.GetAttribute("ConfidentialFlag") = "True" Then
ReturnData = ReturnData & phoneNode.Getattribute("PhoneNum") & VbCrLf
End If
NextCode Snippets
Dim phoneNode
Dim phoneNodeList
ReturnData = ""
Set phoneNodeList = XmlDoc.SelectNodes("/Record/Case/CaseFormsLoad/PartyLoad/Party/PartyPhones/Phone")
For Each phoneNode In phoneNodeList
If phoneNode.GetAttribute("ConfidentialFlag") = "True" Then
ReturnData = ReturnData & phoneNode.Getattribute("PhoneNum") & VbCrLf
End If
NextContext
StackExchange Code Review Q#49824, answer score: 6
Revisions (0)
No revisions yet.