Tip

User Defined Order

You know how to sort a list. But there are situation where user needs to order
the list. For example, consider a workflow application with approval cycle.
Let's say three approvers are there and you want user to define the order. The
following code shows how you can allow the user to define the order.
1. Create a form and type @Command([ViewRefreshFields]) in the PostOpenEvent
of the form.

2. Create a layout region and check both "Show Border" and "3D Style".

3. Create a field (in layout region) called "Fld1" as Keywords, Editable,
select "Use Formula for choices" from choices

combo box and enter value as "Fld2" and select List Box from Interface (expand
the list box to hold three values).

4. Create another field (in layout region) called "Fld2" as Text, Editable,
check "Allow multi-values", and delimiter as Newline. Hide the field for both
read and write mode. Now, enter the value
"ApproverOne":"ApproverTwo":"ApproverThree" in the default value of the field.

5. Create a hotspot button (in layout region) called "Up" and type the
following formula.
tmp:=fld1;
max:=@Elements(fld2);
tmp1:=@Member(tmp;fld2);
tmp2:="";
tmp3:="";
tmp4:="";
tmp5:="";
@If((tmp1-2)>0;@Set("tmp2";@Subset(fld2;(tmp1-2)));@Set("tmp2";""));
@If((tmp1-1)>0;@Set("tmp3";@Subset(@Subset(fld2;(tmp1-1));-1));@Set("tmp3";""));
@If(tmp1>0;@Set("tmp4";@Subset(@Subset(fld2;tmp1);-1));@Set("tmp4";""));
@If((max-tmp1)>0;@Set("tmp5";@Subset(fld2;(tmp1-max)));@Set("tmp5";""));
FIELD fld2:=tmp2:tmp4:tmp3:tmp5;
FIELD fld1:=tmp;
@Command([ViewRefreshFields])

6. Create another hotspot button (in layout region) called "Down" and type the
following formula.
(fld2);
tmp1:=@Member(tmp;fld2);
tmp2:="";
tmp3:="";
tmp4:="";
tmp5:="";
@If((tmp1-1)>0;@Set("tmp2";@Subset(fld2;(tmp1-1)));@Set("tmp2";""));
@If((tmp1)>0;@Set("tmp3";@Subset(@Subset(fld2;(tmp1));-1));@Set("tmp3";""));
@If(tmp1=max;@Set("tmp4";"");(tmp1+1)>0;@Set("tmp4";@Subset(@Subset(fld2;
(tmp1+1));-1));@Set("tmp4";""));
@If((max-(tmp1+1))>0;@Set("tmp5";@Subset(fld2;((tmp1+1)-max)));@Set("tmp5";""));
FIELD fld2:=tmp2:tmp4:tmp3:tmp5;
FIELD fld1:=tmp;
@Command([ViewRefreshFields])

7. Save the form as "UserSort" and execute it. Select the choice in the list
and click up or down button to move the item. The user defined order is
readily available in the field "Fld2".

Note: I've entered a default value in "Fld2" instead you can pass your own
value during run-time whereby user can define their own order of your choices.

Hope this helps.

This was first published in November 2000

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.