05-21-2025, 06:01 PM
(This post was last modified: 05-21-2025, 06:05 PM by Kernelpanic.)
Functions can, of course, also be passed to procedures (subs) as arguments. Just as functions can be passed to functions as arguments. This is usually done to save code lines. However, for people unfamiliar with this, it's difficult to understand.
Functions can also produce more than one output, but only return one. (Uploading an image isn't working right now.)
It looks pretty confusing, but it works.
Code: (Select All)
Option _Explicit
Declare Function funcEndpreis(kaufpreis, mehrwertSteuer As Double) As Double
Declare Sub subEndpreis(eingabe As Double)
Dim As Double kaufpreis, mehrwertSteuer
Locate 2, 3
Input "Kaufpreis : ", kaufpreis
Locate 3, 3
Input "Mehrwertsteuer: ", mehrwertSteuer
Locate 4, 3
Print "----------------------"
Locate 6, 3
Print "Endpreis mit Funktion"
Locate 7, 3
Print Using "Der Endpreis betraegt: ####,#.## Euro"; funcEndpreis(kaufpreis, mehrwertSteuer)
Locate 9, 3
Print "Endpreis mit Prozedur/Sub"
Locate 10, 3
'Function as an argument to a sub
Call subEndpreis(funcEndpreis(kaufpreis, mehrwertSteuer))
End
Sub subEndpreis (eingabe As Double)
'Da braucht man keine neue Variable!
Print Using "Der Endpreis betraegt: ####,#.## Euro"; eingabe
End Sub
Function funcEndpreis (kaufpreis, mehrwertSteuer As Double)
Dim As Double gesamtpreis
gesamtpreis = kaufpreis + ((kaufpreis * mehrwertSteuer) / 100)
funcEndpreis = gesamtpreis
End Function
Functions can also produce more than one output, but only return one. (Uploading an image isn't working right now.)
Code: (Select All)
Function funcEndpreis (kaufpreis, mehrwertSteuer As Double)
Dim As Double gesamtpreis, fool
fool = kaufpreis * 1.5
Print fool
gesamtpreis = kaufpreis + ((kaufpreis * mehrwertSteuer) / 100)
funcEndpreis = gesamtpreis
End Function
It looks pretty confusing, but it works.