如何基于其他变量设置变量 [英] How to set a variable based on other variables

查看:75
本文介绍了如何基于其他变量设置变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google电子表格脚本.我在那里跟踪我的调度.我创建了一个按钮,当按下该按钮时,它将使用您所在的行来创建日历事件. 我正在处理的当前问题是查找事件的任务类型和日期. 我正在使用的3列是:交付,集成,培训.都是日期. 我的第一个(如果没有的话)将日期分配给将用作事件开始日期/时间的变量. 否则,我将任务类型分配给要附加到事件标题的变量.

I'm using google spreadsheet scripting. I track my dispatches there. I created a button that when pressed uses the row you are in to create a calendar event. My current problem I'm working with is finding what type of task the event will be and the date. The 3 columns I'm working with are: Delivery, Integration, Training. All are dates. My first if else I'm assigning the date to a variable that will be used as the event start date/time. The second if else I'm assigning the task type to a variable to append to the event title.

我当前的错误是:丢失;声明前(第15行)-这是我的第一个条件

My current error is: Missing ; before statement (line 15) - that is my first if

     function AddEvent() {

  var ss = SpreadsheetApp.getActiveSheet();
  var row = ss.getActiveRange().getRow();
  var rec = ss.getRange(row,2,1,28).getValues();
  var loc = ss.getRange(row,5).getValue();
  var ttl = ss.getRange(row,2).getValue();
  var typ;
  var stt;
  var del=ss.getRange(row,10).getValue();
  var int=ss.getRange(row,11).getValue();
  var trn=ss.getRange(row,12).getValue();

    //determine what date to use, del-delivery, int-integration, trn-training
    If (isBlank(trn)=False) {stt=trn};
    Else If (isBlank(int)=False) {stt=int};
    Else {stt=del};

    //I will append my event title with this value to know the task type
    If (isBlank(trn)=False) {typ="Training: "};
    Else If (isBlank(int)=False) {typ="Integration: "};
    Else {typ="Delivery: "};

Logger.log(stt, typ);


}

推荐答案

简短答案

该脚本除了报告的错误消息外,还存在一些错误.请记住,Google Apps脚本基于JavaScript.

Short answer

Besides the reported error message the script has several errors. Bear in mind that Google Apps Script is based on JavaScript.

代替

  • If正确的语法是if
  • Else正确的语法是else
  • Else If正确的语法是else if
  • False正确的语法是false
  • If the correct syntax is if
  • Else the correct syntax is else
  • Else If the correct syntax is else if
  • False the correct syntax is false

在Google Apps脚本/JavaScript中,单个=用于将值或对象分配给变量.使用==进行抽象的相等比较,使用===进行严格的相等比较.

On Google Apps Script / JavaScript a single = is used to assign a value or object to a variable. Use == to make an abstract equality comparison and === to make a strict equality comparison.

在Google Apps脚本/JavaScript中,没有默认的isBlank()函数.您必须声明它.

On Google Apps Script / JavaScript there isn't a default isBlank() function. You have to declare it.

这篇关于如何基于其他变量设置变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆