01-23-2024, 09:56 PM
(This post was last modified: 01-23-2024, 09:59 PM by Kernelpanic.)
Quote:@MichelleL - I will confess, I have never used a SUB or a FUNCTION . . .Finally something for fun and play again.
Examples of sub and function. One can also pass a function as an argument to a sub. - You should stop using GoSub these days and replace it with S&F; QuickBasic was already able to do that from 2.0(?)
kaufpreis = Purchase price
mehrwertSteuer = VAT
Endpreis/Gesamtpreis = Final price (total price)
Code: (Select All)
'Beispiel fuer SUB und Funktionen - 23. Jan. 2024
Option _Explicit
Declare Function Endpreis(kaufpreis, mehrwertSteuer As Double) As Double
Declare Sub auchEndpreis(eingabe As Double)
Dim As Double kaufpreis, mehrwertSteuer
Locate 3, 3
Input "Kaufpreis: ", kaufpreis
Locate 4, 3
Input "Mehrwertsteuer: ", mehrwertSteuer
Locate 6, 3
Print Using "Der Endpreis betraegt: ####,#.## Euro"; Endpreis(kaufpreis, mehrwertSteuer)
Locate 8, 3
'Function as an argument to a sub
Call auchEndpreis(Endpreis(kaufpreis, mehrwertSteuer))
End
Sub auchEndpreis (eingabe As Double)
Dim As Double subGesamtpreis
subGesamtpreis = eingabe
Print Using "Der Endpreis betraegt: ####,#.## Euro"; subGesamtpreis
End Sub
Function Endpreis (kaufpreis, mehrwertSteuer As Double)
Dim As Double gesamtpreis
gesamtpreis = kaufpreis + ((kaufpreis * mehrwertSteuer) / 100)
Endpreis = gesamtpreis
End Function

