

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
6 messages in org.openoffice.fr.progRE: [prog] Première fonction| From | Sent On | Attachments |
|---|---|---|
| Jean Sympa | Dec 22, 2006 4:48 am | |
| emma...@fr.thalesgroup.com | Dec 22, 2006 4:58 am | |
| Laurent Godard | Dec 22, 2006 5:06 am | |
| Paul Veuve | Dec 22, 2006 5:21 am | |
| Laurent Godard | Dec 22, 2006 5:47 am | |
| Bernard Marcelly | Dec 22, 2006 11:27 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | RE: [prog] Première fonction | Actions... |
|---|---|---|
| From: | Paul Veuve (ve...@cdisa.ch) | |
| Date: | Dec 22, 2006 5:21:25 am | |
| List: | org.openoffice.fr.prog | |
Voici un exemple de fonction:
Function MultipliePar2 (val as variant) as variant MultipliePar2 = val * 2 End Function
Elle se définit par Function et le retour du résultat se fait affectation a une variable qui porte le nom de la fonction.
------------------------------ Paul Veuve ve...@cdisa.ch
------------------------------ CDI CONSEILS ET DEVELOPPEMENTS INDUSTRIELS SA Chemin de la Justice 15 CH-2000 NEUCHATEL
------------------------------ http://www.cdisa.ch
Phone (+41 32) 733 31 31 or (+41 78) 600 31 31
Fax (+41 32) 733 31 32
------------------------------
-----Message d'origine----- De : Jean Sympa [mailto:jsy...@free.fr] Envoyé : vendredi, 22. décembre 2006 13:49 À : prog Objet : [prog] Première fonction
Bonjour à toutes et à tous,
Première fonction
Je sais que mon exemple et celui d'un débutant: C'est en forgeant que l'on devient forgeron
Objectif : Créer une fonction en partant d'une macro mise au point.
//---- Macro ayant servi de point de départ
-------------------------------------------
Cette macro remplace une seule sous chaîne de caractère par un caractère. Je la transforme en une fonction pour pouvoir remplacer non pas une Sous Chaîne mais autant de Sous chaîne qu'il est nécessaire.
Option Explicit
Sub RemplacerSChParCar()
Dim monDocument as Object
Dim jeCherche As Object, trouv As Variant
Dim x As Long
monDocument=ThisComponent
jeCherche=monDocument.createSearchDescriptor
with jeCherche
.SearchString= "=E8"
.SearchWords=false
end with
trouv=monDocument.findAll(jeCherche)
print "Nombre d'occurences: " & cstr(trouv.count)
for x=0 to trouv.count-1
trouv(x).CharBackColor=1234567 'Fond vert sombre
next
End Sub
Les changements de chaîne ont lieu dans des documents de ce type :
Le père parle à son fiston de 5 ans=20
- Tu dois manger tous les épinards si tu veux devenir fort comme papa.=20 - Non. Je ne veux pas être fort comme toi. Je veux être boss comme maman= =20 ****
La ma=EEtresse d'école...=20 - Popaul, douze bouteilles de vin à 20$ chacune, combien =E7a fait?=20 - =C0 la maison, si c'est pour mon papa, Guy-Marie, =E7a fait 3 jours,=20 mademoiselle.=20
Rem ---------------------------------------------------------------
Fonction créée
Option Explicit
Function Remplacer1SChPar1Car(Sch As String, Car As String)
Dim monDocument as Object
Dim jeCherche As Object, trouv As Variant
Dim x As Long
monDocument=ThisComponent
jeCherche=monDocument.createSearchDescriptor
with jeCherche
.SearchString= Sch
.SearchWords=false
end with
trouv=monDocument.findAll(jeCherche)
'print "Nombre d'occurences: " & cstr(trouv.count)
for x=0 to trouv.count-1
trouv(x).CharBackColor=1234567 'Fond vert sombre
trouv(x).String=Car
next
End Function
Rem --------------------------------------------------------------------
Je lance cette macro, sans succès. Est-ce que j'ai bien écrit les paramètres de la fonction?
Sub RemplacerNSChParNCar()
Remplacer1SChPar1Car("=20", " ")
End Sub
Je n'ai pas trouvvé l'erreur et pourtant je l'ai bien cherchée.
Avec mes remerciements
Cordialement
Papy
--------------------------------------------------------------------- To unsubscribe, e-mail: prog...@fr.openoffice.org For additional commands, e-mail: prog...@fr.openoffice.org
-- No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.432 / Virus Database: 268.15.26/597 - Release Date: 21.12.2006 18:45
-- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.432 / Virus Database: 268.15.26/597 - Release Date: 21.12.2006 18:45







