juvamine
Messages postés468Date d'inscriptionvendredi 21 février 2003StatutMembreDernière intervention30 août 20072 15 oct. 2004 à 09:41
non il fo mouliner:
max=0
for i=1 to ubound(data)
if data(i)>max then max=data(i)
next i
msgbox max
voila
A+
juva
BTS IG, développeurs, et tout le monde ! venez faire un tour sur http://www.webhelp-ig.com Retrouvez une équipe de développeurs confirmés sur le tchate:
serveur : bastia.zefunChat.net
port : 6667
chan : #programmation
jrivet
Messages postés7392Date d'inscriptionmercredi 23 avril 2003StatutMembreDernière intervention 6 avril 201260 15 oct. 2004 à 10:04
Salut, ben pour min tu fais presque la meme chose mais apres avoir trouve le MAX
max=0
for i=1 to ubound(data)
if data(i)>max then max=data(i)
next i
msgbox max
Min=Max
for i=1 to ubound(data)
if data(i)<min then min=data(i)
next i
msgbox min
Je pense que ca devrait marcher
@+
Julien
-----------------------------------------------------------
:big) Essai ca sinon on trouvera autre chose ;)
-----------------------------------------------------------
Renfield
Messages postés17287Date d'inscriptionmercredi 2 janvier 2002StatutModérateurDernière intervention27 septembre 202174 15 oct. 2004 à 10:46
Je suis pas d'accord !!!!
<s>max=0</s>
max=data(1)
for i=2 to ubound(data)
if data(i)>max then max=data(i)
next i
msgbox max
et le min :
<s>Min=Max</s>
min=data(1)
for i=2 to ubound(data)
if data(i)<min then min=data(i)
next i
msgbox min
soit sous forme de fonction :
Public Sub MinMax(ByRef Min, ByRef Max, Values() As Long)
Max = Values(LBound(Values))
Min = Values(LBound(Values))
Dim i As Integer
For i = LBound(Values) + 1 To UBound(Values)
If Max < Values(i) Then Max = Values(i)
If Min > Values(i) Then Min = Values(i)
Next i
End Sub
Private Sub Form_Load()
Dim Values(4) As Long
Values(0) = 5
Values(1) = 7
Values(2) = 3
Values(3) = 8
Values(4) = 2
Dim Min As Long
Dim Max As Long
MinMax Min, Max, Values
MsgBox "MIN : " & Min & vbNewLine & "MAX : " & Max
End Sub
Gobillot
Messages postés3140Date d'inscriptionvendredi 14 mai 2004StatutMembreDernière intervention11 mars 201934 15 oct. 2004 à 10:53
Pour éviter de faire 2 boucles, il faut donner à min au départ une valeur la plus grande possible, de même max doit être initialisé à la valeur la plus petite.
max=-32768
min=32767
for i=1 to ubound(data)
if data(i)>max then max=data(i)
if data(i)<min then min=data(i)
next i
jrivet
Messages postés7392Date d'inscriptionmercredi 23 avril 2003StatutMembreDernière intervention 6 avril 201260 15 oct. 2004 à 11:15
-> Renfield:
Bien Vu, effectivement on prenait pas en compte les negatifs...
Quelle erreur ;)
@+
Julien
-----------------------------------------------------------
:big) Essai ca sinon on trouvera autre chose ;)
-----------------------------------------------------------
Gobillot
Messages postés3140Date d'inscriptionvendredi 14 mai 2004StatutMembreDernière intervention11 mars 201934 15 oct. 2004 à 15:00
>>Renfield
En effet j'ai pris Integer en exemple ce qui oblige à changer de valeur en fonction du type.
Je reconnais ta méthode est mieux, en prenant une valeur existante, pourquoi pas la première, ce qui permet de commencer la boucle à la deuxième position.
mais quand j'ai posté mon post, j'ai du te croiser et j'avais pas vu ta méthode.
Gobillot
Messages postés3140Date d'inscriptionvendredi 14 mai 2004StatutMembreDernière intervention11 mars 201934 15 oct. 2004 à 22:23
On va pas chicaner, la dernière valeur convient aussi, une valeur intermédiaire serait moins pratique.
Max = Values(UBound(Values))
Min = Values(UBound(Values))
Dim i As Integer
For i = LBound(Values) To UBound(Values)-1
If Max < Values(i) Then Max = Values(i)
If Min > Values(i) Then Min = Values(i)
Next i
End Sub