05-26-2025, 11:47 PM
(This post was last modified: 05-27-2025, 11:59 AM by Kernelpanic.)
I hope the translation is understandable. I didn't find any errors in the calculation.
Here is a practical example of a function as an argument for a function as argument passed to a procedure/sub (two arguments). The final price including VAT is calculated once, followed by the final price including the discount.
Since a discount isn't always granted, it's calculated in a separate function.
PS: Small improvement in case there is no discount. - 27. Mai 2025

Here is a practical example of a function as an argument for a function as argument passed to a procedure/sub (two arguments). The final price including VAT is calculated once, followed by the final price including the discount.
Since a discount isn't always granted, it's calculated in a separate function.
PS: Small improvement in case there is no discount. - 27. Mai 2025
Code: (Select All)
'Beispiel fuer SUB und Funktionen - 23. Jan. 2024
'Eine Funktion kann auch als Argument an ein SUB uebergeben werden.
'Rabattberechnung hinzugefuegt fuer Beispiel - 26. Mai 2025
Option _Explicit
Declare Function funcEndpreis(kaufpreis, mehrwertSteuer As Double) As Double
Declare Function endpreisRabatt(endpreisOhneRabatt,rabatt As Doeble) As Double
Declare Sub subEndpreisMit(endpreisOhneRabatt, rabatt As Double)
Dim As Double kaufpreis, mehrwertSteuer, rabatt
Locate 2, 3
Input "Kaufpreis : ", kaufpreis
Locate 3, 3
Input "Mehrwertsteuer in Prozent % : ", mehrwertSteuer
Locate 4, 3
Input "Rabatt in Prozent % (Ohne = 0): ", rabatt
Locate 5, 3
Print "---------------------------------------"
Locate 7, 3
Print Using "Der Endpreis ohne Rabatt betraegt: ####,#.## Euro"; funcEndpreis(kaufpreis, mehrwertSteuer)
Locate 9, 3
'Function as an argument to a sub
Call subEndpreisMit(funcEndpreis(kaufpreis, mehrwertSteuer), endpreisRabatt(funcEndpreis(kaufpreis, mehrwertSteuer), rabatt))
End
Sub subEndpreisMit (endpreisOhneRabatt, rabatt As Double)
Dim As Double endpreisMitRabatt
If rabatt = 0 Then
Print "Kein Rabatt!"
Else
endpreisMitRabatt = endpreisOhneRabatt - rabatt
Print Using "Der Endpreis mit Rabatt betraegt : ####,#.## Euro"; endpreisMitRabatt
End If
End Sub
Function funcEndpreis (kaufpreis, mehrwertSteuer As Double)
Dim As Double gesamtpreis
gesamtpreis = kaufpreis + ((kaufpreis * mehrwertSteuer) / 100)
funcEndpreis = gesamtpreis
End Function
Function endpreisRabatt (endpreisOhneRabatt, rabatt As Double)
Dim As Double rabattBetrag
rabattBetrag = ((endpreisOhneRabatt * rabatt) / 100)
endpreisRabatt = rabattBetrag
End Function
![[Image: Funktion-In-Funktion-Sub2025-05-27.jpg]](https://i.ibb.co/60WXXmzT/Funktion-In-Funktion-Sub2025-05-27.jpg)