my loop keeps looping also its looping the wrong thing? - eclipse

boolean test = true;// my loop starts here and i want to be able to loop the //switch statement when non of the cases are selected, I want the loop to go to back to case 1 after displaying the error message.
while (test)
Proceed = Next.nextInt();
switch (Proceed) {
case 1:// Proceed
System.out.println("Please enter your 5 digit pin below.");
Scanner Pin = new Scanner(System.in);
int Pincode = Pin.nextInt();
if (Pincode > 9999 && Pincode < 99999) {
System.out.println("1)Display Balance");
System.out.println("2)Withdraw Cash");
System.out.println("3)Other services");
} else {
System.err
.println("Sorry,the pin you enterd was incorrect\nyour card is being ejected\nPlease wait...");
}
test=false;
break;
case 2:// Return Card
System.err.println("Your card is being ejected.\n Please Wait..");
test=false;
break;
default: // i want to display this message and send it back to case 1. when i do the method i'm doing it just keeps spamming this message.
System.err.println("Sorry your request could not be processed.Please re-try");
test=true;
}

If you want to send it back to case 1 then you need to set proceed to 1. I'm guessing that Next.nextInt() will give you 1, 2 but then 3 and then 4, etc. And anything over 2 will go to the default case

Related

How to store a return value in variable flutter

I need a little help.
I have this function in another file and i want to store the return value in a variable, because i dont want to repeat the same code again and again and I want to reuse it as many times I want.
here is the code in another file.
double dropDownIf(dropDownVal, finalVal, valParsed) {
if(dropDownVal == 'm'){
finalVal = valParsed;
} else if(dropDownVal == 'cm'){
finalVal = valParsed/100;
} else if(dropDownVal == 'mm'){
finalVal = valParsed/1000;
}
print('here is the updated value $finalVal');
return finalVal;
}
as you can see that it show the return value in debug console but it doesnt show the value in another page in which i am using this code.
here is the code on another page.
dropDownIf(dropDownValueL, finalLength, lengthParsed);
print(finalLength);
here in this page, the print function shows 0, I have declared the double finalLength = 0; in the beginning of the file. so the print shows 0 instead of the updated value.
the middle value in the dropDownIf function is the return value but it doesnt work.
You need to store the return value of the method in a variable, then use it:
double returnValue = dropDownIf(dropDownValueL, finalLength, lengthParsed);
print(returnValue);

AG-Grid: updateRowData({update: ItemsArray}) affecting all rows instead of selected rows

I'm using Ag-Grid and Angular for this project, and what I'm trying to do is set up shortcut keys to change the 'Status' value of selected rows by pressing associated keys('1'= 'status complete', etc.). There is a built in function called onCellKeyPress() that listens for keystrokes after a row, or rows, has been selected. That's working great, I have a switch case that sends off a value depending on which key is pressed like so:
onCellKeyPress = (e: any) => {
switch(e.event.key) {
case '0': this.rowUpdates('New'); break;
case '1': this.rowUpdates('Completed'); break;
case '2': this.rowUpdates('Needs Attention'); break;
case '3': this.rowUpdates('Rejected'); break;
}
}
It sends a string to my custom function rowUpdates(), that takes the value, goes though the existing Nodes, looks for any that are selected, sets the value on those selected, and pushes them to an array.
Now here's where the trouble starts. updateRowData takes 2 params, first is the type of updating it's doing(add, remove, update), in my case I'm using the latter, and an array of rows to change.
rowUpdates = (value: String) => {
let itemsToUpdate = [];
this.gridOptions.api.forEachNode(rowNode => {
if(rowNode.isSelected() === true) {
const selected = rowNode.data;
selected.status.name = value;
itemsToUpdate.push(selected);
console.log(itemsToUpdate);
}
});
this.gridOptions.api.updateRowData({update: itemsToUpdate});
}
However when I press a key to change the row value it updates every row in my grid. What's extra strange is that I have a method that adds a class to the row depending on the 'Status' value, and only the rows I intended to change receive that class.
I'm stumped. I've console.logged everything in this function and they all return with their intended values. The array always contains the nodes that have been selected and the return value of updateRowData is always that same array. I've tried switching out 'forEachNode' with getSelectedNodes and getSelectedRows to no avail. Any ideas?
Please try this.
updateItems(value: String) {
var itemsToUpdate = [];
this.gridApi.forEachNodeAfterFilterAndSort(function(rowNode, index) {
if (!rowNode.selected) {
return;
}
var data = rowNode.data;
data.status.name = value;
itemsToUpdate.push(data);
});
var res = this.gridApi.updateRowData({ update: itemsToUpdate });
this.gridApi.deselectAll();//optional
}

Protractor wait for all elements to have changed text

I want to wait till first element gets updated to rate same as monthlyRate variable and second element gets updated to rate same as annualRate.
With below code I get:
Failed: Wait timed out after 9008ms
public waitForSubscriptionRates = (rateselector: string, monthlyRate: string, annualRate: string) => {
browser.wait(function(){
element.all(by.css(rateselector)).filter(function(elem, index) {
return elem.getText().then(function(text) {
console.log('text=' + text);
console.log('monthlyRate=' + monthlyRate);
console.log('annualrate=' + annualRate);
return (text === monthlyRate || text === annualRate);
});
}).first().click();
},9000);
}
I'm not sure do I understand your code well.
I assume that there are two selectors - first may contain text of monthlyRate and second annualRate. They can not be mixed, isn't it?
I don't get what you want to click.
Anyway, you can chain ExpectedConditions with or keyword.
See the example in the documentation: http://www.protractortest.org/#/api?view=ProtractorExpectedConditions.prototype.or

jqgrid Error : Object does not support Property or Method 'Split'

I am using JQGrid v4.4.1 and MVC3.
When Selecting the 'Next Record' or 'Previous Record' icon on The JQGrid Edit Form, I get a Microsoft JScript runtime error: Object doesn't support property of method 'split'.
If highlights a block of code in the jquery.jqgrid.min.js module : var j=g.split(",")
Sometimes intellesense says that g=0, other times it's -2: I guess it's data related, but i cannot see anything that could be causing this!
I've tried to include a section of this module, including this call, but I'm struggling to make head nor tailof it!
Can anyone help me in determining the cause of this error?
jquery.jqGrid.min.js Extract
2*k+"'>"+t.rowcontent+"</td></tr>"),a(h).append(r),r[0].rp=u);0===m.length&&(m=a("<tr "+q+" rowpos='"+u+"'></tr>").addClass("FormData").attr("id","tr_"+f),a(m).append(p),a(h).append(m),m[0].rp=u);a("td:eq("+(y-2)+")",m[0]).html("undefined"===typeof t.label?e.p.colNames[o]:t.label);a("td:eq("+(y-1)+")",m[0]).append(t.elmprefix).append(l).append(t.elmsuffix);n[j]=o;j++}});if(0<j&&(o=a("<tr class='FormData' style='display:none'><td class='CaptionTD'></td><td colspan='"+(2*k-1)+"' class='DataTD'><input class='FormElement' id='id_g' type='text' name='"+
e.p.id+"_id' value='"+d+"'/></td></tr>"),o[0].rp=j+999,a(h).append(o),c[b.p.id].checkOnSubmit||c[b.p.id].checkOnUpdate))c[b.p.id]._savedData[e.p.id+"_id"]=d;return n}function r(d,e,h){var f,k=0,g,m,j,q,l;if(c[b.p.id].checkOnSubmit||c[b.p.id].checkOnUpdate)c[b.p.id]._savedData={},c[b.p.id]._savedData[e.p.id+"_id"]=d;var o=e.p.colModel;if("_empty"==d)a(o).each(function(){f=this.name;j=a.extend({},this.editoptions||{});if((m=a("#"+a.jgrid.jqID(f),"#"+h))&&m.length&&null!==m[0])if(q="",j.defaultValue?
(q=a.isFunction(j.defaultValue)?j.defaultValue.call(b):j.defaultValue,"checkbox"==m[0].type?(l=q.toLowerCase(),0>l.search(/(false|0|no|off|undefined)/i)&&""!==l?(m[0].checked=!0,m[0].defaultChecked=!0,m[0].value=q):(m[0].checked=!1,m[0].defaultChecked=!1)):m.val(q)):"checkbox"==m[0].type?(m[0].checked=!1,m[0].defaultChecked=!1,q=a(m).attr("offval")):m[0].type&&"select"==m[0].type.substr(0,6)?m[0].selectedIndex=0:m.val(q),!0===c[b.p.id].checkOnSubmit||c[b.p.id].checkOnUpdate)c[b.p.id]._savedData[f]=
q}),a("#id_g","#"+h).val(d);else{var n=a(e).jqGrid("getInd",d,!0);n&&(a('td[role="gridcell"]',n).each(function(m){f=o[m].name;if("cb"!==f&&"subgrid"!==f&&"rn"!==f&&!0===o[m].editable){if(f==e.p.ExpandColumn&&!0===e.p.treeGrid)g=a(this).text();else try{g=a.unformat.call(e,a(this),{rowId:d,colModel:o[m]},m)}catch(i){g="textarea"==o[m].edittype?a(this).text():a(this).html()}b.p.autoencode&&(g=a.jgrid.htmlDecode(g));if(!0===c[b.p.id].checkOnSubmit||c[b.p.id].checkOnUpdate)c[b.p.id]._savedData[f]=g;f=
a.jgrid.jqID(f);switch(o[m].edittype){case "password":case "text":case "button":case "image":case "textarea":if(" "==g||" "==g||1==g.length&&160==g.charCodeAt(0))g="";a("#"+f,"#"+h).val(g);break;case "select":var j=g.split(","),j=a.map(j,function(b){return a.trim(b)});a("#"+f+" option","#"+h).each(function(){this.selected=!o[m].editoptions.multiple&&(a.trim(g)==a.trim(a(this).text())||j[0]==a.trim(a(this).text())||j[0]==a.trim(a(this).val()))?!0:o[m].editoptions.multiple?-1<a.inArray(a.trim(a(this).text()),
j)||-1<a.inArray(a.trim(a(this).val()),j)?!0:!1:!1});break;case "checkbox":g+="";o[m].editoptions&&o[m].editoptions.value?o[m].editoptions.value.split(":")[0]==g?(a("#"+f,"#"+h)[b.p.useProp?"prop":"attr"]("checked",!0),a("#"+f,"#"+h)[b.p.useProp?"prop":"attr"]("defaultChecked",!0)):(a("#"+f,"#"+h)[b.p.useProp?"prop":"attr"]("checked",!1),a("#"+f,"#"+h)[b.p.useProp?"prop":"attr"]("defaultChecked",!1)):(g=g.toLowerCase(),0>g.search(/(false|0|no|off|undefined)/i)&&""!==g?(a("#"+f,"#"+h)[b.p.useProp?
"prop":"attr"]("checked",!0),a("#"+f,"#"+h)[b.p.useProp?"prop":"attr"]("defaultChecked",!0)):(a("#"+f,"#"+h)[b.p.useProp?"prop":"attr"]("checked",!1),a("#"+f,"#"+h)[b.p.useProp?"prop":"attr"]("defaultChecked",!1)));break;case "custom":try{if(o[m].editoptions&&a.isFunction(o[m].editoptions.custom_value))o[m].editoptions.custom_value.call(b,a("#"+f,"#"+h),"set",g);else throw"e1";}catch(q){"e1"==q?a.jgrid.info_dialog(jQuery.jgrid.errors.errcap,"function 'custom_value' "+a.jgrid.edit.msg.nodefined,jQuery.jgrid.edit.bClose):
a.jgrid.info_dialog(jQuery.jgrid.errors.errcap,q.message,jQuery.jgrid.edit.bClose)}}k++}}),0<k&&a("#id_g",i).val(d))}}function u(){a.each(b.p.colModel,function(a,b){b.editoptions&&!0===b.editoptions.NullIfEmpty&&k.hasOwnProperty(b.name)&&""===k[b.name]&&(k[b.name]="null")})}function t(){var e,f=[!0,"",""],m={},g=b.p.prmNames,j,o,l,n,v,p=a(b).triggerHandler("jqGridAddEditBeforeCheckValues",[a("#"+h),z]);p&&"object"===typeof p&&(k=p);a.isFunction(c[b.p.id].beforeCheckValues)&&(p=c[b.p.id].beforeCheckValues.call(b,
k,a("#"+h),"_empty"==k[b.p.id+"_id"]?g.addoper:g.editoper))&&"object"===typeof p&&(k=p);for(l in k)if(k.hasOwnProperty(l)&&(f=a.jgrid.checkValues.call(b,k[l],l,b),!1===f[0]))break;u();f[0]&&(m=a(b).triggerHandler("jqGridAddEditClickSubmit",[c[b.p.id],k,z]),void 0===m&&a.isFunction(c[b.p.id].onclickSubmit)&&(m=c[b.p.id].onclickSubmit.call(b,c[b.p.id],k)||{}),f=a(b).triggerHandler("jqGridAddEditBeforeSubmit",[k,a("#"+h),z]),void 0===f&&(f=[!0,"",""]),f[0]&&a.isFunction(c[b.p.id].beforeSubmit)&&(f=c[b.p.id].beforeSubmit.call(b,
k,a("#"+h))));if(f[0]&&!c[b.p.id].processing){c[b.p.id].processing=!0;a("#sData",i+"_2").addClass("ui-state-active");o=g.oper;j=g.id;k[o]="_empty"==a.trim(k[b.p.id+"_id"])?g.addoper:g.editoper;k[o]!=g.addoper?k[j]=k[b.p.id+"_id"]:void 0===k[j]&&(k[j]=k[b.p.id+"_id"]);delete k[b.p.id+"_id"];k=a.extend(k,c[b.p.id].editData,m);if(!0===b.p.treeGrid)for(v in k[o]==g.addoper&&(n=a(b).jqGrid("getGridParam","selrow"),k["adjacency"==b.p.treeGridModel?b.p.treeReader.parent_id_field:"parent_id"]=n),b.p.treeReader)b.p.treeReader.hasOwnProperty(v)&&
(m=b.p.treeReader[v],k.hasOwnProperty(m)&&!(k[o]==g.addoper&&"parent_id_
After Oleg pointed me in the right direction (thanks Oleg!). I have managed to resolve this Error.
Using The jquery.jqgrid.src.js (much more readable) I managed to take an educated guess that the problem lay on a column in my Grid that was using a FORMATTER. I then noticed that even when loading the Edit form - the value for this column was not correct - and bacause The edittype was 'select', it was defaulting to the first item in the value list.
The Formatter would take the Value of the column (which could be either a -2, 0 or 1 in this case) and turn it into a gif for display purposes in the column. that worked lovely.
The UnFormatter, however, attempted to turn the image back into it's respective number (based on its title). I was then returning a numeric value ( ie. -2, 0 or 1). I needed to return a string value. (ie. '-2','0' or '1')
So, it seems that for Unformatters, you cannot return numeric values like this.
I have added the working code below for clarity :)
Working formatters
function EnabledFormatter(cellvalue, options, rowObject) {
var cellValueInt = parseInt(cellvalue);
switch (cellValueInt)
{
case 1:
return "<img src='#Url.Content("~/Content/images/tick.gif")' title='Enabled' />";
break;
case -2:
return "<img src='#Url.Content("~/Content/images/tick-grey.png")' title='Inherited' />";
break;
default:
return "<img src='#Url.Content("~/Content/images/cross.gif")' title='Disabled' />";
break;
};
};
function EnabledUnformatter (cellvalue, options, cell) {
var sTitle = $('img', cell).attr('title');
switch (sTitle)
{
case 'Enabled':
return '1';
break;
case 'Inherited':
return '-2';
break;
default:
return '0';
break;
};
};
Broken Unformatter Please note The lack of '' around the values returned. The EnabledFormatter is Unchanged
function EnabledUnformatter (cellvalue, options, cell) {
var sTitle = $('img', cell).attr('title');
switch (sTitle)
{
case 'Enabled':
return 1;
break;
case 'Inherited':
return -2;
break;
default:
return 0;
break;
};
};

Filter getElementsByTagName list by option values

I'm using getElementsByTagName to return all the select lists on a page - is it possible to then filter these based upon an option value, ie of the first or second item in the list?
The reason is that for reasons I won't go into here there are a block of select lists with number values (1,2,3,4,5 etc) and others which have text values (Blue and Black, Red and Black etc) and I only want the scripting I have to run on the ones with numerical values. I can't add a class to them which would more easily let me do this however I can be certain that the first option value in the list will be "1".
Therefore is there a way to filter the returned list of selects on the page by only those whose first option value is "1"?
I am pretty sure that there is a better solution, but for the moment you can try something like:
var allSelect = document.getElementsByTagName("select");
var result = filterBy(allSelect, 0/*0 == The first option*/, "1"/* 1 == the value of the first option*/);
function filterBy(allSelect, index, theValue) {
var result = [];
for (var i = 0; i < allSelect.length; i++) {
if(allSelect[i].options[index].value == theValue ) {
result.push(allSelect[i]);
}
}
return result;
}
I managed to get this working by wrapping a simple IF statement around the action to be performed (in this case, disabling options) as follows:
inputs = document.getElementsByTagName('select');
for (i = 0; i < inputs.length; i++) {
if (inputs[i].options[1].text == 1) {
// perform action required
}
}
No doubt there is a slicker or more economic way to do this but the main thing is it works for me.