Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Access > Contribuez
Contribuez Access : Vos contributions. Postez ici vos codes sources, conseils, astuces et autres propositions. Ce forum n'est pas un forum technique mais destiné aux contributions pour www.developpez.com
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 10/06/2006, 11h26   #1
Membre Expert
 
Inscription : avril 2006
Messages : 1 318
Détails du profil
Informations forums :
Inscription : avril 2006
Messages : 1 318
Points : 1 586
Points : 1 586
Par défaut [SOURCE] Lorem ipsum dolor sit amet,

Citation:

Lorem ipsum dolor sit amet, recusandae dolorem non www.developpez.com sit inventore voluptatem Access, fugiat? Officia ut PhilBen aliquid non delectus. Sed amet voluptates, vitae rerum.

Vous allez dire : "Ils sont fous ces romains !", un post en latin...

La recette de cette citation n'est qu'un amalgame de mots d'origine latine avec un zeste de mots personnels et une cuillerée de ponctuation.

L'idée de créer un générateur de texte "latin" est, je crois, de Macromedia pour son logiciel Dreamweaver, ce qui permettait de remplir automatiquement des pages Web avec du texte sans signification dans le but de tester le rendu du site.

Confronté parfois au remplissage de table en phase de test avec des données aléatoires et attiré par le principe, je me suis décidé de créer une classe Access générant du texte "latin".

Le code est composé de 2 classes.
La classe a appelé pour générer différents champs (nom, adresse, téléphone, paragraphe,...) :
(Remarque : 2ème classe dans le POST suivant)
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258

'***************************************************************************************
' Module    : clsLoremIpsum (Type : Module de classe) [Project : LoremIpsum]
' Date Time : 15/05/2006
' Version   : 1.0
' Purpose   : Classe à appeler pour générer des données à base de mots latins
'***************************************************************************************
Option Compare Database
Option Explicit

Public Enum TypeParagraphe
   parComptageMots = 1
   ParLongueurTexte = 2
End Enum

Private Const gcsListeVoies As String = "Quai,Rond Point,Passage,Square,Faubourg," & _
               "Rue,Impasse,Allée,Avenue,Boulevard,Cours,Place,Route,Chemin,Montée," & _
               "Villa,Rocade,Port"
Private goLI As clsLoremIpsumBase
Private gasVoies() As String
Private giCstLimVoies As Integer
'---------------------------------------------------------------------------------------
' Procedure    : class_initialize (Type : Sub)
' Purpose      :
'---------------------------------------------------------------------------------------
Private Sub class_initialize()
   Set goLI = New clsLoremIpsumBase
End Sub
'---------------------------------------------------------------------------------------
' Procedure    : class_terminate (Type : Sub)
' Purpose      :
'---------------------------------------------------------------------------------------
Private Sub class_terminate()
   Set goLI = Nothing
End Sub
'---------------------------------------------------------------------------------------
' Procedure    : SetMotsPerso (Type : Function)
' Purpose      : Permet d'inclure des mots persos dans les textes générés
'---------------------------------------------------------------------------------------
Public Function SetMotsPerso(sListeSepVirgule As String) As Boolean
   Dim iCount As Integer
   If sListeSepVirgule = vbNullString Then
      Exit Function
   End If
   iCount = goLI.CountDynMots
   goLI.SetDynMots = sListeSepVirgule
   SetMotsPerso = IIf(goLI.CountDynMots - iCount > 0, True, False)
End Function
'---------------------------------------------------------------------------------------
' Procedure    : SetActifMotsPerso (Type : Property)
' Purpose      : Active ou non la liste de mots
'---------------------------------------------------------------------------------------
Public Property Let SetActifMotsPerso(bOui As Boolean)
   goLI.SetActifDynMots = bOui
End Property
'---------------------------------------------------------------------------------------
' Procedure    : IsActifMotsPerso (Type : Property)
' Return value : Boolean
' Purpose      : Renvoi l'état d'activation de la liste des mots perso
'---------------------------------------------------------------------------------------
Public Property Get IsActifMotsPerso() As Boolean
   IsActifMotsPerso = goLI.IsActifDynMots
End Property
'---------------------------------------------------------------------------------------
' Procedure    : SetProbaMotsPerso (Type : Property)
' Return value :
' Purpose      : Permet de modifier la probabilité d'apparition des mots perso
'---------------------------------------------------------------------------------------
Public Property Let SetProbaMotsPerso(fVal As Single)
   goLI.SetProbaDynMots = fVal
End Property
'---------------------------------------------------------------------------------------
' Procedure    : GetProbaMotsPerso (Type : Property)
' Return value : Single
' Purpose      : Retourne la proba des mots persos
'---------------------------------------------------------------------------------------
Public Property Get GetProbaMotsPerso() As Single
   GetProbaMotsPerso = goLI.GetProbaDynMots
End Property
'---------------------------------------------------------------------------------------
' Procedure    : GetParagraphe (Type : Function)
' Return value : String
' Purpose      : Génère un paragraphe limité par nb mots ou longueur selon choix
'---------------------------------------------------------------------------------------
Public Function GetParagraphe(eType As TypeParagraphe, ByVal iValeur As Integer, _
                              Optional bDebutLoremIpsum As Boolean = True) As String
   If eType = TypeParagraphe.parComptageMots Then
      If iValeur > 512 Then
         iValeur = 512
      End If
      GetParagraphe = goLI.GetParagrapheByMots(iValeur, bDebutLoremIpsum, True)
   ElseIf eType = TypeParagraphe.ParLongueurTexte Then
      If iValeur > 1024 Then
         iValeur = 1024
      End If
      GetParagraphe = goLI.GetParagrapheByLen(iValeur, bDebutLoremIpsum, True)
   End If
End Function
'---------------------------------------------------------------------------------------
' Procedure    : GetPrenom (Type : Function)
' Return value : String
' Purpose      : Génère un prénom
'---------------------------------------------------------------------------------------
Public Function GetPrenom(Optional ByVal iMinLenMots As Integer = 0, _
                          Optional ByVal iMaxLenPrenom As Integer = 0) As String
   GetPrenom = SetMots(iMinLenMots, iMaxLenPrenom, vbProperCase, "-")
End Function
'---------------------------------------------------------------------------------------
' Procedure    : GetNom (Type : Function)
' Return value : String
' Purpose      : Génère un nom
'---------------------------------------------------------------------------------------
Public Function GetNom(Optional ByVal iMinLenMots As Integer = 0, _
                       Optional ByVal iMaxLenNom As Integer = 0) As String
   GetNom = SetMots(iMinLenMots, iMaxLenNom, vbUpperCase, "-")
End Function
'---------------------------------------------------------------------------------------
' Procedure    : GetAdresse (Type : Function)
' Return value : String
' Purpose      : Génère une adresse postale
'---------------------------------------------------------------------------------------
Public Function GetAdresse(Optional ByVal iMinLenMots As Integer = 0, _
                           Optional ByVal iMaxLenAdresse As Integer = 0) As String
   Dim sTmp As String
   GetAdresse = Int(300 * Rnd() + 1)
   If Rnd() < 0.15 Then
      GetAdresse = GetAdresse & IIf(Rnd() < 0.5, " A", " bis")
   End If
   If giCstLimVoies = 0 Then InitVoies
   GetAdresse = GetAdresse & ", " & gasVoies(Int(giCstLimVoies * Rnd())) & " "
   iMaxLenAdresse = iMaxLenAdresse - Len(GetAdresse)
   If iMinLenMots < iMaxLenAdresse Then
      sTmp = SetMots(iMinLenMots, iMaxLenAdresse, vbProperCase)
      GetAdresse = IIf(sTmp = vbNullString, vbNullString, GetAdresse & sTmp)
   Else
      GetAdresse = vbNullString
   End If
End Function
'---------------------------------------------------------------------------------------
' Procedure    : GetCommune (Type : Function)
' Return value : String
' Purpose      : Génère un nom de commune
'---------------------------------------------------------------------------------------
Public Function GetCommune(Optional ByVal iMinLenMots As Integer = 0, _
                           Optional ByVal iMaxLenCommune As Integer = 0) As String
   Dim sTmp As String
   If Rnd() < 0.12 Then
      sTmp = IIf(Rnd() < 0.5, "SAINT ", "SAINTE ")
      If Len(sTmp) <= iMaxLenCommune Then
         GetCommune = sTmp
      End If
   End If
   iMaxLenCommune = iMaxLenCommune - Len(GetCommune)
   If iMinLenMots < iMaxLenCommune Then
      GetCommune = GetCommune & SetMots(iMinLenMots, iMaxLenCommune, vbUpperCase)
   End If

End Function
'---------------------------------------------------------------------------------------
' Procedure    : GetCodePostal (Type : Function)
' Return value : String
' Purpose      : Génère un code postal à 5 chiffres
'---------------------------------------------------------------------------------------
Public Function GetCodePostal() As String
   GetCodePostal = Format(Int(99999 * Rnd() + 1), "00000")
End Function
'---------------------------------------------------------------------------------------
' Procedure    : GetTelephone (Type : Function)
' Return value : String
' Purpose      : Génère un n° de téléphone à 10 chiffres
'---------------------------------------------------------------------------------------
Public Function GetTelephone() As String
   Dim iPrefixe As Integer
   iPrefixe = Int(7 * Rnd()) + 1
   GetTelephone = "0" & IIf(iPrefixe < 7, iPrefixe, iPrefixe + 1) & Format(Int(99999999 * Rnd() + 1), "00000000")
End Function
'---------------------------------------------------------------------------------------
' Procedure    : GetDate (Type : Function)
' Return value : Date
' Purpose      : Génère une date dans les limites
'---------------------------------------------------------------------------------------
Public Function GetDate(dMinDate As Date, dMaxDate As Date) As Date
   Dim lJours As Long
   Dim dTmp As Date
   
   Swap dMinDate, dMaxDate
  
   lJours = DateDiff("d", dMinDate, dMaxDate)
   lJours = Int((lJours + 1) * Rnd())
   GetDate = DateAdd("d", lJours, dMinDate)
End Function
'---------------------------------------------------------------------------------------
' Procedure    : SetMots (Type : Function)
' Return value : String
' Purpose      : Fonction interne pour générer plusieurs mots
'---------------------------------------------------------------------------------------
Private Function SetMots(iMinLenMots As Integer, iMaxLenTexte As Integer, _
                        iCasse As Integer, Optional sSupSep As String = vbNullString) As String
   Dim sTmpMot As String, sSep As String
   Dim iLenMot As Integer
   Dim bSupSep As Boolean
      
   If iMaxLenTexte <= 0 Then
      Exit Function
   ElseIf iMinLenMots < 0 Then
      iMinLenMots = 0
   End If
   
   If Len(sSupSep) > 0 And sSupSep <> " " Then
      bSupSep = True
   End If
   
   Do
      If iMaxLenTexte < iMinLenMots Then
         Exit Do
      ElseIf iLenMot > 0 And Rnd() < (iMinLenMots / (iMaxLenTexte + 1)) Then
         Exit Do
      End If
      
      sTmpMot = StrConv(goLI.GetMot(iMinLenMots, iMaxLenTexte - Len(sSep), sTmpMot), iCasse)
      iLenMot = Len(sTmpMot)
      
      If iLenMot = 0 Then
         Exit Do
      Else
         SetMots = SetMots & sSep & sTmpMot
         iMaxLenTexte = iMaxLenTexte - iLenMot - Len(sSep)
      End If
      If bSupSep = True And Rnd() < 0.5 Then
         sSep = sSupSep
      Else
         sSep = " "
      End If
   Loop
End Function
'---------------------------------------------------------------------------------------
' Procedure    : Swap (Type : Sub)
' Return value :
' Purpose      : Permet de swapper 2 variants
'---------------------------------------------------------------------------------------
Private Sub Swap(ByRef vMin As Variant, ByRef vMax As Variant)
   If vMin > vMax Then
      Dim vTmp As Variant
      vTmp = vMin
      vMin = vMax
      vMax = vTmp
   End If
End Sub
'---------------------------------------------------------------------------------------
' Procedure    : InitVoies (Type : Sub)
' Return value :
' Purpose      : Crée le tableau des noms de voie pour les adresses
'---------------------------------------------------------------------------------------
Private Sub InitVoies()
   gasVoies = Split(gcsListeVoies, ",")
   giCstLimVoies = UBound(gasVoies) + 1
End Sub
Citation:

Laborum recusandae duis a commodi voluptatem eos?

ou

Comment utiliser cette classe dans votre code ?
1) Déclaration et initialisation de la classe
Code :
1
2
3
4
 
 
Dim oGenLI As clsLoremIpsum
Set oGenLI = New clsLoremIpsum
2) Ajout éventuel de mots personnels
Code :
1
2
3
4
5
6
7
8
9
10
11

' Passe la liste de mots personnels séparés par des virgules
oGenLI.SetMotsPerso "Access,www.developpez.com,PhilBen"

' Défini la probabilité d'apparition des mots de cette liste dans le texte généré
' (0.1 => 10 % de chance d'avoir un mot de la liste perso sur 100 mots générés)
oGenLI.SetProbaMotsPerso = 0.1

' Active la liste de mots perso
oGenLI.SetActifMotsPerso = Me.Actif
C) Appel des fonction de génération de texte
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

' Génère un texte en majuscule simulant un nom (longueur aléatoire)
' On définit la longueur mini des mots retournées et la longueur maxi du texte
sNom = oGenLI.GetNom(iMotMiniLongueur, iTxtMaxLongueur)

' Génère un texte avec la première lettre des mots en capitale
' simulant un prénom (longueur aléatoire)
' Paramètres identiques à GetNom
sPrenom = oGenLI.GetPrenom(3, 15)

' Génère une adresse postale (n° Voie(en français) Nom)
' Paramètres identiques à GetNom
sAdresse = oGenLI.GetAdresse(3, 38)

' Génère un code postal français (de 01XXX à 99XXX)
' Pas de paramètre
sCP = oGenLI.GetCodePostal

' Génère le nom d'une commune avec parfois "SAINT" ou "SAINTE" en préfixe
' Paramètres identiques à GetNom
sCommune = oGenLI.GetCommune(5, 25)

' Génère un paragraphe limité par un nombre de mots
' Le dernier paramètre défini si le exte commence par "Lorem ipsum dolor..."
sTexte = oGenLI.GetParagraphe(parComptageMots, 50, True)

' Génère un paragraphe limité par une longueursTexte = oGenLI.GetParagraphe(TypeParagraphe.ParLongueurTexte, 150, False)

' Génère un numéro de téléphone (10 chiffres ) avec préfixe 01/02/03/04/05/06/08
sTel = oGenLI.GetTelephone

' Génère une date (format date) entre 2 dates définies en paramètres
dDate = oGenLI.GetDate(#1/1/1910#, Date)
D) Libérer la classe
Code :
1
2
3
 
 
Set oGenLI = Nothing

Pour en savoir plus sur Lorem Ipsum :
http://www.loremipsum.net

Ci-joint une base access pour tester les fonctions et le code source.

Philippe
philben est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/06/2006, 11h31   #2
Membre Expert
 
Inscription : avril 2006
Messages : 1 318
Détails du profil
Informations forums :
Inscription : avril 2006
Messages : 1 318
Points : 1 586
Points : 1 586
La classe de base (ne tenez pas sur le post précédent) :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430

'***************************************************************************************
' Module    : clsLoremIpsumBase (Type : Module de classe) [Project : LoremIpsum]
' Date Time : 15/05/2006
' Purpose   : Génère un texte aléatoire avec des mots latins
'***************************************************************************************
Option Compare Database
Option Explicit
Option Base 0
   
Private Const csSpace As String = " "
Private Const csVirguleSpace As String = "," & csSpace
Private Const csPoint As String = "."
Private Const csPointSpace As String = csPoint & csSpace
Private Const csPtInt As String = "?"
Private Const csPtIntSpace As String = csPtInt & csSpace

Private Const cbyMinMotsVirgule As Byte = 1
Private Const cbyMaxMotsVirgule As Byte = 9
Private Const cbyMinMotsPhrase As Byte = 3
Private Const cbyMaxMotsPhrase As Byte = 11
Private Const cfMinProbaPoint As Single = 0.15

Private Const csLoremIpsum As String = "Lorem ipsum dolor sit amet"

Private gasCstMots() As String
Private giCstLim As Integer
Private gbyCstMinLenMots As Byte, gbyCstMaxLenMots As Byte

Private giCstVirguleLim As Integer, giCstPhraseLim As Integer

Private gasDynMots() As String
Private gfProbaDynMots As Single
Private giDynLim As Integer
Private gbyDynMinLenMots As Byte, gbyDynMaxLenMots As Byte
Private gbActifDynMots As Boolean
'---------------------------------------------------------------------------------------
' Procedure    : class_initialize (Type : Sub)
' Return value :
' Purpose      :
'---------------------------------------------------------------------------------------
Private Sub class_initialize()
   Const csLIMots As String = "lorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod tempor incididunt ut labore et dolore magna " & _
            "aliqua ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat " & _
            "duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur excepteur " & _
            "sint occaecat cupidatat non proident sunt in culpa qui officia deserunt mollit anim id est laborum sed ut perspiciatis " & _
            "unde omnis iste natus error sit voluptatem accusantium doloremque laudantium totam rem aperiam eaque ipsa quae ab illo " & _
            "inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo nemo enim ipsam voluptatem quia voluptas sit " & _
            "aspernatur aut odit aut fugit sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt neque porro " & _
            "quisquam est qui dolorem ipsum quia dolor sit amet consectetur adipisci velit sed quia non numquam eius modi tempora " & _
            "incidunt ut labore et dolore magnam aliquam quaerat voluptatem ut enim ad minima veniam quis nostrum exercitationem " & _
            "ullam corporis suscipit laboriosam nisi ut aliquid ex ea commodi consequatur quis autem vel eum iure reprehenderit " & _
            "qui in ea voluptate velit esse quam nihil molestiae consequatur vel illum qui dolorem eum fugiat quo voluptas nulla " & _
            "pariatur at vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti " & _
            "atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident similique sunt in " & _
            "culpa qui officia deserunt mollitia animi id est laborum et dolorum fuga et harum quidem rerum facilis est et expedita " & _
            "distinctio nam libero tempore cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat " & _
            "facere possimus omnis voluptas assumenda est omnis dolor repellendus temporibus autem quibusdam et aut officiis debitis " & _
            "aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae itaque earum rerum " & _
            "hic tenetur a sapiente delectus ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat"
   Dim i As Integer, iLenMot As Integer
   
   Randomize (Timer)

   giCstVirguleLim = cbyMaxMotsVirgule - cbyMinMotsVirgule + 1
   giCstPhraseLim = cbyMaxMotsPhrase - cbyMinMotsPhrase + 1
   
   gasCstMots = (Split(csLIMots, csSpace))
   giCstLim = UBound(gasCstMots) + 1
   gbyCstMinLenMots = 255
   For i = 0 To giCstLim - 1
      iLenMot = Len(gasCstMots(i))
      If iLenMot < gbyCstMinLenMots Then
         gbyCstMinLenMots = iLenMot
      End If
      If iLenMot > gbyCstMaxLenMots Then
         gbyCstMaxLenMots = iLenMot
      End If
   Next i
   gbyDynMinLenMots = 255
End Sub
'---------------------------------------------------------------------------------------
' Procedure    : MaxLenMots (Type : Property)
' Return value : Byte
' Purpose      : Retourne la longueur maximum des mots latins
'---------------------------------------------------------------------------------------
Public Property Get MaxLenMots() As Byte
   MaxLenMots = IIf(gbActifDynMots = True And gbyDynMaxLenMots > gbyCstMaxLenMots, gbyDynMaxLenMots, gbyCstMaxLenMots)
End Property
'---------------------------------------------------------------------------------------
' Procedure    : MinLenMots (Type : Property)
' Return value : Byte
' Purpose      : Retourne la longueur minimum des mots latins
'---------------------------------------------------------------------------------------
Public Property Get MinLenMots() As Byte
   MinLenMots = IIf(gbActifDynMots = True And gbyDynMinLenMots < gbyCstMinLenMots, gbyDynMinLenMots, gbyCstMinLenMots)
End Property
'---------------------------------------------------------------------------------------
' Procedure    : CountDynMots (Type : Property)
' Return value : Integer
' Purpose      : Retourne le nombre de mots perso
'---------------------------------------------------------------------------------------
Public Property Get CountDynMots() As Integer
   CountDynMots = giDynLim
End Property
'---------------------------------------------------------------------------------------
' Procedure    : IsActifDynMots (Type : Property)
' Return value : Boolean
' Purpose      : Retourne l'état (actif ou inactif) de la liste perso
'---------------------------------------------------------------------------------------
Public Property Get IsActifDynMots() As Boolean
   IsActifDynMots = gbActifDynMots
End Property
'---------------------------------------------------------------------------------------
' Procedure    : GetProbaDynMots (Type : Property)
' Return value : Single
' Purpose      : Retourne la probabilité d'apparition des mots persos
'---------------------------------------------------------------------------------------
Public Property Get GetProbaDynMots() As Single
   GetProbaDynMots = gfProbaDynMots
End Property
'---------------------------------------------------------------------------------------
' Procedure    : SetProbaDynMots (Type : Property)
' Return value :
' Purpose      : Permet de définir la proba des mots perso
'---------------------------------------------------------------------------------------
Public Property Let SetProbaDynMots(fProba As Single)
   If fProba >= 0 And fProba <= 1 Then
      gfProbaDynMots = fProba
   End If
End Property
'---------------------------------------------------------------------------------------
' Procedure    : SetActifDynMots (Type : Property)
' Return value :
' Purpose      : Permet d'activer ou de désactiver les mots perso
'---------------------------------------------------------------------------------------
Public Property Let SetActifDynMots(bOui As Boolean)
   If giDynLim > 0 Then
      gbActifDynMots = bOui
   End If
End Property
'---------------------------------------------------------------------------------------
' Procedure    : SetDynMots (Type : Property)
' Return value :
' Purpose      : Permet de définir les mots perso
'---------------------------------------------------------------------------------------
Public Property Let SetDynMots(sListeMots As String)
   Dim asTmp() As String, sMot As String
   Dim i As Integer, iLenMot As Integer, iNbMotsMax As Integer
   iNbMotsMax = giCstLim
   If giDynLim >= iNbMotsMax Then
      Exit Property
   End If
   asTmp = Split(sListeMots, ",")
   For i = 0 To UBound(asTmp)
      sMot = Trim$(asTmp(i))
      iLenMot = Len(sMot)
      If iLenMot > 0 And giDynLim < iNbMotsMax Then
         giDynLim = giDynLim + 1
         ReDim Preserve gasDynMots(giDynLim)
         gasDynMots(giDynLim - 1) = Left$(sMot, 255)
         If iLenMot < gbyDynMinLenMots Then
            gbyDynMinLenMots = iLenMot
         End If
         If iLenMot > gbyDynMaxLenMots Then
            gbyDynMaxLenMots = iLenMot
         End If
      Else
         Exit For
      End If
   Next i
End Property
'---------------------------------------------------------------------------------------
' Procedure    : GetMot (Type : Function)
' Return value : String
' Purpose      : Retourne un mot aléatoire
'---------------------------------------------------------------------------------------
Public Function GetMot(iMinLenMot As Integer, iMaxLenMot As Integer, sLastMot As String) As String
   Dim iMaxBoucle As Integer, iMaxLenMots As Integer, iMinLenMots As Integer
   Dim fProba As Single
   Dim i1 As Integer, i2 As Integer
   iMaxLenMots = Me.MaxLenMots
   iMinLenMots = Me.MinLenMots
   If iMinLenMot > iMaxLenMots Or iMaxLenMot < iMinLenMots Then
      GetMot = vbNullString
      Exit Function
   End If
   iMaxBoucle = IIf(gbActifDynMots = False, giCstLim, giDynLim * gfProbaDynMots + giCstLim * (1 - gfProbaDynMots))
   Do
      iMaxBoucle = iMaxBoucle - 1
      fProba = Rnd()
      If gbActifDynMots = False Then
         GetMot = gasCstMots(Int(giCstLim * fProba))
      Else
         If fProba < gfProbaDynMots Then
            GetMot = gasDynMots(Int(giDynLim * Rnd()))
         Else
            GetMot = gasCstMots(Int(giCstLim * Rnd()))
         End If
      End If
      If Len(GetMot) >= iMinLenMot And Len(GetMot) <= iMaxLenMot And GetMot <> sLastMot Then
         Exit Function
      ElseIf iMaxBoucle = 0 Then
         GetMot = vbNullString
         Exit Function
      End If
   Loop
End Function
'---------------------------------------------------------------------------------------
' Procedure    : GetParagrapheByMots (Type : Function)
' Return value : String
' Purpose      : Retourne un paragraphe limité par un nombre de mots
'---------------------------------------------------------------------------------------
Public Function GetParagrapheByMots(ByVal iNbMots As Byte, _
                                    bDebutLoremIpsum As Boolean, _
                                    bPonctuationFin As Boolean) As String
   Dim asTmp() As String, sPonctuation As String, sMot As String, sLastMot As String
   Dim iCountMots As Integer, iCountMotsVirgule As Integer
   Dim i As Integer, iTmp As Integer
   Dim bMajuscule As Boolean, bVirgule As Boolean
      
   If iNbMots < 1 Then
      GetParagrapheByMots = vbNullString
      Exit Function
   End If
   
   If bDebutLoremIpsum = True Then
      asTmp = Split(csLoremIpsum, csSpace)
      iTmp = UBound(asTmp) + 1
      If iTmp >= iNbMots Then
         For i = 0 To (iNbMots - 1)
            GetParagrapheByMots = GetParagrapheByMots & asTmp(i) & csSpace
         Next i
         GetParagrapheByMots = Left$(GetParagrapheByMots, Len(GetParagrapheByMots) - 1) & _
                               IIf(bPonctuationFin = True, csPoint, vbNullString)
         Exit Function
      Else
         GetParagrapheByMots = csLoremIpsum & csVirguleSpace
         i = iTmp
      End If
      sMot = asTmp(i - 1)
   Else
      bMajuscule = True
   End If
   
   Do Until i >= iNbMots
      sLastMot = sMot
      sMot = GetParagrapheMot(sLastMot, bMajuscule)
      i = i + 1
      
      If i < iNbMots Then
         sPonctuation = GetPonctuation(bVirgule, bMajuscule, iCountMotsVirgule, iCountMots)
      ElseIf bPonctuationFin = True Then
         If Rnd() < cfMinProbaPoint Then
            sPonctuation = csPtInt
         Else
            sPonctuation = csPoint
         End If
      Else
         sPonctuation = vbNullString
      End If
    
      GetParagrapheByMots = GetParagrapheByMots & sMot & sPonctuation
   Loop
End Function
'---------------------------------------------------------------------------------------
' Procedure    : GetParagrapheByLen (Type : Function)
' Return value : String
' Purpose      : Retourne un paragraphe limité par une longueur
'---------------------------------------------------------------------------------------
Public Function GetParagrapheByLen(iMaxLenParagraphe As Integer, _
                                   bDebutLoremIpsum As Boolean, _
                                   bPonctuationFin As Boolean) As String
   Dim asTmp() As String, sPonctuation As String, sMot As String
   Dim sLastMot As String, sTmp As String
   Dim iCountMots As Integer, iCountMotsVirgule As Integer
   Dim iLenTexte As Integer, iTmp As Integer, iLenPonctuation As Integer
   Dim bMajuscule As Boolean, bVirgule As Boolean
      
   If iMaxLenParagraphe < 3 Then
      GetParagrapheByLen = vbNullString
      Exit Function
   End If
   
   If bDebutLoremIpsum = True Then
      iTmp = IIf(bPonctuationFin = True, Len(csPoint), 0)
      iLenTexte = Len(csLoremIpsum) + iTmp
      If iLenTexte >= iMaxLenParagraphe Then
          GetParagrapheByLen = Left$(csLoremIpsum, iMaxLenParagraphe - iTmp) & _
                              IIf(bPonctuationFin = True, csPoint, vbNullString)
         Exit Function
      End If
      asTmp = Split(csLoremIpsum, csSpace)
      sMot = asTmp(UBound(asTmp))
      GetParagrapheByLen = csLoremIpsum & csVirguleSpace
      iLenTexte = Len(GetParagrapheByLen)
   Else
      bMajuscule = True
   End If
   
   Do
      sLastMot = sMot
      sMot = GetParagrapheMot(sLastMot, bMajuscule)
      iLenTexte = iLenTexte + Len(sMot)
      
      If iLenTexte < iMaxLenParagraphe Then
         sPonctuation = GetPonctuation(bVirgule, bMajuscule, iCountMotsVirgule, iCountMots)
         iLenPonctuation = Len(sPonctuation)
      Else
         iLenPonctuation = 0
      End If
    
      If (iLenTexte + iLenPonctuation) < iMaxLenParagraphe Then
         GetParagrapheByLen = GetParagrapheByLen & sMot & sPonctuation
         iLenTexte = iLenTexte + iLenPonctuation
      Else
         If bPonctuationFin = True Then
            sPonctuation = IIf(Rnd() < cfMinProbaPoint, csPtInt, csPoint)
         Else
            sPonctuation = vbNullString
         End If
         iLenTexte = iMaxLenParagraphe + Len(sMot) - iLenTexte - Len(sPonctuation)
         If iLenTexte < Len(csPointSpace) Then
            sTmp = Right$(GetParagrapheByLen, Len(csPointSpace))
            If sTmp = csVirguleSpace Or sTmp = csPointSpace Or sTmp = csPtIntSpace Then
               If iLenTexte < gbyCstMinLenMots Then
                  GetParagrapheByLen = Left$(GetParagrapheByLen, _
                                    Len(GetParagrapheByLen) - Len(csPointSpace)) & sPonctuation
                  Exit Do
               Else
                  GetParagrapheByLen = Left$(GetParagrapheByLen, _
                                    Len(GetParagrapheByLen) - Len(csPointSpace)) & csSpace
                  iLenTexte = iLenTexte + Len(csPointSpace) - Len(csSpace)
               End If
            ElseIf iLenTexte = 0 Then
               GetParagrapheByLen = RTrim$(GetParagrapheByLen) & sPonctuation
               Exit Do
            End If
         End If
         If iLenTexte < Len(sMot) And iLenTexte >= gbyCstMinLenMots Then
            iTmp = giCstLim
            Do
               iTmp = iTmp - 1
               sMot = gasCstMots(iTmp)
            Loop Until (Len(sMot) = iLenTexte And sMot <> sLastMot) Or iTmp = 0
            If Len(sMot) = iLenTexte Then
               GetParagrapheByLen = GetParagrapheByLen & sMot & sPonctuation
            Else
               GetParagrapheByLen = Left$(GetParagrapheByLen & sMot, _
                                 iMaxLenParagraphe - Len(sPonctuation)) & sPonctuation
            End If
         Else
            GetParagrapheByLen = GetParagrapheByLen & sMot & sPonctuation
         End If
         Exit Do
      End If
   Loop
End Function
'---------------------------------------------------------------------------------------
' Procedure    : GetParagrapheMot (Type : Function)
' Return value : String
' Purpose      : Fonction interne pour les fonction Paragraphes
'---------------------------------------------------------------------------------------
Private Function GetParagrapheMot(sLastMot As String, ByRef bMajuscule As Boolean) As String
   Dim fProba As Single
   Do
      fProba = Rnd()
      If gbActifDynMots = False Then
         GetParagrapheMot = gasCstMots(Int(giCstLim * fProba))
      Else
         If fProba < gfProbaDynMots Then
            GetParagrapheMot = gasDynMots(Int(giDynLim * Rnd()))
         Else
            GetParagrapheMot = gasCstMots(Int(giCstLim * Rnd()))
         End If
      End If
   Loop Until Len(GetParagrapheMot) > 0 And GetParagrapheMot <> sLastMot
   
   If bMajuscule = True Then
      GetParagrapheMot = StrConv(GetParagrapheMot, vbProperCase)
      bMajuscule = False
   End If
End Function
'---------------------------------------------------------------------------------------
' Procedure    : GetPonctuation (Type : Function)
' Return value : String
' Purpose      : Fonction interne pour les Paragraphes qui retourne une ponctuation aléatoire
'---------------------------------------------------------------------------------------
Private Function GetPonctuation(ByRef bVirgule As Boolean, ByRef bMajuscule As Boolean, _
                 ByRef iCountMotsVirgule As Integer, ByRef iCountMots As Integer) As String
   Dim i As Integer
   
   bVirgule = False
   GetPonctuation = csSpace
   iCountMotsVirgule = iCountMotsVirgule + 1
   iCountMots = iCountMots + 1

   If iCountMotsVirgule >= cbyMinMotsVirgule Then
      If iCountMotsVirgule <= cbyMaxMotsVirgule Then
         i = Int(giCstVirguleLim * Rnd() + cbyMinMotsVirgule)
         If i = iCountMotsVirgule Then
            GetPonctuation = csVirguleSpace
            iCountMotsVirgule = 0
            bVirgule = True
         End If
      Else
         GetPonctuation = csVirguleSpace
         iCountMotsVirgule = 0
         bVirgule = True
      End If
   End If
      
   If bVirgule = False Then
      If iCountMots >= cbyMinMotsPhrase Then
         If iCountMots <= cbyMaxMotsPhrase Then
            i = Int(giCstPhraseLim * Rnd() + cbyMinMotsPhrase)
            If i = iCountMots Then
               GetPonctuation = IIf(Rnd() < cfMinProbaPoint, csPtIntSpace, csPointSpace)
               iCountMots = 0
               bMajuscule = True
            End If
         Else
            GetPonctuation = IIf(Rnd() < cfMinProbaPoint, csPtIntSpace, csPointSpace)
            iCountMots = 0
            bMajuscule = True
         End If
      End If
   End If
End Function
Philippe
philben est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/06/2006, 11h38   #3
Expert Confirmé Sénior
 
Jean-Michel BORLOT
Fabricant et casseur d'avions
Inscription : avril 2004
Messages : 2 984
Détails du profil
Informations personnelles :
Nom : Jean-Michel BORLOT
Localisation : France, Haute Garonne (Midi Pyrénées)

Informations professionnelles :
Activité : Fabricant et casseur d'avions
Secteur : Aéronautique - Marine - Espace - Armement

Informations forums :
Inscription : avril 2004
Messages : 2 984
Points : 4 691
Points : 4 691
Salut,

Une petite remarque en passant... corrige le lien vers ton site, ça pointe vers http://www.loremipsum.com...
__________________
"Errare humanum est, sed perseverare diabolicum"

Si vous avez un terrain constructible dans l'est du Gers à vendre pas trop cher, contactez-moi par MP.

Ma page sur DVP.com : articles Java/Jogl
Mon site www.plegat.org
plegat est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/06/2006, 11h48   #4
Membre Expert
 
Inscription : avril 2006
Messages : 1 318
Détails du profil
Informations forums :
Inscription : avril 2006
Messages : 1 318
Points : 1 586
Points : 1 586
Bonjour,

merci, correction faite.

"Alea jacta est..."

Philippe

P.S. : Ca va devenir un site d'intellectuels !
philben est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/12/2006, 08h42   #5
Membre Expert
 
Inscription : avril 2006
Messages : 1 318
Détails du profil
Informations forums :
Inscription : avril 2006
Messages : 1 318
Points : 1 586
Points : 1 586
Bonjour,

La dernière version est ici :
http://pbserv.free.fr/dev/

Philippe
philben est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/02/2011, 10h29   #6
Rédacteur

 
Avatar de ClaudeLELOUP
 
Homme Claude LELOUP
Chercheur de loisirs (ayant trouvé !)
Inscription : novembre 2006
Messages : 5 252
Détails du profil
Informations personnelles :
Nom : Homme Claude LELOUP
Âge : 66
Localisation : Belgique

Informations professionnelles :
Activité : Chercheur de loisirs (ayant trouvé !)
Secteur : Finance

Informations forums :
Inscription : novembre 2006
Messages : 5 252
Points : 11 063
Points : 11 063
Ave Philben,

Le hasard m’a conduit à ce post ancien plein d’humour.
http://pbserv.free.fr/dev/LoremIpsum%20v1.01.zip propose un fichier LoremIpsum.mdb d’une version postérieure à Access2000.
Reconnaissance éternelle si tu postes une version compatible Access2000.

Quoi qu’il en soit : Ave atque vale.
ClaudeLELOUP est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/02/2011, 17h39   #7
Membre Expert
 
Inscription : avril 2006
Messages : 1 318
Détails du profil
Informations forums :
Inscription : avril 2006
Messages : 1 318
Points : 1 586
Points : 1 586
Ave Claude ,

La version 2000 de LoremIpsum.

Bonne fin de journée,

Philippe
philben est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 13/02/2011, 17h47   #8
Rédacteur

 
Avatar de ClaudeLELOUP
 
Homme Claude LELOUP
Chercheur de loisirs (ayant trouvé !)
Inscription : novembre 2006
Messages : 5 252
Détails du profil
Informations personnelles :
Nom : Homme Claude LELOUP
Âge : 66
Localisation : Belgique

Informations professionnelles :
Activité : Chercheur de loisirs (ayant trouvé !)
Secteur : Finance

Informations forums :
Inscription : novembre 2006
Messages : 5 252
Points : 11 063
Points : 11 063
Ce qui est dit, est dit : "éternelle" !

ClaudeLELOUP est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 22h19.


 
 
 
 
Partenaires

Hébergement Web