Leren programmeren: bewerkingen


Private Sub cmdbereken_Click()
Dim getal1 As Single
Dim getal2 As Single
Dim bericht As String

If Not IsNumeric(txtGetal1.Text) Then Exit Sub

getal1 = CSng(txtGetal1.Text)

If Not IsNumeric(txtGetal2.Text) Then Exit Sub

getal2 = CSng(txtGetal2.Text)
bericht = getal1 & " + " & getal2 & " = " & getal1 + getal2 & vbCrLf
bericht = bericht & getal1 & " - " & getal2 & " = " & getal1 - getal2 & vbCrLf
bericht = bericht & getal1 & " * " & getal2 & " = " & getal1 * getal2 & vbCrLf
'Alleen delen indien de deler niet nul is
If Not getal2 = 0 then bericht = bericht & getal1 & " * " & getal2 & " = " & getal1 * getal2 & vbCrLf
If Not getal2 = 0 then bericht = bericht & getal1 & " modulus " & getal2 & " = " & getal1 Mod getal2 & vbCrLf
'Alleen machtsverheffing proberen indien mogelijk
If Not getal2 < 0 then bericht = bericht & getal1 & " ^ " & getal2 & " = " & getal1 ^ getal2 & vbCrLf
End Sub


[VB Web] - [Leren programmeren] - [hlrnet] - [copyright]