4 messages in org.openoffice.fr.progRe: [prog] Fonctions perso et paramèt...
FromSent OnAttachments
christianwtdOct 30, 2006 12:21 pm 
Lionel CorgnetOct 30, 2006 12:36 pm 
christianwtdOct 30, 2006 12:56 pm 
Laurent GodardOct 30, 2006 11:55 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [prog] Fonctions perso et paramètre optionnelActions...
From:Lionel Corgnet (lio@velocampus.net)
Date:Oct 30, 2006 12:36:12 pm
List:org.openoffice.fr.prog

christianwtd a écrit :

Je cherche à faire une fonction perso dans Calc et je bute sur les paramètres optionnels. Pour faire simple, un exemple... simple :

Function Bidon(Param1, Param2) Bidon = Param1 + Param2 End Function

peut-être, d'après ce que j'ai pu lire : (mais non testé)

Function Bidon (Param1, Optional Param2) Dim Resultat as Variant If IsMissing(Param2) Then Resultat = Param1 Else Resultat = Param1 + Param2 End If Bidon = Resultat End Function

Dans Calc, je fais : =BIDON(10; 20) et j'ai en retour 30. OK, ça marche. Mais si je souhaite le 2ème paramètre en option et que j'entre : =BIDON(10) J'ai droit à une erreur : Runtime error BASIC. L'argument n'est pas facultatif. Donc je me dis que je vais tester avec : IsMissing(Param2) Ca ne marche pas. Même erreur.

Donc je vais tester avec : On Error Goto TraiteErreurs et je fais faire :

Function Bidon(Param1, Param2) On Error Goto TraiteErreurs Bidon = Param1 + Param2 Exit Function ' TraiteErreurs: Resume Next Return End Function

Cette fois ci plus d'affichage de résultat. Je teste donc :

Function Bidon(Param1, Param2) On Error Goto TraiteErreurs Bidon = Param1 + Param2 Exit Function ' TraiteErreurs: Param2 = 0 Resume Next Return End Function

Encore une déconvenue. La fonction s'arrête à Param2=0 et donc pas de résultat.

Je tourne en rond. Je pense que j'ai raté quelque chose, mais avant de commencer à taper méchamment sur le clavier, peut-être avez-vous la solution.

le "Optional" devant Param2 ?

D'avance merci,

Bon surf, Christian

Lionel, débutant en macros.