peut on créer un module de classe qui fabriquerait des nombres aléatoires et
les renverrai dans un tableau ? j'ai essayé ceci mais ca ne marche pas...
Public Function Rand(ByVal Low As Long, ByVal High As Long, ByVal Deci As
Boolean, ByVal Combien As Integer) As Variant
Dim Tableau(1 To Combien) As Variant
Select Case Deci
Case False
For i = 1 To Combien
Rand = Int((High - Low + 1) * Rnd) + Low
Tableau(i) = Rand
Next i
Case Else
For i = 1 To Combien
Rand = ((High - Low + 1) * Rnd) + Low
Tableau(i) = Rand
Next i
End Select
End Function
Je n'arrive pas à afficher les nombres sur ma form1.
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
Jean-Marc
"scalpa" a écrit dans le message de news:
peut on créer un module de classe qui fabriquerait des nombres aléatoires
et
les renverrai dans un tableau ? j'ai essayé ceci mais ca ne marche pas...
Public Function Rand(ByVal Low As Long, ByVal High As Long, ByVal Deci As Boolean, ByVal Combien As Integer) As Variant
Dim Tableau(1 To Combien) As Variant Select Case Deci Case False For i = 1 To Combien Rand = Int((High - Low + 1) * Rnd) + Low Tableau(i) = Rand Next i Case Else For i = 1 To Combien Rand = ((High - Low + 1) * Rnd) + Low Tableau(i) = Rand Next i End Select
End Function
Je n'arrive pas à afficher les nombres sur ma form1.
Hello, ça marchera mieux comme ceci:
Public Function Rand(ByRef Tableau() As Variant, ByVal Low As Long, ByVal High As Long, ByVal Deci As Boolean, ByVal Combien As Integer) As Variant
ReDim Tableau(1 To Combien) Dim i As Long
Select Case Deci Case False For i = 1 To Combien Rand = Int((High - Low + 1) * Rnd) + Low Tableau(i) = Rand Next i Case Else For i = 1 To Combien Rand = ((High - Low + 1) * Rnd) + Low Tableau(i) = Rand Next i End Select End Function
Et l'appel:
Dim t() As Variant
Rand t(), 1, 100, False, 10
-- Jean-marc "There are only 10 kind of people those who understand binary and those who don't."
"scalpa" <scalpaNoSpam@wanadoo.fr> a écrit dans le message de
news:eM7o8CK1EHA.3452@TK2MSFTNGP14.phx.gbl...
peut on créer un module de classe qui fabriquerait des nombres aléatoires
et
les renverrai dans un tableau ? j'ai essayé ceci mais ca ne marche pas...
Public Function Rand(ByVal Low As Long, ByVal High As Long, ByVal Deci As
Boolean, ByVal Combien As Integer) As Variant
Dim Tableau(1 To Combien) As Variant
Select Case Deci
Case False
For i = 1 To Combien
Rand = Int((High - Low + 1) * Rnd) + Low
Tableau(i) = Rand
Next i
Case Else
For i = 1 To Combien
Rand = ((High - Low + 1) * Rnd) + Low
Tableau(i) = Rand
Next i
End Select
End Function
Je n'arrive pas à afficher les nombres sur ma form1.
Hello, ça marchera mieux comme ceci:
Public Function Rand(ByRef Tableau() As Variant, ByVal Low As Long, ByVal
High As Long, ByVal Deci As Boolean, ByVal Combien As Integer) As Variant
ReDim Tableau(1 To Combien)
Dim i As Long
Select Case Deci
Case False
For i = 1 To Combien
Rand = Int((High - Low + 1) * Rnd) + Low
Tableau(i) = Rand
Next i
Case Else
For i = 1 To Combien
Rand = ((High - Low + 1) * Rnd) + Low
Tableau(i) = Rand
Next i
End Select
End Function
Et l'appel:
Dim t() As Variant
Rand t(), 1, 100, False, 10
--
Jean-marc
"There are only 10 kind of people
those who understand binary and those who don't."
peut on créer un module de classe qui fabriquerait des nombres aléatoires
et
les renverrai dans un tableau ? j'ai essayé ceci mais ca ne marche pas...
Public Function Rand(ByVal Low As Long, ByVal High As Long, ByVal Deci As Boolean, ByVal Combien As Integer) As Variant
Dim Tableau(1 To Combien) As Variant Select Case Deci Case False For i = 1 To Combien Rand = Int((High - Low + 1) * Rnd) + Low Tableau(i) = Rand Next i Case Else For i = 1 To Combien Rand = ((High - Low + 1) * Rnd) + Low Tableau(i) = Rand Next i End Select
End Function
Je n'arrive pas à afficher les nombres sur ma form1.
Hello, ça marchera mieux comme ceci:
Public Function Rand(ByRef Tableau() As Variant, ByVal Low As Long, ByVal High As Long, ByVal Deci As Boolean, ByVal Combien As Integer) As Variant
ReDim Tableau(1 To Combien) Dim i As Long
Select Case Deci Case False For i = 1 To Combien Rand = Int((High - Low + 1) * Rnd) + Low Tableau(i) = Rand Next i Case Else For i = 1 To Combien Rand = ((High - Low + 1) * Rnd) + Low Tableau(i) = Rand Next i End Select End Function
Et l'appel:
Dim t() As Variant
Rand t(), 1, 100, False, 10
-- Jean-marc "There are only 10 kind of people those who understand binary and those who don't."
ng
Salut,
Je te conseillerai en outre de typer correctement ton retour de fonction (éviter le Variant !).
-- Nicolas G. FAQ VB : http://faq.vb.free.fr API Guide : http://www.allapi.net Google Groups : http://groups.google.fr/ MZ-Tools : http://www.mztools.com/
Jean-Marc wrote:
"scalpa" a écrit dans le message de news:
peut on créer un module de classe qui fabriquerait des nombres aléatoires et les renverrai dans un tableau ? j'ai essayé ceci mais ca ne marche pas...
Public Function Rand(ByVal Low As Long, ByVal High As Long, ByVal Deci As Boolean, ByVal Combien As Integer) As Variant
Dim Tableau(1 To Combien) As Variant Select Case Deci Case False For i = 1 To Combien Rand = Int((High - Low + 1) * Rnd) + Low Tableau(i) = Rand Next i Case Else For i = 1 To Combien Rand = ((High - Low + 1) * Rnd) + Low Tableau(i) = Rand Next i End Select
End Function
Je n'arrive pas à afficher les nombres sur ma form1.
Hello, ça marchera mieux comme ceci:
Public Function Rand(ByRef Tableau() As Variant, ByVal Low As Long, ByVal High As Long, ByVal Deci As Boolean, ByVal Combien As Integer) As Variant
ReDim Tableau(1 To Combien) Dim i As Long
Select Case Deci Case False For i = 1 To Combien Rand = Int((High - Low + 1) * Rnd) + Low Tableau(i) = Rand Next i Case Else For i = 1 To Combien Rand = ((High - Low + 1) * Rnd) + Low Tableau(i) = Rand Next i End Select End Function
Et l'appel:
Dim t() As Variant
Rand t(), 1, 100, False, 10
Salut,
Je te conseillerai en outre de typer correctement ton retour de fonction
(éviter le Variant !).
--
Nicolas G.
FAQ VB : http://faq.vb.free.fr
API Guide : http://www.allapi.net
Google Groups : http://groups.google.fr/
MZ-Tools : http://www.mztools.com/
Jean-Marc wrote:
"scalpa" <scalpaNoSpam@wanadoo.fr> a écrit dans le message de
news:eM7o8CK1EHA.3452@TK2MSFTNGP14.phx.gbl...
peut on créer un module de classe qui fabriquerait des nombres
aléatoires et les renverrai dans un tableau ? j'ai essayé ceci mais
ca ne marche pas...
Public Function Rand(ByVal Low As Long, ByVal High As Long, ByVal
Deci As Boolean, ByVal Combien As Integer) As Variant
Dim Tableau(1 To Combien) As Variant
Select Case Deci
Case False
For i = 1 To Combien
Rand = Int((High - Low + 1) * Rnd) + Low
Tableau(i) = Rand
Next i
Case Else
For i = 1 To Combien
Rand = ((High - Low + 1) * Rnd) + Low
Tableau(i) = Rand
Next i
End Select
End Function
Je n'arrive pas à afficher les nombres sur ma form1.
Hello, ça marchera mieux comme ceci:
Public Function Rand(ByRef Tableau() As Variant, ByVal Low As Long,
ByVal High As Long, ByVal Deci As Boolean, ByVal Combien As Integer)
As Variant
ReDim Tableau(1 To Combien)
Dim i As Long
Select Case Deci
Case False
For i = 1 To Combien
Rand = Int((High - Low + 1) * Rnd) + Low
Tableau(i) = Rand
Next i
Case Else
For i = 1 To Combien
Rand = ((High - Low + 1) * Rnd) + Low
Tableau(i) = Rand
Next i
End Select
End Function
Je te conseillerai en outre de typer correctement ton retour de fonction (éviter le Variant !).
-- Nicolas G. FAQ VB : http://faq.vb.free.fr API Guide : http://www.allapi.net Google Groups : http://groups.google.fr/ MZ-Tools : http://www.mztools.com/
Jean-Marc wrote:
"scalpa" a écrit dans le message de news:
peut on créer un module de classe qui fabriquerait des nombres aléatoires et les renverrai dans un tableau ? j'ai essayé ceci mais ca ne marche pas...
Public Function Rand(ByVal Low As Long, ByVal High As Long, ByVal Deci As Boolean, ByVal Combien As Integer) As Variant
Dim Tableau(1 To Combien) As Variant Select Case Deci Case False For i = 1 To Combien Rand = Int((High - Low + 1) * Rnd) + Low Tableau(i) = Rand Next i Case Else For i = 1 To Combien Rand = ((High - Low + 1) * Rnd) + Low Tableau(i) = Rand Next i End Select
End Function
Je n'arrive pas à afficher les nombres sur ma form1.
Hello, ça marchera mieux comme ceci:
Public Function Rand(ByRef Tableau() As Variant, ByVal Low As Long, ByVal High As Long, ByVal Deci As Boolean, ByVal Combien As Integer) As Variant
ReDim Tableau(1 To Combien) Dim i As Long
Select Case Deci Case False For i = 1 To Combien Rand = Int((High - Low + 1) * Rnd) + Low Tableau(i) = Rand Next i Case Else For i = 1 To Combien Rand = ((High - Low + 1) * Rnd) + Low Tableau(i) = Rand Next i End Select End Function
Et l'appel:
Dim t() As Variant
Rand t(), 1, 100, False, 10
Jean-Marc
Oui c'est sur. J'ai même pas regardé le type de retour quand j'ai corrigé la fonction! Dans ce cas d'ailleurs, le meilleur choix est une fonction qui retourne juste un booléen histoire de dire que tout est ok, qq chose comme:
Public Function Rand(ByVal Low As Long, ByVal High As Long, ByVal Deci As Boolean, ByVal Combien As Integer) As Boolean ' .. declaration On error goto Err_Rand ' .. code
Rand = TRue Sortie_OK: exit function Err_Rand: Rand = False Resume Sortie_OK End Function
puis
Dim Result as Boolean
Result = Rand(.., .., ..) If result Then ' OK Else ' something goes wrong ' error handling ... End If
-- Jean-marc "There are only 10 kind of people those who understand binary and those who don't."
"ng" a écrit dans le message de news:
Salut,
Je te conseillerai en outre de typer correctement ton retour de fonction (éviter le Variant !).
-- Nicolas G. FAQ VB : http://faq.vb.free.fr API Guide : http://www.allapi.net Google Groups : http://groups.google.fr/ MZ-Tools : http://www.mztools.com/
Jean-Marc wrote: > "scalpa" a écrit dans le message de > news: >> peut on créer un module de classe qui fabriquerait des nombres >> aléatoires et les renverrai dans un tableau ? j'ai essayé ceci mais >> ca ne marche pas... >> >> Public Function Rand(ByVal Low As Long, ByVal High As Long, ByVal >> Deci As Boolean, ByVal Combien As Integer) As Variant >> >> Dim Tableau(1 To Combien) As Variant >> Select Case Deci >> Case False >> For i = 1 To Combien >> Rand = Int((High - Low + 1) * Rnd) + Low >> Tableau(i) = Rand >> Next i >> Case Else >> For i = 1 To Combien >> Rand = ((High - Low + 1) * Rnd) + Low >> Tableau(i) = Rand >> Next i >> End Select >> >> End Function >> >> Je n'arrive pas à afficher les nombres sur ma form1. > > Hello, ça marchera mieux comme ceci: > > > Public Function Rand(ByRef Tableau() As Variant, ByVal Low As Long, > ByVal High As Long, ByVal Deci As Boolean, ByVal Combien As Integer) > As Variant > > ReDim Tableau(1 To Combien) > Dim i As Long > > Select Case Deci > Case False > For i = 1 To Combien > Rand = Int((High - Low + 1) * Rnd) + Low > Tableau(i) = Rand > Next i > Case Else > For i = 1 To Combien > Rand = ((High - Low + 1) * Rnd) + Low > Tableau(i) = Rand > Next i > End Select > End Function > > Et l'appel: > > Dim t() As Variant > > Rand t(), 1, 100, False, 10
Oui c'est sur. J'ai même pas regardé le type de retour quand j'ai
corrigé la fonction! Dans ce cas d'ailleurs, le meilleur choix est une
fonction qui retourne juste un booléen histoire de dire que tout est
ok, qq chose comme:
Public Function Rand(ByVal Low As Long, ByVal High As Long, ByVal
Deci As Boolean, ByVal Combien As Integer) As Boolean
' .. declaration
On error goto Err_Rand
' .. code
Rand = TRue
Sortie_OK:
exit function
Err_Rand:
Rand = False
Resume Sortie_OK
End Function
puis
Dim Result as Boolean
Result = Rand(.., .., ..)
If result Then
' OK
Else
' something goes wrong
' error handling ...
End If
--
Jean-marc
"There are only 10 kind of people
those who understand binary and those who don't."
"ng" <ng@ngsoft-fr.com> a écrit dans le message de
news:OMMMQNK1EHA.1308@TK2MSFTNGP09.phx.gbl...
Salut,
Je te conseillerai en outre de typer correctement ton retour de fonction
(éviter le Variant !).
--
Nicolas G.
FAQ VB : http://faq.vb.free.fr
API Guide : http://www.allapi.net
Google Groups : http://groups.google.fr/
MZ-Tools : http://www.mztools.com/
Jean-Marc wrote:
> "scalpa" <scalpaNoSpam@wanadoo.fr> a écrit dans le message de
> news:eM7o8CK1EHA.3452@TK2MSFTNGP14.phx.gbl...
>> peut on créer un module de classe qui fabriquerait des nombres
>> aléatoires et les renverrai dans un tableau ? j'ai essayé ceci mais
>> ca ne marche pas...
>>
>> Public Function Rand(ByVal Low As Long, ByVal High As Long, ByVal
>> Deci As Boolean, ByVal Combien As Integer) As Variant
>>
>> Dim Tableau(1 To Combien) As Variant
>> Select Case Deci
>> Case False
>> For i = 1 To Combien
>> Rand = Int((High - Low + 1) * Rnd) + Low
>> Tableau(i) = Rand
>> Next i
>> Case Else
>> For i = 1 To Combien
>> Rand = ((High - Low + 1) * Rnd) + Low
>> Tableau(i) = Rand
>> Next i
>> End Select
>>
>> End Function
>>
>> Je n'arrive pas à afficher les nombres sur ma form1.
>
> Hello, ça marchera mieux comme ceci:
>
>
> Public Function Rand(ByRef Tableau() As Variant, ByVal Low As Long,
> ByVal High As Long, ByVal Deci As Boolean, ByVal Combien As Integer)
> As Variant
>
> ReDim Tableau(1 To Combien)
> Dim i As Long
>
> Select Case Deci
> Case False
> For i = 1 To Combien
> Rand = Int((High - Low + 1) * Rnd) + Low
> Tableau(i) = Rand
> Next i
> Case Else
> For i = 1 To Combien
> Rand = ((High - Low + 1) * Rnd) + Low
> Tableau(i) = Rand
> Next i
> End Select
> End Function
>
> Et l'appel:
>
> Dim t() As Variant
>
> Rand t(), 1, 100, False, 10
Oui c'est sur. J'ai même pas regardé le type de retour quand j'ai corrigé la fonction! Dans ce cas d'ailleurs, le meilleur choix est une fonction qui retourne juste un booléen histoire de dire que tout est ok, qq chose comme:
Public Function Rand(ByVal Low As Long, ByVal High As Long, ByVal Deci As Boolean, ByVal Combien As Integer) As Boolean ' .. declaration On error goto Err_Rand ' .. code
Rand = TRue Sortie_OK: exit function Err_Rand: Rand = False Resume Sortie_OK End Function
puis
Dim Result as Boolean
Result = Rand(.., .., ..) If result Then ' OK Else ' something goes wrong ' error handling ... End If
-- Jean-marc "There are only 10 kind of people those who understand binary and those who don't."
"ng" a écrit dans le message de news:
Salut,
Je te conseillerai en outre de typer correctement ton retour de fonction (éviter le Variant !).
-- Nicolas G. FAQ VB : http://faq.vb.free.fr API Guide : http://www.allapi.net Google Groups : http://groups.google.fr/ MZ-Tools : http://www.mztools.com/
Jean-Marc wrote: > "scalpa" a écrit dans le message de > news: >> peut on créer un module de classe qui fabriquerait des nombres >> aléatoires et les renverrai dans un tableau ? j'ai essayé ceci mais >> ca ne marche pas... >> >> Public Function Rand(ByVal Low As Long, ByVal High As Long, ByVal >> Deci As Boolean, ByVal Combien As Integer) As Variant >> >> Dim Tableau(1 To Combien) As Variant >> Select Case Deci >> Case False >> For i = 1 To Combien >> Rand = Int((High - Low + 1) * Rnd) + Low >> Tableau(i) = Rand >> Next i >> Case Else >> For i = 1 To Combien >> Rand = ((High - Low + 1) * Rnd) + Low >> Tableau(i) = Rand >> Next i >> End Select >> >> End Function >> >> Je n'arrive pas à afficher les nombres sur ma form1. > > Hello, ça marchera mieux comme ceci: > > > Public Function Rand(ByRef Tableau() As Variant, ByVal Low As Long, > ByVal High As Long, ByVal Deci As Boolean, ByVal Combien As Integer) > As Variant > > ReDim Tableau(1 To Combien) > Dim i As Long > > Select Case Deci > Case False > For i = 1 To Combien > Rand = Int((High - Low + 1) * Rnd) + Low > Tableau(i) = Rand > Next i > Case Else > For i = 1 To Combien > Rand = ((High - Low + 1) * Rnd) + Low > Tableau(i) = Rand > Next i > End Select > End Function > > Et l'appel: > > Dim t() As Variant > > Rand t(), 1, 100, False, 10
scalpa
bonjour pourquoi éviter le variant ? merci
Je te conseillerai en outre de typer correctement ton retour de fonction (éviter le Variant !).
bonjour pourquoi éviter le variant ? merci
Je te conseillerai en outre de typer correctement ton retour de fonction
(éviter le Variant !).
Je te conseillerai en outre de typer correctement ton retour de fonction (éviter le Variant !).
scalpa
merci de votre aide je vais étudier tout ça !! Je ferai aussi un essai avec property... Je ne comprends pas la différence entre les deux solutions.....functiun ou property ?
merci de votre aide je vais étudier tout ça !!
Je ferai aussi un essai avec property...
Je ne comprends pas la différence entre les deux solutions.....functiun ou
property ?
merci de votre aide je vais étudier tout ça !! Je ferai aussi un essai avec property... Je ne comprends pas la différence entre les deux solutions.....functiun ou property ?
Patrice Henrio
Le variant est un type qui peut recevoir n'importe quel type donc on imagine que nécessairement le traitement afférent sera plus long : vérification du type, adressage par adresse même pour des byte ou des integer ...alors qu'avec un type défini, la vérification se fait lors de la compilation avec même le transtypage nécessaire en cas de besoin.
"scalpa" a écrit dans le message de news: 41ac8506$0$30416$
bonjour pourquoi éviter le variant ? merci
Je te conseillerai en outre de typer correctement ton retour de fonction (éviter le Variant !).
Le variant est un type qui peut recevoir n'importe quel type donc on imagine
que nécessairement le traitement afférent sera plus long : vérification du
type, adressage par adresse même pour des byte ou des integer ...alors
qu'avec un type défini, la vérification se fait lors de la compilation avec
même le transtypage nécessaire en cas de besoin.
"scalpa" <scalpa@wanadoo.fr> a écrit dans le message de news:
41ac8506$0$30416$8fcfb975@news.wanadoo.fr...
bonjour pourquoi éviter le variant ? merci
Je te conseillerai en outre de typer correctement ton retour de fonction
(éviter le Variant !).
Le variant est un type qui peut recevoir n'importe quel type donc on imagine que nécessairement le traitement afférent sera plus long : vérification du type, adressage par adresse même pour des byte ou des integer ...alors qu'avec un type défini, la vérification se fait lors de la compilation avec même le transtypage nécessaire en cas de besoin.
"scalpa" a écrit dans le message de news: 41ac8506$0$30416$
bonjour pourquoi éviter le variant ? merci
Je te conseillerai en outre de typer correctement ton retour de fonction (éviter le Variant !).