Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > FusionPro® VDP Creator

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old February 1st, 2019, 06:51 AM
Deejtko Deejtko is offline
Junior Community Member
 
Join Date: Sep 2010
Location: Fort Wayne, IN
Posts: 23
Default Clean Up Repetitive Coding

Bellow is a rule I pieced together from some other post. It worked for what I needed but I would like to learn how to clean something like this up and make it more efficient. So if you are bored and good at coding some help would be greatly appreciated.

Thank you,

Code:
var StrLine1 = (!Field("series_1")) ?" ": Trim(Field("series_1") + "<br>");
 var StrLine2 = (!Field("series_2")) ?" ": Trim(Field("series_2") + "<br>");
var StrLine3 = (!Field("series_3")) ?" ": Trim(Field("series_3") + "<br>");
var StrLine4 = (!Field("series_4")) ?" ": Trim(Field("series_4") + "<br>");
var StrLine5 = (!Field("series_5")) ?" ": Trim(Field("series_5") + "<br>");
var StrLine6 = (!Field("series_6")) ?" ": Trim(Field("series_6") + "<br>");
var StrLine7 = (!Field("series_7")) ?" ": Trim(Field("series_7") + "<br>");
var StrLine8 = (!Field("series_8")) ?" ": Trim(Field("series_8") + "<br>");
var StrLine9 = (!Field("series_9")) ?" ": Trim(Field("series_9") + "<br>");
var StrLine10 = (!Field("series_10")) ?" ": Trim(Field("series_10") + "<br>");
var StrLine11 = (!Field("series_11")) ?" ": Trim(Field("series_11") + "<br>");
var StrLine12 = (!Field("series_12")) ?" ": Trim(Field("series_12") + "<br>");
var StrLine13 = (!Field("series_13")) ?" ": Trim(Field("series_13") + "<br>");
var StrLine14 = (!Field("series_14")) ?" ": Trim(Field("series_14") + "<br>");
var StrLine15 = (!Field("series_15")) ?" ": Trim(Field("series_15") + "<br>");
var StrLine16 = (!Field("series_16")) ?" ": Trim(Field("series_16") + "<br>");

return StrLine1 + StrLine2 + StrLine3 + StrLine4 + StrLine5 + StrLine6 + StrLine7 + StrLine8 + StrLine9 + StrLine10 + StrLine11 + StrLine12 + StrLine13 + StrLine14 + StrLine15 + StrLine16;
Reply With Quote
  #2  
Old February 1st, 2019, 03:22 PM
ScottHillock ScottHillock is offline
Regular Contributor
 
Join Date: Mar 2010
Posts: 93
Default Re: Clean Up Repetitive Coding

Replacing the repetition of it with a loop, and a join.
Code:
var Strline = [];
for (i=1; i <= 16; i++){
Strline[i] = (!Field("series_" + i)) ?" ": Trim(Field("series_" + i) + "<br>");
}

return Strline.join("");

Replacing even more with a filter and adjusting the join.
Code:
var Strline = [];
for (i=1; i <= 16; i++){
Strline[i] = Trim(Field("series_" + i));
}

return Strline.filter(String).join("<br>");
I'm sure there's ways to make it even simpler. But, I tend to leave code a little more verbose.
Reply With Quote
  #3  
Old February 6th, 2019, 07:27 AM
Deejtko Deejtko is offline
Junior Community Member
 
Join Date: Sep 2010
Location: Fort Wayne, IN
Posts: 23
Default Re: Clean Up Repetitive Coding

Thank you so much Scott. I wish I was able to think the code out logically like that. I see it, I know what it is doing, I just can't create it on my own.
Reply With Quote
Reply

Tags
clean up code, for loop, rules

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 02:16 PM.


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