Here is what I was able to come up with, thanks to @RetailCoder and some help on StackOverFlow StackOverFlow Dealing with the last()
function/method not working I was able to add xmlDoc.SetProperty "SelectionLanguage", "XPath"
to make it work for me. so here is how I simplified the whole process.
Here is what I was able to come up with, thanks to @RetailCoder and some help on StackOverFlow Dealing with the last()
function/method not working I was able to add xmlDoc.SetProperty "SelectionLanguage", "XPath"
to make it work for me. so here is how I simplified the whole process.
Here is what I was able to come up with, thanks to @RetailCoder and some help on StackOverFlow Dealing with the last()
function/method not working I was able to add xmlDoc.SetProperty "SelectionLanguage", "XPath"
to make it work for me. so here is how I simplified the whole process.
- I replaced my
If...For...If...For
loops with a single switch statement and some XPath statements to grab the correct nodes - I don't have to worry about if the
Comment
node exists or not, ifReturnData
is empty it is taken care of by the last If statement. - Removed the
& ""
like @retailcoder said
I left out the
& ""
part, because that's concatenating an empty string, which does strictly nothing but add confusing clutter to your code.
- There isn't anywhere to use the Joined Declaration & Assignment, the
CommentNodes
variable is set differently based on the Switch statement and Declaring it in both would be redundant. - I didn't add a
Case Else
the way this script functions it is not necessary to follow this path should they input a bad parameter, the application of this script is hard to describe. it is one of many tokens in a word document. - one last thing, I only declared variables that I used in the rest of the script, the original had
oNode
and it was never used. - I also didn't use any
Magic
iterator numbers likeiNode
orjNode
even though I thought that was rather clever.
- I replaced my
If...For...If...For
loops with a single switch statement and some XPath statements to grab the correct nodes - I don't have to worry about if the
Comment
node exists or not, ifReturnData
is empty it is taken care of by the last If statement. - Removed the
& ""
like @retailcoder said
I left out the
& ""
part, because that's concatenating an empty string, which does strictly nothing but add confusing clutter to your code.
- There isn't anywhere to use the Joined Declaration & Assignment, the
CommentNodes
variable is set differently based on the Switch statement and Declaring it in both would be redundant. - I didn't add a
Case Else
the way this script functions it is not necessary to follow this path should they input a bad parameter, the application of this script is hard to describe. it is one of many tokens in a word document. - one last thing, I only declared variables that I used in the rest of the script, the original had
oNode
and it was never used. - I also didn't use any
Magic
iterator numbers likeiNode
orjNode
even though I thought that was rather clever.
Here is what I was able to come up with, thanks to @RetailCoder and some help on StackOverFlow Dealing with the last()
function/method not working I was able to add xmlDoc.SetProperty "SelectionLanguage", "XPath"
to make it work for me. so here is how I simplified the whole process.
Public Function GetParameterXml()
GetParameterXml = _
"<Parameters>" &_
"<Parameter Value='Age' Code='A' Description='Age' Type='Combo' Tooltip='Would you like the newest or oldest Reason?'>" &_
" <Options>" &_
" <Option Code='O' Description='Oldest' Value='OLD' />" &_
" <Option Code='N' Description='Newest' Value='NEW' />" &_
" </Options>" &_
"</Parameter>" &_
"</Parameters>"
End Function
'Parameter Variables
Dim Age : Set Age = Parameters.Item( Bookmark , "Age" )
' PlaceHolder Variables
Dim CommentNodes
''' stop here and look around
stop
xmlDoc.SetProperty "SelectionLanguage", "XPath"
Select Case Age.Value
Case "OLD":
Set CommentNodes = XmlDoc.SelectNodes("Record/CelloXml/Integration/Case/ServiceEvent[1]/Service/Comment")
Case "NEW":
Set CommentNodes = XmlDoc.SelectNodes("/Record/CelloXml/Integration/Case/ServiceEvent[position() = last()]/Service/Comment")
End Select
For Each CommentNode In CommentNodes
ReturnData = ReturnData & CommentNode.Text & MD
Next
If Len(ReturnData) > 0 Then
ReturnData = Left(ReturnData, Len(ReturnData) - Len(MD))
Else
ReturnData = vbNullString
End If
Obviously I am going to remove the breakpoint when I put this into production. but I think this really cleaned up the code.