Public Function Test_Per(Tableau) As Integer
Dim Entven As Integer
Dim Pdd As Integer
Dim PerEVen As Double
Dim PerOdd As Double
Even = 0
Pdd = 0
I = 0
Do While Tableau(I) <> -1
If Tableau(I) Mod 2 = 1 Then Pdd = Pdd + 1
If Tableau(I) Mod 2 = 0 Then Entven = Entven + 1
I = I + 1
Loop
MsgBox "Il y a respectivement " & Entven & " nombres pairs de pourcentage " & Entven / I & " et " & Pdd & " nombres impairs de pourcentage " & Pdd / I
End Function
Sub test_function()
T = Array(1, 8, 20, 50, 51, 47, 6, -6, -7, 9, 3, -1)
Test_Per (T)
End Sub
Non il n'est pas vide.Bonjour à tous,
Il me semble que ton fichier est "vide"
JHA
Public Function Test_Per(Tableau) As Integer
Dim Entven As Integer
Dim Pdd As Integer
Dim PerEVen As Double
Dim PerOdd As Double
Even = 0
Pdd = 0
I = 0
Do While Tableau(I) <> -1
If Tableau(I) Mod 2 = 1 Then Pdd = Pdd + 1
If Tableau(I) Mod 2 = 0 Then Entven = Entven + 1
I = I + 1
Loop
MsgBox "Il y a respectivement " & Entven & " nombres pairs de pourcentage " & Entven / I & " et " & Pdd & " nombres impairs de pourcentage " & Pdd / I
End Function
Sub test_function()
T = Array(1, 8, 20, 50, 51, 47, 6, -6, -7, 9, 3, -1)
Test_Per (T)
End Sub
Merci beaucoupBonjour le fil
@Excellearning pour transmettre un tableau dans une fonction il faut que ce soit définit correctement
VB:Public Function Test_Per(Tableau) As Integer Dim Entven As Integer Dim Pdd As Integer Dim PerEVen As Double Dim PerOdd As Double Even = 0 Pdd = 0 I = 0 Do While Tableau(I) <> -1 If Tableau(I) Mod 2 = 1 Then Pdd = Pdd + 1 If Tableau(I) Mod 2 = 0 Then Entven = Entven + 1 I = I + 1 Loop MsgBox "Il y a respectivement " & Entven & " nombres pairs de pourcentage " & Entven / I & " et " & Pdd & " nombres impairs de pourcentage " & Pdd / I End Function Sub test_function() T = Array(1, 8, 20, 50, 51, 47, 6, -6, -7, 9, 3, -1) Test_Per (T) End Sub
A+
Option Explicit
Sub somme()
Dim c As Long, s As Long, i As Long
c = 2: s = 0
For i = c To 99 Step 3
s = s + i
MsgBox "(" & s & " , " & i & ")"
Next i
MsgBox "La somme est :" & s
End Sub
Sub Palindrome()
Dim s As String
s = LCase(Trim(InputBox("Entrer un texte :")))
If s = "" Then Exit Sub
If s = StrReverse(s) Then MsgBox "Le texte " & s & " est un palindrome." Else MsgBox "Le texte " & s & " n'est un palindrome."
End Sub
Public Sub Test_Per(Tableau)
Dim PairS As Long, Impairs As Long, x
For Each x In Tableau
If x = -1 Then Exit For
If x Mod 2 = 0 Then PairS = PairS + 1 Else Impairs = Impairs + 1
Next x
MsgBox "Il y a " & PairS & " nombres pairs (" & Format(PairS / (PairS + Impairs), ".0%") & ")" & vbLf & _
"Il y a " & Impairs & " nombres impairs (" & Format(Impairs / (PairS + Impairs), ".0%") & ")"
End Sub
Sub test_function()
Dim T
T = Array(1, 8, 20, 50, 51, 47, 6, -6, -7, 9, 3, -1)
Test_Per T
End Sub
Merci beaucoupBonjour à tous,
Pour le fun, le code à ma sauce .
La fonction Test_Per ne sert à rien puisqu'elle ne renvoie rien. Autant la transformer en Sub(). Cela ne change en rien la manière de passer un tableau dans une fonction ou sub.
Le code:
Code:Option Explicit Sub somme() Dim c As Long, s As Long, i As Long c = 2: s = 0 For i = c To 99 Step 3 s = s + i MsgBox "(" & s & " , " & i & ")" Next i MsgBox "La somme est :" & s End Sub Sub Palindrome() Dim s As String s = LCase(Trim(InputBox("Entrer un texte :"))) If s = "" Then Exit Sub If s = StrReverse(s) Then MsgBox "Le texte " & s & " est un palindrome." Else MsgBox "Le texte " & s & " n'est un palindrome." End Sub Public Sub Test_Per(Tableau) Dim PairS As Long, Impairs As Long, x For Each x In Tableau If x = -1 Then Exit For If x Mod 2 = 0 Then PairS = PairS + 1 Else Impairs = Impairs + 1 Next x MsgBox "Il y a " & PairS & " nombres pairs (" & Format(PairS / (PairS + Impairs), ".0%") & ")" & vbLf & _ "Il y a " & Impairs & " nombres impairs (" & Format(Impairs / (PairS + Impairs), ".0%") & ")" End Sub Sub test_function() Dim T T = Array(1, 8, 20, 50, 51, 47, 6, -6, -7, 9, 3, -1) Test_Per T End Sub