Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old November 12th, 2021, 09:24 AM
mjlongo mjlongo is offline
Junior Community Member
 
Join Date: Jul 2013
Location: Rochester NY
Posts: 47
Default Selecting a range of values

Hello, I have a job where the customer supplies 5 fields. F1, F2, F3, F4 and F5. They will either contain a zero or they will contain a numeric value. I have to select the range from the fields and print that range of fields when they are not zero. Fields inside the range can contain a zero. So for example:

Code:
F1=50, F2=100, F3=200, F4=300, F5=100: I print all fields.
F1=0, F2=100, F3=200, F4=300, F5=100: I print fields F2 through F5.
F1=50, F2=100, F3=0, F4=300, F5=0: I print fields F1 through F4.
F1=0, F2=0, F3=200, F4=0, F5=100: I print fields F3 through F5.
F1=0, F2=0, F3=200, F4=0, F5=0: I print only field F3.
I'm pretty sure I can come up with a long list of if statements to handle this but I'm also sure there is a smarter way. Maybe using some kind of test on an array? Any ideas on how to handle this would be greatly appreciated.
Thanks!
__________________
FusionPro VDP Creator 10.1.11

Last edited by mjlongo; November 12th, 2021 at 09:28 AM..
Reply With Quote
Old November 12th, 2021, 10:00 AM
mjlongo
This message has been deleted by mjlongo. Reason: confusing
  #2  
Old November 15th, 2021, 06:19 AM
mjlongo mjlongo is offline
Junior Community Member
 
Join Date: Jul 2013
Location: Rochester NY
Posts: 47
Default Re: Selecting a range of values

I wanted to follow up and state that I managed to figure out a pretty simple script to solve this issue. Maybe someone else can benefit from this. I just put the fields into an array and parsed from both the front and back of the array. I replaced any field that contained "$0" with the word "ZERO". This then allowed me to print any field that does not contain the word "ZERO". It turned out to be quite easy and worked perfectly for what I needed to do.

Refer to the code below:

Code:
// Create a results variable
var results='';

//Trim excess spaces from the fields in the data file
var cashLY=Trim(Field("Cash LY"));
var cash2Y=Trim(Field("Cash 2Y"));
var cash3Y=Trim(Field("Cash 3Y"));
var cash4Y=Trim(Field("Cash 4Y"));
var cash5Y=Trim(Field("Cash 5Y"));

// Put each field into an array
var arr = [cashLY,cash2Y,cash3Y,cash4Y,cash5Y]

/* check from front of array then the back for any fields that contain 
"$0". If a field does contain a "$0", replace it with the word "ZERO"
Otherwise, break out of the routine if we find a field that has 
anything other than a "$0". This will result in a middle range. */

// check from front of array
for (i=0; i < arr.length; i++){
    if(arr[i]=='$0'){
        arr[i]='ZERO';
    }else{
        break;
    };
};

// check from back of array
for (i=arr.length-1; i >=0 ; i--){
    if(arr[i]=='$0'){
        arr[i]='ZERO';
    }else{
        break;
    };
};

/* After parsing through the array, we should be left with fields
from the front of the array and then from the back of the array that
now have the word "ZERO" in it.  We can then use that information to
print the range of fields that we have been left with */

if (arr[0]!='ZERO'){results += '2020-2021<t>'+cashLY+'<br>'};
if (arr[1]!='ZERO'){results += '2019-2020<t>'+cash2Y+'<br>'};
if (arr[2]!='ZERO'){results += '2018-2019<t>'+cash3Y+'<br>'};
if (arr[3]!='ZERO'){results += '2017-2018<t>'+cash4Y+'<br>'};
if (arr[4]!='ZERO'){results += '2016-2017<t>'+cash5Y};

return results;
__________________
FusionPro VDP Creator 10.1.11
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 01:23 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.