Ma "function" s'exécute en boucle
S
Bonjour, j'ai un problème avec une fonction qui s'exécute en boucle lorsque les conditions du premier IF me fond passer au ELSE. Je ne comprend vraiment pas pourquoi, inévitablement, peu importe ce que j'essai, lorsque j'arrive au ELSE ma fonction fait une boucle, et seulement une. ?? À noter, je suis novice en VBA alors si avez des commentaires autres n'hésiter pas. Merci
Function StillWaterSeaPressure(ZoneUnderConsideration As String, z As Double) As Double
Call Val_constante
Dim ExposedDeckLocation As String
Dim Phi As Double
Dim Ps As Double
'Sea water pressure calculation
If ZoneUnderConsideration = "Bottom and side below the waterline" Then
Ps = 1.025 * 9.81 * (T - z)
ElseIf ZoneUnderConsideration = "Side above the waterline" Then
Ps = 0
Else
ExposedDeck.Show 'UserForm: Choose the right exposed deck, then press 'Ok'
ExposedDeck.ExpDeckLoop 'Garde le UserForm affiché tant qu'on n'a pas appuyé sur le bouton 'Ok'
'... à ce point ci je choisi ma valeur qui sera ExposedDeckLocation à partir d'une liste déroulant dans une cellule
ExposedDeckLocation = ActiveCell
'Pressure coefficient on exposed deck
If ExposedDeckLocation = "Freeboard deck" Then
Phi = 1
ElseIf ExposedDeckLocation = "Superstructure deck" Then
Phi = 0.75
ElseIf ExposedDeckLocation = "1st tier of deckhouse" Then
Phi = 0.56
Else
Phi = 0.42
End If
Ps = InputBox("Enter pressure due to load carried on deck :" & vbCrLf & _
"It may not be taken less than " & 10 * Phi & " kN/m²")
End If
StillWaterSeaPressure = Ps
End FunctionBonsoir Sam,
cette partie de ton code est inutile :
ElseIf ZoneUnderConsideration = "Side above the waterline" Then
Ps = 0
Elsecar Ps est déjà à 0 lors de la déclaration avec Dim Ps As Double ; la valeur de retour de la fonction est aussi déjà à 0.
Function StillWaterSeaPressure(ZoneUnderConsideration As String, z As Double) As Double
Call Val_constante
Dim ExposedDeckLocation As String
Dim Phi As Double
Dim Ps As Double
'Sea water pressure calculation
If ZoneUnderConsideration = "Side above the waterline" Then Exit Function
If ZoneUnderConsideration = "Bottom and side below the waterline" Then _
StillWaterSeaPressure = 1.025 * 9.81 * (T - z): Exit Function
ExposedDeck.Show 'UserForm: Choose the right exposed deck, then press 'Ok'
ExposedDeck.ExpDeckLoop 'Garde le UserForm affiché tant qu'on n'a pas appuyé sur le bouton 'Ok'
'à ce point-ci, je choisis ma valeur qui sera ExposedDeckLocation à partir
'd'une liste déroulante dans une cellule
ExposedDeckLocation = ActiveCell
'Pressure coefficient on exposed deck
Select Case ExposedDeckLocation
Case "Freeboard deck": Phi = 1
Case "Superstructure deck": Phi = 0.75
Case "1st tier of deckhouse": Phi = 0.56
Case Else: Phi = 0.42
End Select
Ps = InputBox("Enter pressure due to load carried on deck :" & _
vbCrLf & "It may not be taken less than " & 10 * Phi & " kN/m²")
StillWaterSeaPressure = Ps
End Functiondhany
S
Merci beaucoup pour ta réponse, je vais pouvoir mettre ça en pratique demain. L'utilisation du Select Case aussi, ça devrait alléger mon Module.