2014-12-08 3 views
0

설치 UI가 작동하는 것 같습니다.구글 스크립트의 두 텍스트 상자의 내용을 비교하십시오.

두 개의 textboxes이 비어 있지 않은지 확인한 다음 무언가를하고 싶습니다.

아래 주제와 관련된 스크립트를 표시하고 필요한 경우 전체 기능을 추가 할 수 있습니다.

누구나 나를 도와 줄 수 있습니까? 현재 코드는 길이를 검색 할 수없는 메시지를 생성합니다.

마지막 : handlerFunction

function handlerFunction(eventInfo) 
    { 
    var app=UiApp.getActiveApplication(); 
    var parameter = eventInfo.parameter; 
    var panel = parameter.panel; 
    var source = parameter.source; 
    var text100 = parameter.text100; 
    var text101 = parameter.text101; 
    var text102 = parameter.text102; 
    var text103 = parameter.text103; 
    var text104 = parameter.text104; 
    var text105 = parameter.text105; 
    var text106 = parameter.text106; 
    var stations=parameter.stations; 
    var stations2=parameter.stations2; 
    var systems = parameter.systems; 
    var systems2 = parameter.systems2; 
    var products=parameter.products; 
    var products2=parameter.products2; 
    var but200 = parameter.but200; 
    var but201 = parameter.but201; 

switch (source)  
    { 
     case '1': 
      var app=UiApp.getActiveApplication(); 
      app.getElementById('text100').setText(systems) 
      .setStyleAttribute('textAlign', 'center'); 
      return app; 
     break; 

     case '2': 

      // get the value of last changed element in listbox written to editbox 
      var app=UiApp.getActiveApplication(); 
      app.getElementById('text101').setValue(stations) 
      .setStyleAttribute('textAlign', 'center'); 
      return app; 
     break; 

     case '3': 
      var app=UiApp.getActiveApplication(); 
      app.getElementById('text102').setValue(products) 
      .setStyleAttribute('textAlign', 'center'); 
      return app; 
     break; 

       case '4': 
      var app=UiApp.getActiveApplication(); 
      app.getElementById('text10').setText(systems2) 
      .setStyleAttribute('textAlign', 'center'); 
      return app; 
     break; 

     case '5': 

      // get the value of last changed element in listbox written to editbox 
      var app=UiApp.getActiveApplication(); 
      app.getElementById('text11').setValue(stations) 
      .setStyleAttribute('textAlign', 'center'); 
      return app; 
     break; 

     case '6': 
      var app=UiApp.getActiveApplication(); 
      app.getElementById('text12').setValue(products2) 
      .setStyleAttribute('textAlign', 'center'); 
      return app; 
     break; 


     case '200': // SAVE button cliked 
     var app=UiApp.getActiveApplication(); 

     // var parameter = eventInfo.parameter; 
     var test1=app.getElementById('text100').setText(parameter.text.length); 
     var test2=app.getElementById('text101').setText(parameter.text.length); 

      if (test1 >= '1' && test2 >= '1') 
      { 
       app.getElementById('text103').setValue('123'); 

      } 

       return app; 
      break;  

    } 

} 

답변

0

에 대한 디버그를 실행할 때 로그는 응용 프로그램을 제외하고 모든 정의되지 말한다이 줄을 변경해보십시오 : 이것에

var test1=app.getElementById('text100').setText(parameter.text.length); 

: 단지

var test1=app.getElementById('text100').setText(eventInfo.parameter.text.length); 

I을 추가 된 eventInfo.

은 즉,이 문서의 예제에 사용되는 방법은 다음과 같습니다

Google Documentation - Class TextBox

+0

안녕하세요. 같은 오류가 발생합니다 : 정의되지 않은 속성 길이를 읽습니다. 시도해 보았습니다. eventInfo/parameter –

+0

텍스트 상자의 ID를 설정해야합니다. 'var text100 = app.createTextBox(). setId ("text100");'해봤습니까? [Google 문서] (https://developers.google.com/apps-script/reference/ui/text-box#setId (String)) –

+1

안녕하세요, 그렇지만 setID에 작은 따옴표를 사용했습니다. 모든 스크립트를 보여주는 내 질문에 새로운 대답을 게시하십시오. 내 (슬픈) 코딩을 들여다 주셔서 감사합니다 :) –

0

을 heres는 모든 스크립트.

function doGet() { 

var app = UiApp.createApplication(); 
    app.setStyleAttribute("background", '#aaaaaa').setStyleAttribute("color", "white"); 
    app.setTitle("Elite Dangerous trading"); 
    app.setHeight('1100'); 
    app.setWidth('1850'); 




// drawui(); 

    var app=UiApp.getActiveApplication(); 
    //create panel 
    var panel = app.createAbsolutePanel(); 
    panel.setStyleAttribute("position",0); 
    panel.setStyleAttribute("height",1100); 
    panel.setStyleAttribute("width",1850); 
    panel.setStyleAttribute('backgroundImage',"url('http://www.incgamers.com/wp-content/uploads/2014/07/elite-dangerous.jpg')"); 

    var handle = app.createServerHandler("handlerFunction"); 
    // create grid1 
var mygrid1 = app.createGrid(3, 4) 
.setStyleAttribute("background", '#5F9EF5') 
.setBorderWidth(3) 
.setCellSpacing(8) 
.setCellPadding(8); 


    // create grid2 
var mygrid2 = app.createGrid(3, 4) 
.setStyleAttribute("background", '#754F0E') 
.setBorderWidth(3) 
.setCellSpacing(8) 
.setCellPadding(8); 

    // create 3 listboxes with handle for save 

var systems = app.createListBox().setId('1').setName('systems').setPixelSize(200,24).addChangeHandler(handle) 
.setStyleAttribute("background", "blue").setStyleAttribute("color", "white").setStyleAttribute('textAlign', 'center'); 

var stations = app.createListBox().setId('2').setName('stations').setPixelSize(200,24).addChangeHandler(handle) 
.setStyleAttribute("background", "blue").setStyleAttribute("color", "white").setStyleAttribute('textAlign', 'center'); 

var products = app.createListBox().setId('3').setName('products').setPixelSize(200,24).addChangeHandler(handle) 
.setStyleAttribute("background", "blue").setStyleAttribute("color", "white").setStyleAttribute('textAlign', 'center'); 


    // create 3 listboxes with handle for show 

var systems2 = app.createListBox().setId('4').setName('systems2').setPixelSize(200,24).addChangeHandler(handle) 
.setStyleAttribute("background", '#4D3308').setStyleAttribute("color", "yellow").setStyleAttribute('textAlign', 'center'); 

var stations2 = app.createListBox().setId('5').setName('stations2').setPixelSize(200,24).addChangeHandler(handle) 
.setStyleAttribute("background", '#4D3308').setStyleAttribute("color", "yellow").setStyleAttribute('textAlign', 'center'); 

var products2 = app.createListBox().setId('6').setName('products2').setPixelSize(200,24).addChangeHandler(handle) 
.setStyleAttribute("background", '#4D3308').setStyleAttribute("color", "yellow").setStyleAttribute('textAlign', 'center'); 



    //create 4 read only text boxes 

var text1 = app.createTextBox() 
    .setStyleAttribute("background", "blue").setStyleAttribute("color", "white").setStyleAttribute('textAlign', 'center') 
    .setName('text1') 
    .setId('text1') 
    .setText("System input") 
    .setWidth(200)  
    .setReadOnly(true); 


    var text2 = app.createTextBox() 
    .setStyleAttribute("background", "blue").setStyleAttribute("color", "white").setStyleAttribute('textAlign', 'center') 
    .setName('text2') 
    .setId('text2') 
    .setText("Station input") 
    .setWidth(200)  
    .setReadOnly(true); 


    var text3 = app.createTextBox() 
    .setStyleAttribute("background", "blue").setStyleAttribute("color", "white").setStyleAttribute('textAlign', 'center') 
    .setName('text3') 
    .setId('text3') 
    .setText("Product input") 
    .setWidth(200)  
    .setReadOnly(true); 


    // price pr. item textbox 
    var text4= app.createTextBox() 
    .setStyleAttribute("background", "blue").setStyleAttribute("color", "white").setStyleAttribute('textAlign', 'center') 
    .setName('text4') 
    .setId('text4') 
    .setText("Station sellingprice a piece") 
    .setWidth(200)  
    .setReadOnly(true); 




    //create 4 read only text boxes for textbox showfields showing 

var text9 = app.createTextBox() 
    .setStyleAttribute("background", '#4D3308').setStyleAttribute("color", "yellow").setStyleAttribute('textAlign', 'center') 
    .setName('text9') 
    .setId('text9') 
    .setWidth(200)  
    .setReadOnly(true); 


    var text10= app.createTextBox() 
    .setStyleAttribute("background", '#4D3308').setStyleAttribute("color", "yellow").setStyleAttribute('textAlign', 'center') 
    .setName('text10') 
    .setId('text10') 
    .setWidth(200)  
    .setReadOnly(true); 


    var text11 = app.createTextBox() 
    .setStyleAttribute("background", '#4D3308').setStyleAttribute("color", "yellow").setStyleAttribute('textAlign', 'center') 
    .setName('text11') 
    .setId('text11') 
    .setWidth(200)  
    .setReadOnly(true); 


    // price pr. item textbox 
    var text12= app.createTextBox() 
    .setStyleAttribute("background", '#4D3308').setStyleAttribute("color", "yellow").setStyleAttribute('textAlign', 'center') 
    .setName('text12') 
    .setId('text12') 
    .setWidth(200)  
    .setReadOnly(true); 


     //create 4 read only text boxes for textbox showfields showing 

var text5 = app.createTextBox() 
    .setStyleAttribute("background", '#4D3308').setStyleAttribute("color", "yellow").setStyleAttribute('textAlign', 'center') 
    .setName('text5') 
    .setId('text5') 
    .setText("System") 
    .setWidth(200)  
    .setReadOnly(true); 


    var text6 = app.createTextBox() 
    .setStyleAttribute("background", '#4D3308').setStyleAttribute("color", "yellow").setStyleAttribute('textAlign', 'center') 
    .setName('text6') 
    .setId('text6') 
    .setText("Station") 
    .setWidth(200)  
    .setReadOnly(true); 


    var text7 = app.createTextBox() 
    .setStyleAttribute("background", '#4D3308').setStyleAttribute("color", "yellow").setStyleAttribute('textAlign', 'center') 
    .setName('text7') 
    .setId('text7') 
    .setText("Product") 
    .setWidth(200)  
    .setReadOnly(true); 


    // price pr. item textbox 
    var text8= app.createTextBox() 
    .setStyleAttribute("background", '#4D3308').setStyleAttribute("color", "yellow").setStyleAttribute('textAlign', 'center') 
    .setName('text8') 
    .setId('text8') 
    .setText("Station sellingprice a piece") 
    .setWidth(200)  
    .setReadOnly(true); 


// create 4 textboxes 100,101,102,103, from which to save system,station,products input 

    var text100 = app.createTextBox().addChangeHandler(handle) 
    .setStyleAttribute("background", "blue").setStyleAttribute("color", "white").setStyleAttribute('textAlign', 'center') 
    .setName('text100') 
    .setId('text100') 
    .setText("") 
    .setWidth(200)  
    .setReadOnly(false); 

    var text101= app.createTextBox().addChangeHandler(handle) 
    .setStyleAttribute("background", "blue").setStyleAttribute("color", "white").setStyleAttribute('textAlign', 'center') 
    .setName('text101') 
    .setId('text101') 
    .setText("") 
    .setWidth(200)  
    .setReadOnly(false); 

    var text102 = app.createTextBox().addChangeHandler(handle) 
    .setStyleAttribute("background", "blue").setStyleAttribute("color", "white").setStyleAttribute('textAlign', 'center') 
    .setName('text102') 
    .setId('text102') 
    .setText("") 
    .setWidth(200)  
    .setReadOnly(false); 


    var text103 = app.createTextBox().addChangeHandler(handle) 
    .setStyleAttribute("background", "blue").setStyleAttribute("color", "white").setStyleAttribute('textAlign', 'center') 
    .setName('text103') 
    .setId('text103') 
    .setText("") 
    .setWidth(200)  
    .setReadOnly(false); 



//create submit buttons 
    var inputbutton = app.createButton().addClickHandler(handle) 
    .setStyleAttribute("background", '#0000FF').setStyleAttribute("color", "white").setStyleAttribute('textAlign', 'center') 
    .setId('200') 
    .setWidth(80) 
    .setHeight(80) 
    .setText("SAVE"); 



//create submit buttons 
    var showbutton = app.createButton().addClickHandler(handle) 
    .setStyleAttribute("background", '#4D3308').setStyleAttribute("color", "yellow").setStyleAttribute('textAlign', 'center') 
    .setId('201') 
    .setWidth(80) 
    .setHeight(80) 
    .setText("SHOW"); 


    // fill listboxes save 

    //Open the spreadsheet and get the sheet objects 
var openedSS = SpreadsheetApp.openById("15tGpfnt72_yxVcO3Kp0wFBLfYpf8nr3vZCteprtX_Ss"); 
var sheetList1 = openedSS.getSheetByName("data");//Spreadsheet must match with sheet name 

numItemList1 = sheetList1.getLastRow()-1;//-1 is to exclude header row 
    //get the item array 
    list1ItemArray = sheetList1.getRange(2,1,numItemList1,1).getValues(); 
    //Add the items in ListBox 
    for(var i=0; i<list1ItemArray.length; i++){ 
    products.addItem(list1ItemArray[i][0]); 
    } 
    i=0; 


numItemList2 = sheetList1.getLastRow()-1;//-1 is to exclude header row 
    //get the item array 
    list2ItemArray = sheetList1.getRange(2,3,numItemList2,1).getValues(); 
    //Add the items in ListBox 
    for(var i=0; i<list2ItemArray.length; i++){ 
    stations.addItem(list2ItemArray[i][0]); 
    } 
    i=0; 


    numItemList3 = sheetList1.getLastRow()-1;//-1 is to exclude header row 
    //get the item array 
    list3ItemArray = sheetList1.getRange(2,5,numItemList3,1).getValues(); 
    //Add the items in ListBox 
    for(var i=0; i<list3ItemArray.length; i++){ 
    systems.addItem(list3ItemArray[i][0]); 
    } 
    i=0; 


    // fill listboxes read 

    //Open the spreadsheet and get the sheet objects 
// var openedSS = SpreadsheetApp.openById("15tGpfnt72_yxVcO3Kp0wFBLfYpf8nr3vZCteprtX_Ss"); 
// var sheetList1 = openedSS.getSheetByName("data");//Spreadsheet must match with sheet name 

numItemList4 = sheetList1.getLastRow()-1;//-1 is to exclude header row 
    //get the item array 
    list4ItemArray = sheetList1.getRange(2,1,numItemList1,1).getValues(); 
    //Add the items in ListBox 
    for(var i=0; i<list4ItemArray.length; i++){ 
    products2.addItem(list4ItemArray[i][0]); 
    } 
    i=0; 


numItemList5 = sheetList1.getLastRow()-1;//-1 is to exclude header row 
    //get the item array 
    list5ItemArray = sheetList1.getRange(2,3,numItemList2,1).getValues(); 
    //Add the items in ListBox 
    for(var i=0; i<list5ItemArray.length; i++){ 
    stations2.addItem(list5ItemArray[i][0]); 
    } 
    i=0; 


    numItemList6 = sheetList1.getLastRow()-1;//-1 is to exclude header row 
    //get the item array 
    list6ItemArray = sheetList1.getRange(2,5,numItemList3,1).getValues(); 
    //Add the items in ListBox 
    for(var i=0; i<list6ItemArray.length; i++){ 
    systems2.addItem(list6ItemArray[i][0]); 
    } 
    i=0; 


// fill up grid 

    mygrid1.setWidget(0, 0, text1); 
    mygrid1.setWidget(0, 1, text2); 
    mygrid1.setWidget(0, 2, text3); 
    mygrid1.setWidget(0, 3, text4); 
    mygrid1.setWidget(1, 3, text103); 
    mygrid1.setWidget(1, 0, text100); 
    mygrid1.setWidget(1, 1, text101); 
    mygrid1.setWidget(1, 2, text102); 
    mygrid1.setWidget(2, 0, systems); 
    mygrid1.setWidget(2, 1, stations); 
    mygrid1.setWidget(2, 2, products); 
    panel.add(mygrid1,24,100); 
    panel.add(inputbutton,436,270); 


    mygrid2.setWidget(0, 0, text5); 
    mygrid2.setWidget(0, 1, text6); 
    mygrid2.setWidget(0, 2, text7); 
    mygrid2.setWidget(0, 3, text8); 
    mygrid2.setWidget(1, 3, text9); 
    mygrid2.setWidget(1, 0, text10); 
    mygrid2.setWidget(1, 1, text11); 
    mygrid2.setWidget(1, 2, text12); 
    mygrid2.setWidget(2, 0, systems2); 
    mygrid2.setWidget(2, 1, stations2); 
    mygrid2.setWidget(2, 2, products2); 
    panel.add(mygrid2,24,570); 
    panel.add(showbutton,436,740); 




//add the panel to the application 
    app.add(panel); 

// add callbacks 


handle.addCallbackElement(inputbutton) 
     .addCallbackElement(showbutton) 
     .addCallbackElement(text100) 
     .addCallbackElement(text101) 
     .addCallbackElement(text102) 
     .addCallbackElement(text103) 
     .addCallbackElement(text9) 
     .addCallbackElement(text10) 
     .addCallbackElement(text11) 
     .addCallbackElement(text12) 
     .addCallbackElement(systems) 
     .addCallbackElement(stations) 
     .addCallbackElement(products2) 
     .addCallbackElement(systems2) 
     .addCallbackElement(stations2) 
     .addCallbackElement(products2) 
     .addCallbackElement(panel); 




    var doc = SpreadsheetApp.getActive(); 
    doc.show(app); 
    return app; 

} 


function handlerFunction(eventInfo) 
    { 
    var app=UiApp.getActiveApplication(); 
    var parameter = eventInfo.parameter; 


    // There's a lot of information in 'parameter' about the event too, but we'll focus here 
    // only on the callback elements. 
    var panel = parameter.panel; 
    var source = parameter.source; 
    var text100 = parameter.text100; 
    var text101 = parameter.text101; 
    var text102 = parameter.text102; 
    var text103 = parameter.text103; 
    var text104 = parameter.text104; 
    var text105 = parameter.text105; 
    var text106 = parameter.text106; 
    var stations=parameter.stations; 
    var stations2=parameter.stations2; 
    var systems = parameter.systems; 
    var systems2 = parameter.systems2; 
    var products=parameter.products; 
    var products2=parameter.products2; 
    var but200 = parameter.but200; 
    var but201 = parameter.but201; 
    var test1 = parameter.test1; 
    var test2 = parameter.test2; 


    switch (source)  
    { 
     case '1': 
      var app=UiApp.getActiveApplication(); 
     app.getElementById('text100').setText(systems) 
      .setStyleAttribute('textAlign', 'center'); 
      return app; 
     break; 

     case '2': 

      // get the value of last changed element in listbox written to editbox 
      var app=UiApp.getActiveApplication(); 
      app.getElementById('text101').setValue(stations) 
      .setStyleAttribute('textAlign', 'center'); 
      return app; 
     break; 

     case '3': 
      var app=UiApp.getActiveApplication(); 
      app.getElementById('text102').setValue(products) 
      .setStyleAttribute('textAlign', 'center'); 
      return app; 
     break; 

       case '4': 
      var app=UiApp.getActiveApplication(); 
      app.getElementById('text10').setText(systems2) 
      .setStyleAttribute('textAlign', 'center'); 
      return app; 
     break; 

     case '5': 

      // get the value of last changed element in listbox written to editbox 
      var app=UiApp.getActiveApplication(); 
      app.getElementById('text11').setValue(stations) 
      .setStyleAttribute('textAlign', 'center'); 
      return app; 
     break; 

     case '6': 
      var app=UiApp.getActiveApplication(); 
      app.getElementById('text12').setValue(products2) 
      .setStyleAttribute('textAlign', 'center'); 
      return app; 
     break; 


     case '200': // SAVE button cliked 
     var app=UiApp.getActiveApplication(); 
     var parameter = eventInfo.parameter; 


     // var parameter = eventInfo.parameter; 
    // var test1=app.getElementById('text100').setText(parameter.text.length); 
    // var test2=app.getElementById('text101').setText(parameter.text.length); 

     var test1=app.getElementById('text100').setValue(text100); 
     var test2=app.getElementById('text101').setValue(text101); 

      if (test1 >= '1' && test2 >= '1') 
      { 
       app.getElementById('text103').setValue('123'); 

      } 

      return app; 
      break; 


    } 



} 
+0

그럼 이제 작동합니까? 어떤 코드 라인에 오류가 있습니까? –

+0

슬프게도, 작동하지 않습니다. 스위치 케이스를 입력 할 때 eventinfo, e의 느슨한 추적처럼 보입니다. 거의 모든 정보는 정의되지 않지만 응용 프로그램 매개 변수입니다. –

1

문제, 우아한 말을하지 해결했다 :)

Scriptcode 아래로 아래.

관심을 가져 주셔서 감사합니다.

관련

 function handlerFunction(eventinfo) 
    { 
    var app=UiApp.getActiveApplication(); 
    var parameter =eventinfo.parameter; 
    var panel = parameter.panel; 
    var source = parameter.source; 
    var text100 = parameter.text100; 
    var text101 = parameter.text101; 
    var text102 = parameter.text102; 
    var text103 = parameter.text103; 
    var text104 = parameter.text104; 
    var text105 = parameter.text105; 
    var text106 = parameter.text106; 
    var stations=parameter.stations; 
    var stations2=parameter.stations2; 
    var systems = parameter.systems; 
    var systems2 = parameter.systems2; 
    var products=parameter.products; 
    var products2=parameter.products2; 
    var but200 = parameter.but200; 
    var but201 = parameter.but201; 


    switch(parameter.source) 
    { 
     case '1': 
      var app=UiApp.getActiveApplication(); 
     app.getElementById('text100').setText(systems) 
      .setStyleAttribute('textAlign', 'center'); 
      return app; 
     break; 

     case '2': 

      // get the value of last changed element in listbox written to editbox 
      var app=UiApp.getActiveApplication(); 
      app.getElementById('text101').setValue(stations) 
      .setStyleAttribute('textAlign', 'center'); 
      return app; 
     break; 

     case '3': 
      var app=UiApp.getActiveApplication(); 
      app.getElementById('text102').setValue(products) 
      .setStyleAttribute('textAlign', 'center'); 
      return app; 
     break; 

       case '4': 
      var app=UiApp.getActiveApplication(); 
      app.getElementById('text10').setText(systems2) 
      .setStyleAttribute('textAlign', 'center'); 
      return app; 
     break; 

     case '5': 

      // get the value of last changed element in listbox written to editbox 
      var app=UiApp.getActiveApplication(); 
      app.getElementById('text11').setValue(stations) 
      .setStyleAttribute('textAlign', 'center'); 
      return app; 
     break; 

     case '6': 
      var app=UiApp.getActiveApplication(); 
      app.getElementById('text12').setValue(products2) 
      .setStyleAttribute('textAlign', 'center'); 
      return app; 
     break; 


     case '200': // SAVE button cliked 
     var app=UiApp.getActiveApplication(); 
     var val1=parameter.text100.length; 
     var val2=parameter.text101.length; 

     if (val1 !=0 && val2 !=0) 
      { 
       app.getElementById('text103').setValue(val1); 

       return app; 
      } 
     break; 
    } 

} 
+0

솔루션을 찾았습니다 게시 해 주셔서 감사합니다. –

관련 문제