Help on Procedure

Je ne suis pas un jeune développeur (76 ans) mais j’ai commencé il y a 50 ans comme programmeur; et depuis une vingtaine d’année j’ai arrêté, mais j’ai les bases!
Je m’intéresse à APP Inventor que je trouve génial et je me pose la question suivante.
Je fais un petit développement et j’ai fait 20 fois la même chose alors que je pense qu’avec une procédure je pourrais l’appeler 20 fois en ne passant qu’un paramètre, le numéro; ce que j’ai dans chaque bloc en fonction de ce numéro : test et set flag, set de couleur.
Comment faire ?
Merci et bonne journée

I am not a young developer (76 years old) but I started 50 years ago as a programmer; and for twenty years I stopped, but I have the basics!
I am interested in APP Inventor which I find awesome and I ask myself the following question.
I am doing a small development and I have done the same thing 20 times when I think that with a procedure I could call it 20 times by passing only one parameter, the number; what I have in each block according to this number: test and set flag, set of color.
How to do ?
Thank you and have a nice day

2 Likes

Welcome to the community.

Can you show the blocks you have made?

Thanks for your help; here is a link:
https://pjjoint.malekal.com/files.php?id=20200401_j13k69s10h7
nany thanks

Could you please post the image of your blocks here and not on another site. You can upload the blocks. image

image

How to create and use a Procedure is discussed in Chapter 21. Defining Procedures

You might find that article useful.

You could use the any component block. This gives an example.

http://ai2.appinventor.mit.edu/reference/other/any-component-blocks.html

Thanks. I stay with my 20 blocks!

you are correct, don't repeat yourself...

more about the advanced blocks see here

How to work with the advanced features

A Multiple Choice Quiz: How to work with the advanced features

let me recommend you to use procedures and the advanced blocks...
to simplify at least a little bit, you could replace the if statement like this
Unbenannt

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.

1 Like

Here is a sample project to show the power of generic component events and lists of components …

Peter,
Could you give an example?
or a link to?
Yhanks

I would not to insist but always trying to solve a loop! “DRY” or “component block”


Here is what I have (left) and what I guess I should have (right)
Unfortunately I donot know how to fill the “FAIRE” !!!
Any help is welcomed!
Merci pour tout

what about storing the values of your flags (true or false) in a list rather than using 21 global variables?
see also


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.

ThanksTaifun,
is there an example somewhere to show how works “lists”?
Bonne journée/Have a nice day

it does not look like you followed the links I provided earlier?
see also Displaying a List and Making Lists (App Inventor 2)

Taifun

Here is an easy starter example for you …

Les listes sont déclarées comme vouls l’avez fait pour une variable normale en l’initialisant par une constante EmptyList (prise dans les objets lists sur la gauche) c’est le même principe que les tableaux sous C ou Pascal sauf que l’indice sur App Inventor commence à 1 pas à zero.
Il y dans le bloc lists à gauche un tas de fonctions pour ajouter, retirer ou chercher un élément dans la liste déclarée. L’aide en ligne est très exhaustive et très bien faite, faut pas être pressé par contre.