Topic: HELP needed to configure Button for "IF THEN & WHILE" actions

Hi guys,

I'm a newbie to MVD and its coding Script language
(more of a MSaccess admin builder).

.... therefore I do need to know how to code a process to filter Tables records, using :
- IF THEN
- WHILE
and similar operations...

I'm not sure the language used in MVD is Pascal, and I would greatly apreciate more info/ links in order
to writte the correct syntax that MVD does use to process such operations on a Button "key released" action.

I want my Button action to select/filter records from a Table and Copy them to another Table, based on various criterias.

Thanks a lot for pointing me to some good (TESTED) samples or Scripts if you know or have some related to the IF() use.
(I have downloaded the available few samples from MVD page but nothing related to that part)

Looking for your answers guys/girls !
Hasta la Vista smile

Rien ne sert de courir, mieux vaut savoir dans quelle direction aller,, smile

Re: HELP needed to configure Button for "IF THEN & WHILE" actions

Hello bibif,

We've all been "newbies" at one time or another here, so you are more than welcome to ask. :-)


The "script" used in MVD is Object Oriented Pascal, also known as Delphi. It's a rather old but still beeing improved, structured and strongly typed programming language, fun to use and easy to learn, and powerful as well.


The way you are going to set your buttons depends greatly on the way you use MVD : some here make a challenge of using as little scripting as possible (like Tcoton) and others, like me, use as much script as they can because they love it (or because I'm mad). Some others use script only when they can not perform exactly what they want with the embedded functions in MVD that Dmitry regularly improves.


In order to help you, I have a few questions :
When you say copy/ filter from a table to another, do you mean tables as in database table or do you mean Tablegrid as they are displayed on forms ?
Is it just a matter of displaying filtered information or is it a matter of saving it in a database table ?


As for the key release action, I usually use the on after click option. The button once clicked performs an action (manually scripted or MVD handeled) and AFTER that action is completed, performs another one. That could be what you ar looking for if you want to filter/search data then move/display part of it somewhere else.


The if/then is typically a logical testing structure that is used in Delphi and the while (or for x:=0 to y do) is a loop command that can be used to repeat operations until a certain state is reached.


There are plenty of good sites out there to explain how to use them, like http://www.delphibasics.co.uk/RTL.asp?Name=While and many others.

You're Access background should be profitable when it comes to structuring your database and writing SQL queries (in which you can include variables easily).


I realize I did not quite answer your question, but I hope I gave you a few clues on directions to look at.


Do not hesitate to include your project with your post (delete the exe file from the zipped project before uploading to the forum, we can all recompile it) with your specific question and I'm sure someone will have a look at it. I will.


Cheers


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: HELP needed to configure Button for "IF THEN & WHILE" actions

OK, I had some free time, so I made you a small demo application.


Compile it with beta version 2.7 and you'll see 3 examples, based on the same database that I provide. The data consists of a list of URL and the date they were added to the database.


With that material :

  • Form1 display the data automatically in the tablegrid (no script, just MVD doing it's job), and a script parses the rows to calculate the age of the data and colorize the rows depending on the age.

  • Form2 uses the same date, but a button copies part of the data from tablegrid1that is automatically field by MVD, to Tablegrid2 by script, based on the age of the data. The conditions are hard coded.

  • Form3 does like Form2, but the conditions are chosen by the user, and the query is made by script accordingly.


I tried to comment the code as much as I could to explain what was going on in the script. (comment appears in blue).

You'll find examples of

  • loops with "for ---> do"

  • conditions with "if / then / else"

  • manual filling of Tablegrid with scripted queries

  • and various use of variables


Look at the way they are declared before being used, pay attention to the structure of the if then else that I intentionally over detailed. I also embedded "if / else" in "if / else" to show you how to nest conditional structures.


have fun and do not hesitate to ask questions if you have.

Cheers


Mathias

Post's attachments

Attachment icon LINKS.zip 341.02 kb, 569 downloads since 2016-08-20 

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

4 (edited by bibif 2016-08-20 17:49:13)

Re: HELP needed to configure Button for "IF THEN & WHILE" actions

Hi Matt,
Thks for your reply and the Zip file.

Form No 3 of your smple is pretty much what I intend to do between 2 tables so I'm glad you sent this sample.

My requirement is going to be a lil more heavy to code but It seems MVD has what it takes to do that.

I'm going to go through your sample scripts to see how far I get it.


But before all i have one more question....
assuming I am using several columns in TableGrid 1 and severals in TG 2
Does MVD allows to copy content/value from a certain column of TG1 and paste into the smilar column from TG2 ?
(instead of copying a full record line)


The reason I am asking is as follow...

Use a script to Auto-assign NAMES of TWO "volunteers" to a target schedule based on their favorite Day/Time (Real Availability)

GRID1 (Availability can use Boolean type)
NAME:     MON-8     MON-10   MON-12      HrAccount 
Matt          ok                ok             .                              2
Tim           .                   ok             .                              4
Tom           .                   ok                  ok                     6
Jim            .                    .                    ok                     2
 
NAME:     TUES-8     TUES-10   TUES-12    HrAccount     
Matt          ok                ok             .                               6
Jane        ok  .              ok             .                               2
Mike           .                                        ok                       2
Jim            .                   ok .                ok                       4 


cliking BUTTON: Action  "ASSIGN PEOPLE NOW"

Would process records in order to fullfiling Grid2 repeateadly for 14 days (Using 2 Vol/each days).
[Loop twice for 14 times on distinct day lines]

RESULT:

GRID2 - AutoCalculated Assignments.(or Printable Layout sample)
                   
DATES                           8 to 10         10-12         12-2Pm                (Column titles)
--------------------------------------------------------------------------
22-8-2016      Vol.A       Matt              Matt              Tom              (Detail for each day)
  Monday        Vol.B    (no one)         Tim               Jim
-------------------------------------------------------------------------
23-8-2016      Vol.A      Jane             Jane             Jim
  Tuesday        Vol.B      Matt              Jim               Mike
-------------------------------------------------------------------------
ETC...

When two people are available at the same day/time,
The script first search for the one with the smallest HRAccount. (amount of participation hours)
It is no big deal if some ppl HRAccount ends getting much higher than others during a period of time...

Assigning a Name to a Period of time also increment by 2 hours his HRAccount TOTAL before processing the following day...


For the Above case, I would need to VERIFY ASAP... if MVD offers features to allow a script to fullfill (copy/paste) dif. Value on the same line one by one before processing the next day (line) of the Schedulte Grid.

(.... since copying a full line from Grid A to GridB would not be apropriate) 

Do you have any idea if column by column value copying is possible, within the same line ?
THANKS !!!
smile
Have a Nice Week End ! smile

Rien ne sert de courir, mieux vaut savoir dans quelle direction aller,, smile