WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Functions

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

WinItemNameId and WinItemizeEx

 Keywords: WinItemNameId WinItemizeEx Pipe Parse @TAB Format

Question:

You've selected vertical bar as the separator in WinItemizeEx (partial-winname, multiple, hidden, 2) for two purposes: separating doubles "|" as well as separating and . Not the best choice, when there are Window names containing the separator, like this one: "Status Connected|VPN Client".

Usually you separate items with @tab . That would have been just perfect: extracting the internal id from the window name with any number of vertical bars would have been just extracting the last item from a @tab-separated list item.

I guess you do not have any easy work-around for this, do you?

Answer:

Our intentions are to always make the programmers life simpler NOT harder! I agree it would have been easier to parse using some other delimiter between each window1-name and window1-ID'grouping'. However it has remained this way to assure backward compatibility. Here is a UDF I generally recommend using to parse the results:
#DefineFunction UDFReformat_List (list)
   newlist = ""
   count = ItemCount( list,"|")
   count = count/2
   For x = 1 To count By 2
     newlist = StrCat(newlist, ItemExtract(x,list,"|"),"|", ItemExtract(x+1,list,"|"),@TAB)
   Next
   Return StrTrim(newlist)
#EndFunction

winlist = WinItemNameId( )
list = UDFReformat_List (winlist)
AskItemlist("Windows and ID's", list, @TAB, @UNSORTED,@SINGLE, @FALSE)

However, the window name containing a PIPE symbol definitely does introduce a problem. Note : WinItemNameId also returns a similarly formatted result.

Here is my attempt at a workaround:


#DefineFunction UDFReformat_ListFix (list)
     newlist = ""
     count = ItemCount( list,"|")
     ret = count mod 2
     If ret == 0 ; even number of items in list
        count = count/2
           For x = 1 To count By 2
              newlist = StrCat(newlist, ItemExtract(x,list,"|"),"|", ItemExtract(x+1,list,"|"),@TAB)
           Next
     Else
           ; One of the window names contains a Pipe character !!!!
           ; Every even item must contain #WINID$
           For x = 1 To count By 2
              windowname = ItemExtract(x,list,"|")
                windowid = ItemExtract(x+1,list,"|")
                If !StrIndexNC( windowid, '#WINID$', 1, @FWDSCAN )
                      windowname = ItemExtract(x,list,"|"):"|":ItemExtract(x+1,list,"|")
                    windowid = ItemExtract(x+2,list,"|")
                     x = x+1
                EndIf
              newlist = StrCat(newlist, windowname,"|", windowid,@TAB)
           Next
     EndIf
     Return StrTrim(newlist)
#EndFunction

;winlist = 'name1|#WINID$0001|name2|#WINID$0002|namewith|pipe|#WINID$0003|name4|#WINID$0004'
;winlist = 'namewith|pipe|#WINID$0001|name2|#WINID$0002|name3|#WINID$0003|name4|#WINID$0004'
winlist = 'name1|#WINID$0001|name2|#WINID$0002|name3|#WINID$0003|namewith|pipe|#WINID$0004'

list = UDFReformat_ListFix (winlist)
AskItemlist("Windows and ID's", list, @TAB, @UNSORTED,@SINGLE, @FALSE)
Exit
I hope this answers your question.
Article ID:   W17902
Filename:   WinItemNameId and WinItemizeEx.txt
File Created: 2011:01:07:11:17:26
Last Updated: 2011:01:07:11:17:26