| CodeModul, KlassenModul, Function |
| |
| |
| Herkömmliche Realisierung mit Codemodul | Benutzen einer einfachen Klasse |
| ' Referenzierung des Objekts |
| | Private myObj As CRechne |
|
| Private Sub Form_Load() |
| ' Instanzierung des Objekts |
| Set myObj = New CRechne |
| End Sub |
| |
| Private Sub txtTextbox_KeyUp(Index As Integer, _ | Private Sub txtTextBox_KeyUp(Index As Integer, _ |
| KeyCode As Integer, Shift As Integer) | KeyCode As Integer, Shift As Integer) |
| Dim brutt!, nett!, mws! | Dim brutt!, nett!, mws! |
| ' Textfelder => Variablen (Eingabe) | ' Textfelder => Variablen (Eingabe) |
| brutt = Val(txtTextbox(0)) | brutt = Val(txtTextBox(0)) |
| nett = Val(txtTextbox(1)) | nett = Val(txtTextBox(1)) |
| mws = Val(txtTextbox(2)) | mws = Val(txtTextBox(2)) |
| ' Berechnung (Benutzen der Prozeduren des Codemoduls) | ' Berechnung (Benutzen der Methoden des Objekts) |
| Select Case Index | Select Case Index |
| Case 0: nett = netto(brutt, mws) | Case 0: nett = myObj.netto(brutt, mws) |
| Case 1, 2: brutt = brutto(nett, mws) | Case 1, 2: brutt = myObj.brutto(nett, mws) |
| End Select | End Select |
| ' Variablen => Textfelder (Ausgabe) | ' Variablen => Textfelder (Ausgabe) |
| If Index <> 0 Then txtTextbox(0) = Format$(brutt, "#,##0.00") | If Index <> 0 Then txtTextBox(0) = Format$(brutt, "#,##0.00") |
| If Index <> 1 Then txtTextbox(1) = Format$(nett, "#,##0.00") | If Index <> 1 Then txtTextBox(1) = Format$(nett, "#,##0.00") |
| End Sub | End Sub |
| |
| Private Sub txtTextbox_KeyPress(Index As Integer, _ | Private Sub txtTextBox_KeyPress(Index As Integer, _ |
| KeyAscii As Integer) | KeyAscii As Integer) |
| ' korrigiert Dezimalkomma | ' korrigiert Dezimalkomma |
| If KeyAscii = 44 Then KeyAscii = 46 | If KeyAscii = 44 Then KeyAscii = 46 |
| End Sub | End Sub |
| |
| Private Sub cmdEnde_Click() | Private Sub cmdEnde_Click() |
| Unload Me | Unload Me |
| End Sub | End Sub |
| |
| |
| Codemodul | Klassenmodul CRechne |
| Option Explicit | Option Explicit |
| |
| Public Function netto(brutto As Single, mwst As Single) _ | Public Function netto(brutto As Single, mwst As Single) _ |
| As Single | As Single |
| ' Funktionsname wird zugewiesen | netto = brutto / (1 + mwst) |
| netto = brutto / (1 + mwst) | End Function |
| End Function | |
| |
| Public Function brutto(netto As Single, mwst As Single) _ | Public Function brutto(netto As Single, mwst As Single) _ |
| As Single | As Single |
| ' Funktionsname wird zugewiesen | brutto = netto * (1 + mwst) |
| brutto = netto * (1 + mwst) | End Function |
| End Function |  |
| |
| |
| |
| |
| |
| . |
| |