logo
down
shadow

Doing math on a for loop variable in Google Scripts


Doing math on a for loop variable in Google Scripts

By : Y.W
Date : November 20 2020, 11:01 PM
To fix this issue 'j: '+ j is a string. When you add 1 to that string, you end up doing string concatenation.
You need to use parentheses to perform the addition first:
code :


Share : facebook icon twitter icon
Google Scripts For Loop

Google Scripts For Loop


By : Phong Vân
Date : March 29 2020, 07:55 AM
Hope this helps You're trying to access the four arrays created from the values for columns 1-4.
Your for statement needs to match their structure, starting with the first array instance of 0. You can use any of the arrays for the iteration, I've chosen the first.
code :
for (var i = 0; i < evento.length; i++) {
  target.getRange(targetRow,1).setValue(evento[i]);
  target.getRange(targetRow,2).setValue(descript[i]);
  target.getRange(targetRow,3).setValue(tags[i]);
  target.getRange(targetRow,4).setValue(sheetsIDHome[i]);
  targetRow++; 
}
Using Google Sheets and Google Scripts - How do I insert an entry from a cell into a variable?

Using Google Sheets and Google Scripts - How do I insert an entry from a cell into a variable?


By : Hitesh
Date : March 29 2020, 07:55 AM
will help you The return type is an array of objects i.e. json = [{object1},{object2}] Even though there is just one element, you still need to access it like so
code :
var sym = json[0]["symbol"]
//or
var sym = json[0].symbol
function getSymbol (name) {
var url = "https://api.coinmarketcap.com/v1/ticker/"+name+"/?convert=USD";
  var response = UrlFetchApp.fetch(url);
  var text = response.getContentText();

  var json = JSON.parse(text);
  var sym = json[0]["symbol"];

  return sym;

  }
Inputting an array into Math.Max in Google Apps Scripts

Inputting an array into Math.Max in Google Apps Scripts


By : 지건호
Date : March 29 2020, 07:55 AM
wish helps you You can use Math.max.apply() at GAS. And data retrieved by getValues() is a 2 dimensional array. So in order to use the data for Math.max.apply(), the array has to be flattened. By reflecting this, the sample script can be modified as follows.
Script :
code :
function itemAdd(form) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];
  var sh = SpreadsheetApp.getActiveSheet();
  var lRow = sh.getLastRow();
  var range = sh.getRange(3,1,lRow,1);
  var ar = Array.prototype.concat.apply([], range.getValues());
  var maxNum = Math.max.apply(null, ar);
  sheet.appendRow([maxNum,form.category, form.item, form.manupub, form.details, form.quantity]);
  return true;
}
Solving math equations with fractions on google scripts

Solving math equations with fractions on google scripts


By : user1827938
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , The question deals with Maths worksheets, and specifically problems with solving equations for the addition of fractions.
This code is designed to update the results on the "Key" sheet for the fraction equations that appear on rows 8 to 26. Having established the logic and mechanism, the code can be adapted by the questioner to evaluate and update the formulae in rows 30 to 47.
code :
ws.getRange(i, 4).setValue('+');
function so_52469576() {

  // build solutions for fractions
  // Define the sdpreadsheet and sheets
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var ks = ss.getSheetByName("Key");

  // set/reset key variables
  var status = 0;
  var numtotal = 0;
  var answer = 0;
  var IntegerDenominator = 0;
  var IntegerNumerator = 0;
  var answercell = "";
  var Remainder = 0;
  var answerInteger = 0;
  var seqL = 0;
  var newnumL = 0;
  var seqR = 0;
  var newnumR = 0;
  var numL = 0; 
  var denL = 0; 
  var numR = 0; 
  var denR = 0; 
  var lcd = 0; 

  // start loop for equations in lows 8 to 26, every other row
  for (var i = 8; i <= 26; i = i + 2){

    //Logger.log("i="+i);//DEBUG

    // ensure some variables values don't carry over
    // might not be necessary
    status = 0;
    numtotal = 0;
    answer = 0;
    IntegerDenominator = 0;
    IntegerNumerator = 0;
    answercell = "";
    Remainder = 0;
    answerInteger = 0;
    seqL = 0;
    newnumL = 0;
    seqR = 0;
    newnumR = 0;
    numL = 0; 
    denL = 0; 
    numR = 0; 
    denR = 0; 
    lcd = 0; 

    // collect denominators and numerators
    numL = ks.getRange(i,16).getValue(); 
    denL = ks.getRange(i,17).getValue(); 
    numR = ks.getRange(i,19).getValue(); 
    denR = ks.getRange(i,20).getValue(); 
    lcd= ks.getRange(i,22).getValue(); 
    //Logger.log("i="+i+",numL="+numL+", denL="+denL+",numR="+numR+", denR="+denR+", lcd="+lcd); //DEBUG

    // commence evaluation
    // 1- test for an integer
    // Left side first
     if ((denL == "n/a") || (denL == 1)){
       // Left side is an integer
       status = 1;
       //Logger.log("denl is an integer"); //DEBUG
     }
     else{
       // Left side must be a Fraction
       status = 2;
       // Logger.log("denl is NOT an integer"); //DEBUG
     }

     // Right side
     if ((denR == "n/a") || (denR == 1)){
       // Left side is an integer
       status = status+1;
       // Logger.log("denR is an integer"); // DEBUG
     }
     else{
       // Left side must be a Fraction
       status = status+2;
       // Logger.log("denR is NOT an integer"); //DEBUG
     }

     // possible status values
     // 2 = Two Integers
     // 3 = One Integer and one Fraction
     // 4 = Two Fractions
     // There aretwo variations to Two Fractions: 1 - Same denominators; 2 - Different Denominators

     if (status == 2){

       //Logger.log("Status = 2 - Two Integers");
       // Two integers
       //get the numerator
       numtotal = numL + numR;
       answer = numtotal;
       //Logger.log("i="+i+",Result 2");//DEBUG
       answercell = ks.getRange(i, 7);
       answercell.setValue(answer);
       // end status 2 - Two Integers


     } else if (status == 3){ 

       //Logger.log("Status = 3 - One Integer and One Fraction");//DEBUG
       // One Integer and One Fraction
       // establish which side is the integer

       if (denL == "n/a" || denL == 1){
         // the integer is on the left
         IntegerDenominator = denR; //row, column Col L
         IntegerNumerator = numL * IntegerDenominator; 
         numtotal = IntegerNumerator + numR; 
         //Logger.log("i="+i+",Result 3-1-1");//DEBUG

       }else{
         // the integer is on the right
         IntegerDenominator = denL; //row, column Col L
         IntegerNumerator = numR * IntegerDenominator;
         numtotal = IntegerNumerator + numL;
         // Logger.log("i="+i+",Result 3-1-2");// DEBUG
       }


       // test for a numerator equal to zero
       // no intergers are = zero 
       // no denominators = zero

       if (numL==0 && numR==0){

         // doesn't apply for one integer and one fraction, 
         // but retain for consistency
         // answer must be zero

         answer = 0; 
         // Logger.log("i="+i+",Result 3-1");// DEBUG

       } else if  (numL == 0) {

       // if numL is zero, then the fraction must be on the left side
       // integer must be on the right
       // so answer is an integer

       answer = numR;
         //Logger.log("i="+i+",Result 3-2");//DEBUG

       } 
       else if (numR == 0) {

         // if numR is zero, then the fraction must be on the right side
         // so integer must be on the left  
         // so answer is an integer
         answer = numL;
         // Logger.log("i="+i+",Result 3-3");DEBUG

       } 
       else {

         // neither side = zero, so answer as normal
         answerInteger = parseInt(numtotal / IntegerDenominator);
         Remainder = numtotal-(answerInteger * IntegerDenominator);
         answer = " "+answerInteger+" "+Remainder+"/"+IntegerDenominator;
         // Logger.log("i="+i+",Result 3-4");// DEBUG
       }

       answercell = ks.getRange(i, 7);
       answercell.setValue(answer);
       // end status 3

     } else {

       //Logger.log("Status = 4 - Two Fractions");
       // Two Fractions

       // test for a numerator equal to zero
       // no intergers are = zero 
       // no denominators = zero

       if (numL==0 && numR==0){

         // doesn't apply for one integer and one fraction, 
         // but retain for consistency
         // answer must be zero

         answer = 0;
         // DEBUGLogger.log("i="+i+",Result 4-1: ");

       } else if  (numL == 0) {

         // if numL is zero, then fraction on the left must = zero
         // so only the fraction on the right applies
         // so answer is the righthand side
         answer = " "+numR+" "+"/"+denR;  
         //Logger.log("i="+i+",Result 4-2");//DEBUG

       } else if  (numR == 0) {

         // if numR is zero, then fraction on the right must = zero
         // so only the fraction on the left applies
         // so answer is the lefthand side
         answer = " "+numL+" "+"/"+denLR;  
         // Logger.log("i="+i+",Result 4-3");//DEBUG

       } else if (denL == denR && numL !=0 && numR!=0){

         // establish whehther same or different demoninators
         // same denominators
         numtotal = numL + numR;
         answerInteger = parseInt(numtotal / denL);
         Remainder = numtotal-(answerInteger * denL);
         answer = " "+answerInteger+" "+Remainder+"/"+denL;
         // Logger.log("i="+i+",Result 4-4");// DEBUG
         // end same denominators

       }
       else if (denL != denR && numL !=0 && numR!=0)
       {

         // Test for different denominators
         // Requires calculating the Lowest Common Denominator

         seqL = (lcd/denL);
         newnumL = seqL * numL;
         seqR = (lcd/denR);
         newnumR = seqR * numR;
         numtotal = newnumL+ newnumR;
         answerInteger = parseInt(numtotal/lcd);
         Remainder = numtotal-(answerInteger * lcd);
         answer = " "+answerInteger+" "+Remainder+"/"+lcd;  
         // Logger.log("i="+i+",Result4-5");// DEBUG
         // end different denominators

       }
         answercell = ks.getRange(i, 7);
         answercell.setValue(answer); 

     }// end status 4 - Two Fractions  
   }// end for  
}// end
Assume the denominators are "6" and "2". The LCM value = 6, but the true Lowest common denominator is "2". 
Inserting variable data into an existing Google Sheet in Google Scripts

Inserting variable data into an existing Google Sheet in Google Scripts


By : rsdesign
Date : March 29 2020, 07:55 AM
wish helps you I may not have entirely understood the problem you are facing. But I can see the cause of the 'Range not found' error.
Your loop starts with a value of 0 for i. This causes the script to look for a range called P0 in the first iteration.
code :
 var cell = ss.getRange("P"+(i+1));
var ss = SpreadsheetApp.openById('113aqWVAjjUYCmI2oFc_BTbXkWMPFPjk_SschsKEx6qU');
var templateFile = DriveApp.getFileById(templateId); // Outside the loop
var documentID = templateFile.makeCopy(DriveApp.getFolderById('1zV-WpzUKoRurE9FnBcfjBygBA5rCO67I')).getId();
Related Posts Related Posts :
  • Accessing 'this' inside the callback should reference my array
  • get empty request while posting
  • CSS Flip animation on click
  • How to hide element if filter returns null angularjs
  • Popups for checking/unchecking a checkbox
  • Loop event click jquery synchronize current status
  • "Export to excel" button kendogrid download more than 1 file
  • Load bootstrap forms from select page
  • Using Vue with django
  • JS Outputting a form value receives 'undefined' in console
  • Why do enzyme not find 'tr' in a table?
  • Inject GET parameter to target URL of a button, on click
  • tags in JS and css counter increment
  • Post "url-from' in a form
  • TypeError: $(...).magnificPopup is not a function
  • .toggleclass and .slidetoggle don't work
  • user agent for windows 7 vs 8 vs 10
  • How to write (A or B or C) followed by X in JavaScript regex?
  • Ember template convention
  • Sum multiple objects in multiple arrays and then average sums
  • Append a list to ul
  • React router Link; activeClassName not working
  • Site Overlay not working "Uncaught ReferenceError: closeNav is not defined"
  • How to require Stateless Functional Components (Unknown module _createWrapper?)
  • Binding a field state (disabled or hidden) according to different selected values in a combobox
  • stomp+ActiveMQ with SSL
  • creating an expression that acts like a .contains
  • Showcase the first n-items in a bootstrap grid
  • Background colour fade on carousel
  • Extend prototype using decorator
  • In react router v4 how does one link to a fragment identifier?
  • How to send local storage data with ajax to php page?
  • Javascript not working after publish to IIS
  • Remove GMT+530(Indian standard Time) without changing current time in javascript
  • Javascript: Syntax creating private object properties
  • how to make the table not having <thead> header fixed
  • ng-init with condition statements
  • javascript change height based on element's height
  • How to improve performance when loading CSV file into html table with javascript and ajax?
  • Javascript for rounding down in a finance calculator
  • .htaccess file rules are disturbing the menubar layout when window goes on mobile view
  • Angular 1.5 Option with ng-change
  • Angular Trix not working in all browsers
  • Vue.js add property to bound object
  • Push item with interfaces on typescript
  • jQuery on click event firing multiple times
  • Add first three elements of array in javascript
  • HTML5 video Uncaught TypeError: .play is not a function
  • Manipulate java List<Object> in Jquery
  • How to configure data representation in richselect?
  • How to make fade in and fade out for different images in same place using Jquery?
  • adding a function in href using JQuery
  • How to get reference to the textarea inside the table?
  • Google Visualization : How to call and draw sequential query with table?
  • ko click reference error
  • Why doesn't this arrow function work in IE 11?
  • How to access a function object from within?
  • Including other ES6 modules in development
  • How to add option to the first in knockout js options?
  • Using month view, move week by week instead of month by month
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com