Show or Hide Multiple Rows Based on Cell Value - google-apps-script

I'm trying to create a spreadsheet that hides rows based off of a certain cell (B2) value.
I'm having issues where sometimes my code doesn't on certain if statements but works on others. For instance, the, "Kombucha" and, "Koji" if statements don't work but the, "Sweet Fermentation" does.
Spreadsheet is here and below is my code:
function onEdit2(e) {
var sh=e.range.getSheet();
var acid=[4, 6, 8];
if(sh.getName()=='Master' && e.range.columnStart==2 && e.range.rowStart==2) {
e.source.toast(e.value);
if(e.value=="Acid") {
sh.hideRows(12,73);
sh.hideRows(33,52);
sh.hideRows(53,72);
sh.hideRows(73,84);
sh.showRows (9,11);
}
if(e.value=="Kombucha") {
sh.hideRows(53,72);
}
if(e.value=="Koji") {
sh.hideRows(12,32);
}
if(e.value=="Sweet Fermentation") {
sh.hideRows(12,61);
}
else{
sh.showRows(1,32);
sh.showRows(33,52);
sh.showRows(53,72);
sh.showRows(73,84);
}
if(e.value=="All"){
sh.showRows (1,100)
}
}
}
Thank you so much for your help. I'm very green to Javascript and would like to learn to make better spreadsheets for my company.

Try this:
function onMyEdit(e) {
e.source.toast(e.value);
var sh = e.range.getSheet();
if (sh.getName() == 'Sheet0' && e.range.columnStart == 2 && e.range.rowStart == 2) {
e.source.toast('cond')
if (e.value == "Acid") {
sh.hideRows(3, 8);
}
if (e.value == "Kombucha") {
sh.hideRows(12, 10);
}
if (e.value == "Koji") {
sh.hideRows(23, 10);
}
if (e.value == "All") {
sh.showRows(1, 100)
}
}
}
None of these are overlapping so it's easy to see how it work. The problem you have was that the else clause on sweet fermentation was always showing rows that you were trying to hide from above.
function onMyEdit(e) {
e.source.toast(e.value);
var sh = e.range.getSheet();
if (sh.getName() == 'Sheet0' && e.range.columnStart == 2 && e.range.rowStart == 2) {
e.source.toast('cond')
if (e.value == "Acid") {
sh.hideRows(3, 8);
}
if (e.value == "Kombucha") {
sh.hideRows(12, 10);
}
if (e.value == "Koji") {
sh.hideRows(23, 52);
}
if(e.value == "Sweet Fermentation") {
sh.hideRows(75,25)
} else {
sh.showRows(75,25);
}
if (e.value == "All") {
sh.showRows(1, 100)
}
}
}

Related

I want to make everyone able to upload files

**Hello in my site,**
no one can upload files except those who own the names of these ranks, how can I make everyone who has a rank be able to upload files
Blockquote
I want to make everyone be able to upload files
Blockquote
app.post("/upload", function (taylinn, tetsuo) {
var sylvian = orpah;
UsersRepo.getByToken(taylinn.query.token).then(function (rubith) {
var kyele = sylvian;
if (rubith) {
if (taylinn.query.secid == "u") {
islink = "/sendfile";
upload(taylinn, tetsuo, function (yalanda) {
if (yalanda) {
tetsuo.send(yalanda);
} else {
tetsuo.end("/sendfile/" + taylinn.file.filename);
}
});
} else {
if (rubith.power == "admin" || rubith.power == "chatmaster" || rubith.power == "rank" || rubith.power == "power" || rubith.power == "Hide") {
islink = "/" + taylinn.query.state;
upload(taylinn, tetsuo, function (aya) {
if (aya) {
tetsuo.send(aya);
} else {
tetsuo.end(JSON.stringify({err: ![], msg: taylinn.file.filename}));
}
});

Issue while loop , TypeError: Cannot read property '0' of undefined

Issues in while loop instead of checking if typeof is different of undefined .
Here my code to purge data of duplicate values.
function purge() {
var ss = SpreadsheetApp
.openByUrl(SpreadsheetApp.getActive().getUrl())
.getSheetByName("Feuille 1");
var ssdata = ss.getDataRange().getValues();
var m = 1;
while (typeof ssdata[m][0] != undefined) {
var j = 1;
while (typeof ssdata[m + j][0] != undefined) {
while (ssdata[m + j][0] === ssdata[m][0]) {
if (ssdata[m + j][0] == ssdata[m][0]) {
SpreadsheetApp.openByUrl(SpreadsheetApp.getActive().getUrl()).getSheetByName("Feuille 1").getRange(m + j + 1, 1, 1, 15).clearContent();
}
j++;
}
m++;
}
}
}
How to solve it ???
Replace
while (typeof ssdata[m][0] != undefined) {
by
while (m < ssdata.length) {
or by
while (ssdata[m]) {

Encountering an error while attempting to create a game

I'm trying to create a crossword puzzle game using Actionscript 3.0 in Adobe
Animate. For the game coding, I followed an online tutorial and now I'm encountering an error. The error occurs whenever I'm in the actual game scene, no errors are encountered on the home page or instruction page. can anyone help me? my coding skills are below basic.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at CROSSWORD_CODE_fla::MainTimeline/entFrame().
stop();
quitbtn.addEventListener(MouseEvent.CLICK, quitt);
function quitt(evt: MouseEvent): void {
gotoAndStop("start");
}
var hippopotamus: Number = 0;
var horse: Number = 0;
var eel: Number = 0;
var frog: Number = 0;
var ant: Number = 0;
var turtle: Number = 0;
var tiger: Number = 0;
var bird: Number = 0;
var penguin: Number = 0;
var orca: Number = 0;
var octopus: Number = 0;
var owl: Number = 0;
var snail: Number = 0;
var duck: Number = 0;
var kangaroo: Number = 0;
var iguana: Number = 0;
var ALLwords:Number = 0;
var Total:Number = 0;
{
stage.addEventListener(Event.ENTER_FRAME, entFrame);
function entFrame(evt:Event):void {
if ((hypoH.text == ("h").toString())
&& (hypo1.text == ("i").toString())
&& (hypoP.text == ("p").toString())
&& (hypoP2.text == ("p").toString())
&& (hypoO.text == ("o").toString())
&& (hypoP3.text == ("p").toString())
&& (hypoO2.text == ("o").toString())
&& (hypoT.text == ("t").toString())
&& (hypoA.text == ("a").toString())
&& (hypoM.text == ("m").toString())
&& (hypoU.text == ("u").toString())
&& (hypoS.text == ("s").toString()))
{
hippopotamus = 1;
trace("hippopotamus");
}
}
{
if ((hrsO.text == ("o").toString())
&& (hrsR.text == ("r").toString())
&& (hrsS.text == ("s").toString())
&& (hrsE.text == ("e").toString()))
{
horse = 1;
trace("horse");
}
}
{
if ((eelE.text == ("e").toString())
&& (eel1.text == ("l").toString()))
{
eel = 1;
trace("eel");
}
}
{
if ((penP.text == ("p").toString())
&& (penE.text == ("e").toString())
&& (penN.text == ("n").toString())
&& (penG.text == ("g").toString())
&& (penU.text == ("u").toString())
&& (pen1.text == ("i").toString())
&& (penN2.text == ("n").toString()))
{
penguin = 1;
trace("penguin");
}
}
{
if ((brdB.text == ("b").toString())
&& (brdR.text == ("r").toString())
&& (brdD.text == ("d").toString()))
{
bird = 1;
trace("bird");
}
}
{
if ((octO.text == ("o").toString())
&& (octC.text == ("c").toString())
&& (octT.text == ("t").toString())
&& (octO2.text == ("0").toString())
&& (octP.text == ("p").toString())
&& (octU.text == ("u").toString()))
{
octopus = 1;
trace("octopus");
}
}
{
if ((orcR.text == ("r").toString())
&& (orcC.text == ("c").toString())
&& (orcA.text == ("a").toString()))
{
orca = 1;
trace("orca");
}
}
{
if ((owlO.text == ("o").toString())
&& (owlW.text == ("w").toString()))
{
owl = 1;
trace("owl");
}
}
{
if ((nailS.text == ("s").toString())
&& (nailA.text == ("a").toString())
&& (nail1.text == ("i").toString())
&& (nailL.text == ("l").toString()))
{
snail = 1;
trace("snail");
}
}
{
if ((dkD.text == ("d").toString())
&& (dkU.text == ("u").toString())
&& (dkC.text == ("c").toString())
&& (dkK.text == ("k").toString()))
{
duck = 1;
trace("duck");
}
}
{
if ((groA.text == ("a").toString())
&& (groN.text == ("n").toString())
&& (groG.text == ("g").toString())
&& (groA2.text == ("a").toString())
&& (groR.text == ("r").toString())
&& (groO.text == ("o").toString()))
{
kangaroo = 1;
trace("kangaroo");
}
}
{
if ((frgF.text == ("f").toString())
&& (frgR.text == ("r").toString())
&& (frgG.text == ("g").toString()))
{
frog = 1;
trace("frog");
}
}
{
if ((ignG.text == ("g").toString())
&& (ignU.text == ("u").toString())
&& (ignA.text == ("a").toString())
&& (ignN.text == ("n").toString()))
{
iguana = 1;
trace("iguana");
}
}
{
if ((antA.text == ("a").toString())
&& (antN.text == ("n").toString()))
{
ant = 1;
trace("ant");
}
}
{
if ((trtT.text == ("t").toString())
&& (trtU.text == ("u").toString())
&& (trtR.text == ("r").toString())
&& (trtT2.text == ("t").toString())
&& (trtL.text == ("l").toString()))
{
turtle = 1;
trace("turtle");
}
}
{
if ((tgr1.text == ("i").toString())
&& (tgrG.text == ("g").toString())
&& (tgrE.text == ("e").toString()))
{
tiger = 1;
trace("tiger");
}
}
ALLwords = hippopotamus + horse + eel + frog + tiger + octopus + penguin + bird + orca +
turtle + duck + snail + ant + kangaroo + iguana + owl;
Total = 16 - ALLwords;
if (Total == 0)
{
trace("Gameover");
}
incorrectTXT.text = ("you have" + Total+ " incorrect words remaining").toString();
}

Issue with setValues

I have this code :
function calculateTotals(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var total, clientID,cellValues,cellFontLines, result;
for (i=0;i<98;i++) {
//sheet.getRange("K"+i).setValue("calculating");
clientID=sheet.getRange("J3:J100").getValues();
total=0;
cellValues=sheet.getRange("B3:H234").getValues();
cellFontLines=sheet.getRange("B3:H234").getFontLines();
result=sheet.getRange("K3:K100").getValues(); // this is dumb
if (clientID[i][0] != "") {
for (j=0;j<=6;j++) {
for (k=0;k<=231;k++) {
if (cellValues[k][j] == clientID[i][0] && cellFontLines[k][j] != 'line-through' ) {
total++;
}
}
}
result[i][0]=total/2;
Logger.log(i,clientID[i][0],result[i][0]);
//sheet.getRange("K"+(i+3)).setValue(result[i][0]);
} else {
break;
}
}
sheet.getRange("K3:K100").setValues(result); // this doesn't seem to do anything
Logger.log(result);
}
I can't figure out how to use setValues. I logged it all, and it looks right, in the debugger the array is all set but I still have to use the commented out setValue() line to update that column.
As an aside, is there a better way to initialize result to the correct dimensions than just reading in the previous results?
This works :
function calculateTotals(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var total, clientID,cellValues,cellFontLines, result=new Array(98);
clientID=sheet.getRange("J3:J100").getValues();
cellValues=sheet.getRange("B3:H234").getValues();
cellFontLines=sheet.getRange("B3:H234").getFontLines();
result=sheet.getRange("K3:K100").getValues();
for (i=0;i<98;i++) {
//sheet.getRange("K"+i).setValue("calculating");
total=0
if (clientID[i][0] != "") {
for (j=0;j<=6;j++) {
for (k=0;k<=231;k++) {
if (cellValues[k][j] == clientID[i][0] && cellFontLines[k][j] != 'line-through' ) {
total++;
}
}
}
result[i][0]=total/2;
} else {
break;
}
}
sheet.getRange("K3:K100").setValues(result);
}

Change keyboard button effects on HTML

Whilst in a html textarea input, I want the tab keyboard button to act like a Word processor-style indentation key rather than skipping to the next element.
How can this be done?
google is your friend! link
function insertTab(o, e)
{
var kC = e.keyCode ? e.keyCode : e.charCode ? e.charCode : e.which;
if (kC == 9 && !e.shiftKey && !e.ctrlKey && !e.altKey)
{
var oS = o.scrollTop;
if (o.setSelectionRange)
{
var sS = o.selectionStart;
var sE = o.selectionEnd;
o.value = o.value.substring(0, sS) + "\t" + o.value.substr(sE);
o.setSelectionRange(sS + 1, sS + 1);
o.focus();
}
else if (o.createTextRange)
{
document.selection.createRange().text = "\t";
e.returnValue = false;
}
o.scrollTop = oS;
if (e.preventDefault)
{
e.preventDefault();
}
return false;
}
return true;
}
<textarea onkeydown="insertTab(this, event);"></textarea>