Hi my code as fallows what is wrong with it?
thank you and sorry for my bad english.
protected function belgelerDG_itemClickHandler(event:ListEvent):void
{
var durum:Boolean = false;
if(belgeicerikWindow==null){
belgeicerikWindow=new belgeicerik();
belgeicerikWindow.title=belgelerDG.selectedItem.belge;
belgeicerikWindow.open();
}
else{
durum=false;
for ( var i:int = NativeApplication.nativeApplication.openedWindows.length - 1; i >= 0; --i ) {
if(NativeApplication.nativeApplication.openedWindows[i].title.toString() == belgeicerikWindow.title=belgelerDG.selectedItem.belge){
belgeicerikWindow.orderToFront();
durum=true;
}
}
if(durum==false){
belgeicerikWindow=new belgeicerik();
belgeicerikWindow.title=belgelerDG.selectedItem.belge;
belgeicerikWindow.open();
}
}
}
I'm betting the problem lies with the if statement that starts with:
if(NativeApplication.nativeApplication.openedWindows[i].title.toString()
You are doing an assignment within the value you are trying to compare against:
== belgeicerikWindow.title=belgelerDG.selectedItem.belge)
If it isn't what is causing your problem, at least it is something you should fix to make things more legible. :)
Related
ternary make code concise and readable, I'm curious about how to change the following if condition to ternary operator:
var1 = if(true){'a'};
I try the following
var1 = true? 'a': ;
since it require nothing to do with false condition, I leave blank after :, but apparently it gives me a error.
Is there a way to do this?
--------update---------
The intention of using the above example is that I want to simplify the problem, however it made everyone more confuse, so I post my original code:
if($_SERVER['REQUEST_METHOD'] == 'GET'){ $sub_count = 0; }
$sub_count = $_SERVER['REQUEST_METHOD'] == 'GET'? 0 : ;
how to change the if condition to ternary ?
$sub_count = null;
$sub_count = $_SERVER['REQUEST_METHOD'] == 'GET'? 0 : null;
// To check:
if(!isset($sub_count))
{
// Do something because $_SERVER['REQUEST_METHOD'] != 'GET'
} else {
if($sub_count===0)
{
// REQUEST METHOD IS GET
}
}
How can I break out of an if statement?
Exit only works for "for", "sub", etc.
In VB.net:
if i > 0 then
do stuff here!
end if
In C#:
if (i > 0)
{
do stuff here!
}
You can't 'break out' of an if statement. If you are attempting this, your logic is wrong and you are approaching it from the wrong angle.
An example of what you are trying to achieve would help clarify, but I suspect you are structuring it incorrectly.
There isn't such an equivalent but you should't really need to with an If statement. You might want to look into using Select Case (VB) or Switch (C#) statements.
In C# .NET:
if (x > y)
{
if (x > z)
{
return;
}
Console.Writeline("cool");
}
Or you could use the goto statement.
You can use
bool result = false;
if (i < 10)
{
if (i == 7)
{
result = true;
break;
}
}
return result;
I have to admit, that in some cases you really wanna have something like an exit sub or a break. On a rare occasion is I use "Goto End" and jump over the "End If" with the def. End:
I know this is an old post but I have been looking for the same answer then eventually I figured it out
try{
if (i > 0) // the outer if condition
{
Console.WriteLine("Will work everytime");
if (i == 10)//inner if condition.when its true it will break out of the outer if condition
{
throw new Exception();
}
Console.WriteLine("Will only work when the inner if is not true");
}
}
catch (Exception ex)
{
// you can add something if you want
}
`
how can I fix this error ?
Target of assignment must be a reference value
for (var z:int=0; z<this.tags.getItemAt(i).yearPopularity.length; z++) {
summedPopularity.getItemAt(z) = summedPopularity.getItemAt(z) + tags.getItemAt(i).yearPopularity.getItemAt(z);
}
thanks
I'm not sure you can assign to the value returned by getItemAt()
try:
for (var z:int=0; z<this.tags.getItemAt(i).yearPopularity.length; z++) {
var tempItem:Object = summedPopularity.getItemAt(z) + tags.getItemAt(i).yearPopularity.getItemAt(z);
summedPopularity.setItemAt(tempItem, z);
}
This error means your trying to give a value (or a read only object) a value.
If summedPopularity.getItemAt(z) is the only thing accepting anything,try changing that to a var
var someVariable:Number =0;
for (var z:int=0; z<this.tags.getItemAt(i).yearPopularity.length; z++) {
someVariable = summedPopularity.getItemAt(z) + tags.getItemAt(i).yearPopularity.getItemAt(z);
}
I think this would work fine,
thus denoting summedPopularity.getItemAt(z) is an object type.
trace(summedPopularity.getItemAt(z)); //<<< Debug stop and inspect
Try that, aside from that, you'll have to give us more code and show us what summedPopularity is.
Hope it helps.
I've solved with summedPopularity[i] instead of summedPopularity.getItemAt(i)
I am porting over some Java code into Google's Go language and I converting all code except I am stuck on just one part after an amazingly smooth port. My Go code looks like this and the section I am talking about is commented out:
func main() {
var puzzleHistory * vector.Vector;
puzzleHistory = vector.New(0);
var puzzle PegPuzzle;
puzzle.InitPegPuzzle(3,2);
puzzleHistory.Push(puzzle);
var copyPuzzle PegPuzzle;
var currentPuzzle PegPuzzle;
currentPuzzle = puzzleHistory.At(0).(PegPuzzle);
isDone := false;
for !isDone {
currentPuzzle = puzzleHistory.At(0).(PegPuzzle);
currentPuzzle.findAllValidMoves();
for i := 0; i < currentPuzzle.validMoves.Len(); i++ {
copyPuzzle.NewPegPuzzle(currentPuzzle.holes, currentPuzzle.movesAlreadyDone);
copyPuzzle.doMove(currentPuzzle.validMoves.At(i).(Move));
// There is no function in Go's Vector that will remove an element like Java's Vector
//puzzleHistory.removeElement(currentPuzzle);
copyPuzzle.findAllValidMoves();
if copyPuzzle.validMoves.Len() != 0 {
puzzleHistory.Push(copyPuzzle);
}
if copyPuzzle.isSolutionPuzzle() {
fmt.Printf("Puzzle Solved");
copyPuzzle.show();
isDone = true;
}
}
}
}
If there is no version available, which I believe there isn't ... does anyone know how I would go about implementing such a thing on my own?
How about Vector.Delete( i ) ?
Right now Go doesn't support generic equality operators. So you'll have to write something that iterates over the vector and removes the correct one.
Is it possible to sort an XMLList? All the examples I can find on it create a new XMLListCollection like this:
MyXMLListCol = new XMLListCollection(MyXMLList);
I don't think the XMLListCollection in this case has any reference to the XMLList so sorting it would leave my XMLList unsorted, is this correct?
How can I sort the XMLList directly?
Thanks
~Mike
So I finally got my search terms altered enough I actually churned up an answer to this.
Using the technique I got from here:
http://freerpad.blogspot.com/2007/07/more-hierarchical-sorting-e4x-xml-for.html
I was able to come up with this:
public function sortXMLListByAttribute(parentNode:XML,xList:XMLList,attr:String):void{
//attr values must be ints
var xListItems:int = xList.length();
if(xListItems !=0){
var sortingArray:Array = new Array();
var sortAttr:Number = new Number();
for each (var item:XML in xList){
sortAttr = Number(item.attribute(attr));
if(sortingArray.indexOf(sortAttr)==-1){
sortingArray.push(sortAttr);
}
//piggy back the removal, just have to remove all of one localName without touching items of other localNames
delete parentNode.child(item.localName())[0];
}
if( sortingArray.length > 1 ) {
sortingArray.sort(Array.NUMERIC);
}
var sortedList:XMLList = new XMLList();
for each(var sortedAttr:Number in sortingArray){
for each (var item2:XML in xList){
var tempVar:Number = Number(item2.attribute(attr));
if(tempVar == sortedAttr){
sortedList += item2
}
}
}
for each(var item3:XML in sortedList){
parentNode.appendChild(item3);
}
}
}
Works pretty fast and keeps my original XML variable updated. I know I may be reinventing the wheel just to not use an XMLListCollection, but I think the ability to sort XML and XMLLists can be pretty important
While there is no native equivalent to the Array.sortOn function, it is trivial enough to implement your own sorting algorithm:
// Bubble sort.
// always initialize variables -- it save memory.
var ordered:Boolean = false;
var l:int = xmlList.length();
var i:int = 0;
var curr:XML = null;
var plus:XML = null;
while( !ordered )
{
// Assume that the order is correct
ordered = true;
for( i = 0; i < l; i++ )
{
curr = xmlList[ i ];
plus = xmlList[ i + 1 ];
// If the order is incorrect, swap and set ordered to false.
if( Number( curr.#order ) < Number( plus.#order ) )
{
xmlList[ i ] = plus;
xmlList[ i + 1 ] = curr;
ordered = false;
}
}
}
but, realistically, it is far easier and less buggy to use XMLListCollection. Further, if someone else is reading your code, they will find it easier to understand. Please do yourself a favor and avoid re-inventing the wheel on this.