Possible if bug. pls help!

97 views
Skip to first unread message

JFK422

unread,
May 1, 2015, 2:40:17 PM5/1/15
to androi...@googlegroups.com
Hi guys on the forum of DroidScript

I'm workin' on a app which could calculate school grades and i'm stuck in this problem. I think it cold might be a bug.
I have tested all the stuff in the database. There's everything expected.

//function called after startin the app to process the grades


function processMark(results)
{
    var s = 0; //The grade variable
    var nte = 0; //How much it counts
    var len = results.rows.length; //Lenght of the database
    var txt = ""; //Troubleshoot stuff
    for(var i = 0; i < len; i++ )
    {
        var item = results.rows.item(i); //Loading stuff out of the database
        ttt.SetText( item.data_Bol ); //It doesn't work if I put "item.data_Bol" directly in the if statment (bug I think) so I put it in some invisible text and get it from there.
        txt+=item.data_Bol; //Troubleshoot stuff
        txt+=" "; //Troubleshoot stuff
        if( ttt.GetText() ){ //If does always turn true or false never mixed->(what I want it to do!!)
            s += item.data_Val*=item.data_Num; //Calculation stuff
            nte += item.data_Num; //Calculation stuff
        }
    }
    app.ShowPopup( txt ); //Troubleshoot stuff
    s /= nte; //Calculation again
    mark.SetText( Math.round( s*2 )/2 ); //Set some text to the calculated stuff
}

//And here's the database
db = app.OpenDatabase( "Note" );    
   db.ExecuteSql( "CREATE TABLE IF NOT EXISTS noten " +   
        "(id integer primary key, data text, data_Name text, data_Val integer, data_Num integer, data_Fach text, data_Bol bolean)" );

Thanks for help already. PS: SorryForBadEnglish

Christoph Stehl

unread,
May 3, 2015, 4:55:53 PM5/3/15
to androi...@googlegroups.com
Probably this is the Problem:
var item = results.rows.item(i);

I think it must be this Code:

var item = results.rows.item[i];

JFK422

unread,
May 7, 2015, 6:54:53 AM5/7/15
to androi...@googlegroups.com
I have tested it and it doesn't work.
Also its the same line from the sample that I use.

Chris Hopkin

unread,
May 7, 2015, 1:21:45 PM5/7/15
to androi...@googlegroups.com
Hi JFK422

The problem with if( item.data_Bol ) is due to data_Bol being returned as the string "true" or "false" in the results, rather than a true or false boolean value.

As I understand it, Sqlite treats booleans as integers (0 for false, 1 for true), so really instead of inserting true or false into the database, you should really use 1 or 0 instead. You can read more about data types in Sqlite here https://www.sqlite.org/datatype3.html

In your CREATE TABLE sql, you currently have 'bolean' where you meant 'boolean'. You could use 'integer' as the data type instead, but I think you can still use 'boolean', it will just be interpreted as a numerical type.

P.S. results.rows.item(i) is correct - item is a function not an array.

Thanks

Chris

JFK422

unread,
May 12, 2015, 2:57:26 PM5/12/15
to androi...@googlegroups.com
Hi Chris and the other guys on the forum

I have messed around with it for about an hour now. But i still didnt made any progress.
I have changed the database thingy with item.data_Bol to 1 & 0 like you said. But now it doesn't calculate anythig. So I tested it with the system I had at first, an I had some sucsess.

function executeMark(results)
{
    var s = 0;
    var nte = 0;
    var len = results.rows.length;
    var mark = "";
    var count = "";
    for(var i = 0; i < len; i++ )
    {
        var item = results.rows.item(i);
        gwt.SetText( item.data_Bol );
        
        mark = item.data_Val;
        count = item.data_Num;
        
        
        if( gwt.GetText()=="true" ){                      //This works now but if I change it its VERY buggy.
            if( !mark=="null" && count=="null" ){   //I have some diffrent touble cause this if is now not working!
                    s += mark*=count;                    //I think it doen't calculate beacuse it hase some null stuff in it but now it doesnt work
                    nte += count;
                    app.ShowPopup( "LOLP" );        //Doesn't show up
            }
            else app.ShowPopup( "Hello" );         //Always pops up
        }
    }
    s /= nte;
    mark.SetText( Math.round( s*2 )/2 );
}

Also I have tested again the contents in the database. Everything is THERE what I want.

And the database again: db = app.OpenDatabase( "Note" );    
                                    db.ExecuteSql( "CREATE TABLE IF NOT EXISTS noten " + "(id integer primary key, data text, data_Name text, data_Val integer, data_Num integer, data_Fach text, data_Bol boolean)" );

I have also attatched the .js file form my project if that helps. ( Sorry if you find some uncomfortable language, I had sometimes a lot of rage attacks while coding! )
Hope anyone understands german.

Thanks for help JFK422

Pluspoints.js

Chris Hopkin

unread,
May 14, 2015, 4:21:05 AM5/14/15
to androi...@googlegroups.com
Hi

The Pluspoint.js script is incomplete, it is ends halfway through the executeMark function. Can you post an SPK instead (long press on your App and choose 'Share via Email').

Thanks

Chris
Reply all
Reply to author
Forward
0 new messages