More help with @Subset please

Hi

This topic has been discussed extensively but I can’t find the answer I need - so if you can point me to the right thread that would be great. I have a table where the values are stored in text strings and I use several buttons to add, modify and delete. I have added the code from one button to show you quite how many times I use @Subset. I am getting the “second argument to @Subset cannot be zero”. I have tried using @Statusbar and @Prompt without success to try to find where the error is occurring. Can someone please tell me how to find the error(s) or specifically what code I need to add and where in order to error check it.

Many thanks

Tim

tnorris@notesafrica.co.za

=========================

replicaid:=“C1256870:003CDA3C”;

telemRT := @Elements(OItemNumber);

@If(telemRT; “”; @Return(“”));

tNewQty := “”;

tNewDesc := “”;

tNewFreq := “”;

tItemNo := “”;

tItemSearch0 := “”;

tItemDescription := “”;

tItemFrequency := “”;

tItemSearch := “”;

tSLP := “”;

tDisc := “”;

tDisc0 := “”;

tPrice0 := “”;

tPrice := “”;

tList := OItemNumber + " " + ODescription + " - Qty: " + @Text(OQuantity);

tA := “0” : “1” : “2” : “3” : “4” : “5” : “6” : “7” : “8” : “9”;

tB := tA *+ tA;

tB2 := @Subset(tB; -99);

tPopupList := @Subset(tB2; telemRT) + ". " + tList;

tselection := @Prompt([OkCancelList]; “Modify Item”; “Select the item you wish to modify:”; @Subset(tPopupList; 1); tPopupList);

@If(tselection = “”; @Return(“”); “”);

tChoice := @Member(tselection; tPopupList);

tNbrElements := @Elements(tPopupList);

tWhat := @Prompt([OkCancelList]; “Modify Field”; "Select the field you wish to modify for Item " + @Subset(@Subset(OItemNumber; tChoice); -1); “List Price”; “Item Number” : “Item Description” : “Quantity” : “List Price” : “Discount”: “Replacement Frequency”);

@If(tWhat = “Quantity”;

@Do(@Set(“tNewQty”; @TextToNumber(@Prompt([OkCancelEdit]; “New Quantity”; “Enter new quantity”; @Text(@Subset(@Subset(OQuantity; tChoice); -1)))));

@If(@IsNumber(tNewQty) & tNewQty > 0; “”; @Do(@Prompt([Ok]; “Error”; “The quantity entered is not a valid number ! " + @Text(tNewQty)); @Return(”")) );

@If(tChoice = 1; @SetField(“OQuantity”; tNewQty : @Subset(OQuantity; 1 - tNbrElements));

tChoice = tNbrElements; @SetField(“OQuantity”; @Subset(OQuantity; tChoice - 1) : tNewQty);

@SetField(“OQuantity”; @Subset(OQuantity; tChoice - 1) : tNewQty : @Subset(OQuantity; tChoice - tNbrElements))));

tWhat = “Replacement Frequency”; @Do(@Set(“tNewFreq”; @TextToNumber(@Prompt([OkCancelEdit]; “New Replacement Frequency”; “Enter new Frequency”; @Text(@Subset(@Subset(OFrequency; tChoice); -1)))));

@If(@IsError(tNewFreq); @Do(@Prompt([Ok]; “Error”; “The frequency you entered is not a valid number ! " + @Text(tNewFreq) + “. Click OK and repeat the procedure”); @Return(”")); “”);

@If(tChoice = 1; @SetField(“OFrequency”; tNewFreq : @Subset(OFrequency; 1 - tNbrElements));

tChoice = tNbrElements; @SetField(“OFrequency”; @Subset(OFrequency; tChoice - 1) : tNewFreq);

@SetField(“OFrequency”; @Subset(OFrequency; tChoice - 1) : tNewFreq : @Subset(OFrequency; tChoice - tNbrElements))));

tWhat = “List Price”;

@Do(@Set(“tSLP”; @TextToNumber(@Prompt([OkCancelEdit]; “New Item List Price”; “Enter new Item List Price”; @Text(@Subset(@Subset(OListPrice; tChoice); -1)))));

@If(@IsError(tSLP); @Do(@Prompt([Ok]; “Error”; “The List Price you entered is not a valid number ! - " + @Text(tSLP) + “. Click OK and repeat the procedure”); @Return(”")); “”);

@Set(“tPrice”; tSLP * (1 - @Subset(@Subset(ODiscount; tChoice); -1)));

@If(tChoice = 1; @Do(@SetField(“OListPrice”; tSLP : @Subset(OListPrice; 1 - tNbrElements));

@SetField(“OPrice”; tPrice : @Subset(OPrice; 1 - tNbrElements)) );

tChoice = tNbrElements; @Do(@SetField(“OListPrice”; @Subset(OListPrice; tChoice - 1) : tSLP);

@SetField(“OPrice”; @Subset(OPrice; tChoice - 1) : tPrice) );

@Do(@SetField(“OListPrice”; @Subset(OListPrice; tChoice - 1) : tSLP : @Subset(OListPrice; tChoice - tNbrElements));

@SetField(“OPrice”; @Subset(OPrice; tChoice - 1) : tPrice : @Subset(OPrice; tChoice - tNbrElements))) ) );

tWhat = “Discount”; @Do(@Set(“tDisc0”; @TextToNumber(@Prompt([OkCancelEdit]; “New Discount”; “Enter new Discount (eg 20 for 20%)”; @Text(100 * @Subset(@Subset(ODiscount; tChoice); -1)))));

@If(@IsError(tDisc0) ; @Do(@Prompt([Ok]; “Error”; “The Discount you entered is not a valid number ! " + @Text(tDisc0) + “. Click OK and repeat the procedure”); @Return(”")); “”);

@Set(“tDisc”; tDisc0 / 100);

@Set(“tListPrice”; @Subset(@Subset(OListPrice; tChoice); -1));

@Set(“tPrice”; (1- tDisc) * tListPrice);

@If(tChoice = 1; @Do(@SetField(“ODiscount”; tDisc : @Subset(ODiscount; 1 - tNbrElements));

@SetField(“OPrice”; tPrice : @Subset(OPrice; 1 - tNbrElements)) );

tChoice = tNbrElements; @Do(@SetField(“ODiscount”; @Subset(ODiscount; tChoice - 1) : tDisc);

@SetField(“OPrice”; @Subset(OPrice; tChoice - 1) : tPrice) );

@Do(@SetField(“ODiscount”; @Subset(ODiscount; tChoice - 1) : tDisc : @Subset(ODiscount; tChoice - tNbrElements));

@SetField(“OPrice”; @Subset(OPrice; tChoice - 1) : tPrice : @Subset(OPrice; tChoice - tNbrElements))) ) );

tWhat = “Item Description”; @Do(@Set(“tNewDesc”; @Prompt([OkCancelEdit]; “Description”; “Enter new description”; @Subset(@Subset(ODescription; tChoice); -1))); @If(tChoice = 1; @SetField(“ODescription”; tNewDesc : @Subset(ODescription; 1 - tNbrElements)); tChoice = tNbrElements; @SetField(“ODescription”; @Subset(ODescription; tChoice - 1) : tNewDesc); @SetField(“ODescription”; @Subset(ODescription; tChoice - 1) : tNewDesc : @Subset(ODescription; tChoice - tNbrElements))));

tWhat = “Item Number”; @Do(@Set(“tItemNo”; @UpperCase(@Trim(@Prompt([OkCancelEdit]; “Item Number”; “Enter new item number:”; “”)))); @If(tItemNo = “”; @Return(@Prompt([Ok]; “Re-enter Item Number”; “Item Number must be entered. Please click OK and repeat the procedure”)); “”);

@Set(“tItemSearch0”; @DbLookup(“”; replicaid; “(SearchByItemNumber)”; tItemNo; 2)); @Set(“tItemDescription”; @If(@IsError(tItemSearch0) | tItemSearch0 = “”; @Left(@UpperCase(@Trim(@Prompt([OkCancelEdit]; “Description”; "Please enter Description for Item " + tItemNo; tItemDescription))); 32); @Do(@Prompt([Ok]; “Item description”; tItemSearch0); @Text(tItemSearch0))));

@Set(“tItemSearch1”; @DbLookup(“”; replicaid; “(SearchByItemNumber)”; tItemNo; 4)); @Set(“tItemFrequency”; @If(@IsError(tItemSearch1) | tItemSearch1 = “”; @Left(@UpperCase(@Trim(@Prompt([OkCancelEdit]; “Replacement Frequency (Months)”; "Please enter Frequency for Item " + tItemNo; tItemFrequency))); 32); @Do(@Prompt([Ok]; “Standard Replacement Frequency (Months)”; “The Standard Replacement Frequency for this Item is set at " + @Text(tItemSearch1) + " months”); tItemSearch1)));

@Set(“tItemSearch”; @DbLookup(“”; replicaid; “(SearchByItemNumber)”; tItemNo; 3)); @Set(“tListPrice”; @If(@IsError(tItemSearch) | tItemSearch = “”; @TextToNumber(@Prompt([OkCancelEdit]; “Item List Price”; “Enter the Item List Price for " + tItemNo; “”)); @Do(@Prompt([Ok]; “Item List Price”; @Text(tItemSearch; “F,2”)); tItemSearch))); @If(@IsNumber(tListPrice) & tListPrice > 0; “”; @Do(@Prompt([Ok]; “Re-Enter List Price”; “The List Price entered must be a valid number. Please click OK and repeat the procedure.”); @Return(”")));

@Do(@Set(“tDisc0”; @TextToNumber(@Prompt([OkCancelEdit]; “Enter Discount”; “Enter new Discount (eg 20 for 20%)”; @Text(100 * @Subset(@Subset(ODiscount; tChoice); -1)))));

@If(@IsError(tDisc0) ; @Do(@Prompt([Ok]; “Error”; “The Discount you entered is not a valid number ! " + @Text(tDisc0) + “. Click OK and repeat the procedure”); @Return(”")); “”);

@Set(“tDisc”; tDisc0 / 100);

@Set(“tListPrice”; @Subset(@Subset(OListPrice; tChoice); -1));

@Set(“tPrice”; (1- tDisc) * tListPrice));

@If(tChoice = 1; @Do(@SetField(“OItemNumber”; tItemNo : @Subset(OItemNumber; 1 - tNbrElements)); @SetField(“ODescription”; tItemDescription : @Subset(ODescription; 1 - tNbrElements)); @SetField(“OListPrice”; tListPrice : @Subset(OListPrice; 1 - tNbrElements)); @SetField(“ODiscount”; tDisc : @Subset(ODiscount; 1- tNbrElements));@SetField(“OPrice”; tPrice : @Subset(OPrice; 1 - tNbrElements)) );

tChoice = tNbrElements; @Do(@SetField(“OItemNumber”; @Subset(OItemNumber; tChoice - 1) : tItemNo); @SetField(“ODescription”; @Subset(ODescription; tChoice - 1) : tItemDescription);

@SetField(“OListPrice”; @Subset(OListPrice; tChoice - 1) : tListPrice); @SetField(“ODiscount”; @Subset(ODiscount; tChoice - 1) : tDisc); @SetField(“OPrice”; @Subset(OPrice; tChoice - 1) : tPrice));

@Do(@SetField(“OItemNumber”; @Subset(OItemNumber; tChoice - 1) : tItemNo : @Subset(OItemNumber; tChoice - tNbrElements)); @SetField(“ODescription”; @Subset(ODescription; tChoice - 1) : tItemDescription : @Subset(ODescription; tChoice - tNbrElements));

@SetField(“OListPrice”; @Subset(OListPrice; tChoice - 1) : tListPice : @Subset(OListPrice; tChoice - tNbrElements)); @SetField(“ODiscount”; @Subset(ODiscount; tChoice - 1) : tDisc : @Subset(ODiscount; tChoice - tNbrElements));

@SetField(“OPrice”; @Subset(OPrice; tChoice - 1) : tPrice : @Subset(OPrice; tChoice - tNbrElements))))); “”);

@PostedCommand([ViewRefreshFields])

Subject: More help with @Subset please

Well, here’s the first thing I noticed:

tNbrElements := @Elements(tPopupList);

…

@Subset(OQuantity; 1 - tNbrElements)

So what happens when the user chooses one choice from the popuplist?

Subject: RE: More help with @Subset please

Hi BruceYes, that could be it. If there is only one element then the second argument would evaluate to 0. So how does one get around this - endless error checks or additional code? If so, what would be the code?

Thanks for your help and interest

Tim Norris

Tel: +27 (0)11 621 4880

Fax: +27 (0)11 621 4883

Cell: +27 (0)82 552 6951

Subject: RE: More help with @Subset please

Without parsing through and decoding your entire piece of code (and I’ve tried, but it’s too long – it looks to me to be much longer than it needs to be), all I can say is that the 1 - tNbrElements part is probably just flat out wrong. Maybe it should be @Subset(OQuantity; - (tNbrElements)) or maybe it should be @Subset(@Subset(OQuantity; tNbrElements); -1)(also doable in R6 as OQuantity[tNbrElements]). Since I don’t know what the code is trying to do, I can’t say.

Did you write this yourself, or cobble it together from found code? IMO, it’s a lot less work (and a LOT more maintainable) to write such lengthy stuff myself from scratch, rather than try to crowbar a bunch of others’ code segments into the shape I need.

Subject: RE: More help with @Subset please

Hi BruceThanks for that - but the code was written in France and is correct (lots of text lists and modification depending on the position in the list). Many thanks for your input. Regards Tim