2016-04-27 8 views
0

私はこのコードを無限に実行しています。私はステップバイステップでチェックし、エラーがループの最後の部分にあることを確認します。 (f、3)の値が400であり、セル(f、4)のセル(f-1,4)セル(f-2,4)のセル(f-3,4)の値はそれぞれ400と400です。 200、50、20、100google appsスクリプトで無限にコードを実行

セル(F、12)は、配列を返すgetValues()代わりにgetValue()を使用している270

function myFunction() { 

     var ss = SpreadsheetApp.getActiveSpreadsheet();  

     var sheet = ss.getSheetByName("Feuille 1"); 
     var active = sheet.getActiveCell(); 

     var f = active.getRowIndex();   
     var r = sheet.getRange(f,3).getValues();   
     var i = f   
     var cellule = sheet.getRange(i,4).getValues();  
     var C = 0 

     do {    
     C = C + cellule; 
     var destverif = sheet.getRange(f,12);  
     destverif.setValue(C); 
     i = i-1;    
     }while (C + cellule <= r);  

} 
+0

共有できますか?これは、これをはるかに容易にするでしょう。それは、明確なA1表記やcol/rowインデックスで記述されたデータセットを投稿することで、「セル(f、3)に値400を持たず、セル(f、4)セル(f-1) 、4)細胞(f-2,4)細胞(f-3,4):200,50,20,100' –

+0

https://docs.google.com/spreadsheets/d/1FyzOrdvQYyZHwa3GFBq_ES_d0j-Qx-U2mNs8j1WcVoo/edit #gid = 0私はあなたとスプレッドシートを共有しました。右のスプレッドシートに行く前に、私はそれをテストしています。 –

+0

私はアクセスをリクエストしました。 –

答えて

0

値を示すべきです。あなたのwhile条件は本質的にwhile(NaN + [["200"]] <= [["400"]])をチェックしていますが、実際にはうまくいきません。まるでそれが真実に戻りつつあり、本質的にはwhile(true)だったかのようです。

これを修正するには、代わりにgetValue()を使用してください。これはすぐにあなたの無限ループを修正します。

私はgchatを使ってあなたとチャットし、あなたのロジックが予想通りの出力にも間違っていると判断しました。あなたは、このようなデータのセットを取るしようとしている。

enter image description here

は強調表示された列の値が200から開始し、あなたの合計がより大きいか400に等しいまで上がって取得します。それは、この値をヒットしたら、私はあなたのコードを修正し、列、その行の12 400/AVERAGE(200,100,101)

に書き込み、このコードは、トリックん:あなたは、いくつかのサンプルデータでスプレッドシートを

function getValues(){ 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    var sheet = ss.getSheetByName("Feuille 1"); 
    var active = sheet.getActiveCell(); 

    var rowIndex = active.getRowIndex(); //Get the rowindex of the current active cell 
    var maxValue = sheet.getRange(rowIndex,3).getValue(); //Your max value is the active cells value 

    var currentValue = 0; 
    var activeRowIndex = rowIndex 
    var loopIndex = 0; 
    do{ 

    var cellData = sheet.getRange(activeRowIndex, 4).getValue(); //Get the value of the cell next to the selectedCell 
    if(cellData !== ''){ //If the cell is not blank continue 
     currentValue += cellData; //Add up the total as we go 
     activeRowIndex --; //Subtract the row index so we can keep movign up 
     loopIndex++; //Iterate the loopIndex so we know how many numbers we have added up to calculate the average 
    } else {  
     break; //If the cell is blank, break out of the loop 
    } 

    } while (currentValue <= maxValue); 

    sheet.getRange(rowIndex, 12).setValue(maxValue/(currentValue/loopIndex)); //set the ranges value and do the math in line for the average. 
} 
関連する問題