Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use of Functions
#36
I hope the translation is understandable. I didn't find any errors in the calculation.  Rolleyes

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]
Reply


Messages In This Thread
Use of Functions - by PhilOfPerth - 05-20-2025, 11:21 PM
RE: Use of Functions - by bplus - 05-20-2025, 11:24 PM
RE: Use of Functions - by ahenry3068 - 05-20-2025, 11:34 PM
RE: Use of Functions - by PhilOfPerth - 05-21-2025, 12:25 AM
RE: Use of Functions - by bplus - 05-21-2025, 12:39 AM
RE: Use of Functions - by PhilOfPerth - 05-21-2025, 01:33 AM
RE: Use of Functions - by SMcNeill - 05-21-2025, 02:33 AM
RE: Use of Functions - by PhilOfPerth - 05-21-2025, 04:24 AM
RE: Use of Functions - by ahenry3068 - 05-21-2025, 06:41 AM
RE: Use of Functions - by bplus - 05-21-2025, 09:12 AM
RE: Use of Functions - by SMcNeill - 05-21-2025, 09:45 AM
RE: Use of Functions - by bplus - 05-21-2025, 11:23 AM
RE: Use of Functions - by bplus - 05-21-2025, 11:35 AM
RE: Use of Functions - by Kernelpanic - 05-22-2025, 03:00 PM
RE: Use of Functions - by bplus - 05-21-2025, 11:41 AM
RE: Use of Functions - by SMcNeill - 05-21-2025, 11:45 AM
RE: Use of Functions - by bplus - 05-21-2025, 11:55 AM
RE: Use of Functions - by TempodiBasic - 05-21-2025, 12:06 PM
RE: Use of Functions - by mdijkens - 05-21-2025, 12:11 PM
RE: Use of Functions - by TempodiBasic - 05-21-2025, 08:40 PM
RE: Use of Functions - by Dimster - 05-21-2025, 03:34 PM
RE: Use of Functions - by Kernelpanic - 05-21-2025, 06:01 PM
RE: Use of Functions - by CharlieJV - 05-22-2025, 02:37 AM
RE: Use of Functions - by hsiangch_ong - 05-22-2025, 03:30 PM
RE: Use of Functions - by PhilOfPerth - 05-22-2025, 10:22 PM
RE: Use of Functions - by bplus - 05-22-2025, 11:37 PM
RE: Use of Functions - by madscijr - 05-23-2025, 12:34 AM
RE: Use of Functions - by bplus - 05-23-2025, 10:29 AM
RE: Use of Functions - by bplus - 05-23-2025, 10:49 AM
RE: Use of Functions - by bplus - 05-23-2025, 11:22 AM
RE: Use of Functions - by PhilOfPerth - 05-23-2025, 10:16 PM
RE: Use of Functions - by Pete - 05-23-2025, 10:55 PM
RE: Use of Functions - by madscijr - 05-24-2025, 03:10 AM
RE: Use of Functions - by OldMoses - 05-25-2025, 06:05 PM
RE: Use of Functions - by eoredson - 05-26-2025, 08:59 PM
RE: Use of Functions - by PhilOfPerth - 05-28-2025, 03:32 AM
RE: Use of Functions - by Kernelpanic - 05-26-2025, 11:47 PM
RE: Use of Functions - by Pete - 05-27-2025, 11:25 PM
RE: Use of Functions - by bplus - 05-28-2025, 06:17 AM
RE: Use of Functions - by PhilOfPerth - 05-28-2025, 09:11 AM
RE: Use of Functions - by bplus - 05-28-2025, 09:17 AM
RE: Use of Functions - by PhilOfPerth - 05-28-2025, 09:22 AM
RE: Use of Functions - by SMcNeill - 05-28-2025, 09:53 AM
RE: Use of Functions - by PhilOfPerth - 05-28-2025, 10:59 AM
RE: Use of Functions - by Kernelpanic - 05-28-2025, 05:08 PM
RE: Use of Functions - by TempodiBasic - 05-28-2025, 10:18 PM
RE: Use of Functions - by Pete - 05-29-2025, 12:08 AM
RE: Use of Functions - by Pete - 05-29-2025, 12:22 AM
RE: Use of Functions - by PhilOfPerth - 05-29-2025, 02:02 AM
RE: Use of Functions - by PhilOfPerth - 05-29-2025, 02:42 AM
RE: Use of Functions - by SMcNeill - 05-29-2025, 02:38 AM
RE: Use of Functions - by Pete - 05-29-2025, 06:52 PM
RE: Use of Functions - by Kernelpanic - 05-29-2025, 08:21 PM
RE: Use of Functions - by TempodiBasic - 05-30-2025, 01:49 PM



Users browsing this thread: 2 Guest(s)