Solved

Sort a list in lotus script

Posted on 2008-10-20
16
2,739 Views
Last Modified: 2013-12-18
I'm working on an action that will take a list of names (obtained from a form) and lookup their associated group. Pull each groupname onto a list (unique names only) then update the group field on the form.

The problem I have is, before I update the group name field I want comapare the new version with the old and alert the user of the change. But the 2 fields have the groupnames in different order. Has anyone written a list compare function that can handle that?

Thx!
0
Comment
Question by:BillTr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
16 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 22762739
I must have a sort() function somewhere, but there's an easier solution in R6: use the Evaluate() function. Pass a formula as a string parameter, it returns the output values as an array.

In your case you don't even have to sort, but you might "subtract" both lists (assuming that you don't exchange two groupnames in which case there won't be differences!).

Example:

Dim v As Variant

v= Evaluate(|@Trim(@Replace(FieldWithNewNames;FieldWithOldNames;""))|, doc)
If v(0)="" Then
   ' nothing changed
Else
   'changes!!
End If
0
 

Author Comment

by:BillTr
ID: 22767140
His Sjef,
Did you mean to use @compare? I've been experimenting with this.
DUPCHKLIST is just a comma delimited string that I build. OldList is also a string field, read in from the doc.

Dim v As Variant
DUPCHKLIST = Evaluate(|@sort(DUPCHKLIST;)|)
v= Evaluate(|@Trim(@Compare(DUPCHKLIST;OLDLIST;""))|, doc)
   If v(0)="" Then
        Msgbox "No change"
   Else
       Msgbox "changed"
  End If
0
 

Author Comment

by:BillTr
ID: 22767357
Sjef,
If you can just help me with the sort on the DUPCHKLIST. That should do it.

Thx!
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 22767481
Nope, I picked @Replace purposely, I don't need @Compare. But if there's a better function to do it, be my guest. The general idea is to use Evaluate() to solve this type of problems. The example is just that: an example.

The @Replace(l1;l2;"") will replace all list values in l1 that occur in l2 by the empty string. The @Trim(l3) will remove empty strings from the list l3 and leave the rest. If there is no rest, it will leave the empty string as only element.

Of course, there could be mistakes in the code... Warranty up to and including the threshold... :-P
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 22767522
Oh, sorry, forgot something: the values should be LISTS. So if you have a string that contains commas, you'd have to @Explode it first.

v= Evaluate(|@Trim(@Replace(@Explode(Dubcek;",");OldNames;""))|, doc)
If v(0)="" Then
   ' nothing changed
Else
   'changes!!
End If

If OldNames is also comma-delimited, put another @Explode(OldNames; ",") instead of it.
0
 

Author Comment

by:BillTr
ID: 22771089
That works great, but can I sort Dupchklist?

Something like:
v = Evaluate(|@Trim(@Sort(@Explode(DUPCHKLIST;","))|,doc)???
0
 
LVL 63

Expert Comment

by:SysExpert
ID: 22771437
http://www-10.lotus.com/ldd/sandbox.nsf/ecc552f1ab6e46e4852568a90055c4cd/c53130426d18db0e85256f7b00571d46?OpenDocument&Highlight=0,group

This is the code sample for the article, "Working with groups in LotusScript."

also read the article itself.


I hope this helps !
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 22772530
v = Evaluate(|@Sort(@Explode(DUPCHKLIST;","))|,doc)

The parentheses didn't match, and the @Trim wasn't very useful, so I removed it.
0
 

Author Comment

by:BillTr
ID: 22777333
I keep getting an empty variant.. here is the code I tried.

NEWGROUPlist= Evaluate(|@Sort(@Explode(DUPCHKLIST;";"))|,doc)

NEWGROUPlist= Evaluate(|@Explode(DUPCHCKLIST)|)

DUPCHKLIST is delimited by ;

0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 22777615
The doc as a parameter is required, the formula interpreter needs to have a context. If there is a field DUPCHKLIST in the doc. So the second will never work, it needs to be

NEWGROUPlist= Evaluate(|@Explode(DUPCHCKLIST)|, doc)

The first one should work, your Notes-version is R6. I hope you didn't have those two calls together in your code?

Maybe use the debugger, so you can step through the code and inspect every variable.
0
 

Author Comment

by:BillTr
ID: 22780177
DUPCHCKLIST (now NEWGROUPstr) is a delimited string I build by pulling data out of a view. There is not a field on the form by that name.

 I changed the name to make the variable type a bit more clear.
NEWGROUPlist= Evaluate(|@Sort(@Explode(NEWGROUPstr;";"))|,doc)
NEWGROUPlist = "" when I run.
NEWGROUPstr = "group1;group2;group3"



0
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 250 total points
ID: 22780478
Aaaaah... Me bad.

NEWGROUPlist= Evaluate(|@Sort(@Explode("| + NEWGROUPstr + |";";"))|,doc)

Since Formula doesn't know a thing about NEWGROUPstr, you have to create the complete string first, by embedding the variable's contents, and then call Evaluate.
0
 

Author Comment

by:BillTr
ID: 22780861
Great!

So... another dumb question. Now that I have my list sorted, I want to display it back to the user.
I assume that means a coversion back to the text via an implode, but I get type mismatch when I try that.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 22781102
Heh, no, easier: in LotusScript we have Split and Join instead of @Explode and @Implode

Try to set the textfield's value to Join(yourarray, ";")
0
 

Author Closing Comment

by:BillTr
ID: 31508052
Worked great! Thanks again for the help!
You helped me on several things so I increased the points.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 22781529
Gweat!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question