Topic: x=x+1

in my script i have a statement to get a value from the record, add 1 to it and save it back each time a team plays (line 4). when i run the program the first time and pick the team 'holy cow',  i get the value 1. when i run the program the second time and pick the team 'holy cow', i get the value 2. when i run the program every time after that and pick the team 'holy cow',i get the same value of 2. since the same team can play up to 20 - 25 times it should add 1 up to 20 - 25 times. can anyone fix this or help me fix it.

Post's attachments

Attachment icon My Sample 4.zip 19.81 kb, 412 downloads since 2016-06-15 

Re: x=x+1

Hello Lee,
Sorry not to have been able to help out recently - I've been away.
Looks like your project is really starting to take shape.
With this specific problem you're asking about, I think you need to amend line 4 of your script to read;
form1.edit22.Value := sqlexecute('select IFNULL(max(wksplayed), 0) from matches where id_teams = ' + Form1.ComboBox1.sqlValue) + 1;

As it stands, when no record exists, the wksplayed value is set to 1 and the first record is created.
When 1 record exists, it uses the wksplayed value of the first record (ie 1), adds 1 and creates a second record with a wksplayed value of 2.
When 2 records exist, it still uses the wksplayed value of the first record (ie 1), adds 1 and creates a third record BUT with a wksplayed value of 2.
When 3 records exist, it still uses the wksplayed value of the first record (ie 1), adds 1 and creates a fourth record BUT with a wksplayed value of 2.
And so on and so on - it will NEVER go above a wksplayed value of 2

This is where the 'max' instruction in the script comes into play;  using 'max' in the script forces it to read the last record and then add 1.  This should then start incrementing the week numbers correctly.
I trust that makes sense and hope it helps,
Derek.

Re: x=x+1

Hello Again Lee,
I forgot to mention in my response that I think you'll also need to amend the relationship you've created in line 4 of your script. because when you add more seasons to the data, your script, as it stands, won't know which season to use to add the wksplayed to. 
I'd suggest something like this:
form1.edit22.Value:= sqlexecute('select IFNULL(max(wksplayed), 0) from matches where (id_seasons = ' + form1.combobox5.sqlvalue + ') and id_teams = ' + Form1.ComboBox1.sqlValue) + 1;
Hope that makes sense.
Derek.

Re: x=x+1

hello Derek

Thank you. You saved me and my project. i was tired of asking for help and not getting what i needed so this was my last try before scraping the whole thing and moving on to some of my more enjoyable hobbies.

i must be learning something in sql as i actually do understand what you were saying ;-)  it works great and i hope i keeps me going for awhile. please dont go too far away though;-)

again, thank you for your help

lee

Re: x=x+1

No problem Lee - just glad to be able to give something back after all the help that I'v'e received from various members (yes, you know who you are - LOL!!).
Bit worrying though that you understand my SQL - not sure I do myself half the time!
Derek.

Re: x=x+1

Hi Derek

is there anything around about using sql in the script/forms environment used by mvd? i read/watch as much as my ancient mind will take but find nothing about the way we use it. i get the commands to work in sqlite browser and sqlite studio but not it a script. then i start grasping at every permutation of what might or might not look like a command. by the time i get on here people wonder what in the  world i was thinking.. then when i get the solution its nothing like the original command that worked.

lee

Re: x=x+1

Hello Lee,
My understanding (may be wrong) is that the scripting language only supports a sub-set of functions and that the syntax for those functions is often specific to MVD, which is why finding 'answers' on Google or in SQLITE studio etc confuses rather than helps. 
For that reason, for me the best way of finding out how to do something in MVD is simply by using the SEARCH function within the forum itself - it can be a bit tedious reading all the relevant (and not so relevant) posts but at the same time, it's surprising what else you come across that you might use later on, so it's never wholly wasted.
Derek.