Option Compare Database
Option Explicit
'Taschenrechner
Dim gmDezimal As Integer
Dim gmOperator As Double
Function Clear() '********************
'** Alles Löschen **
'********************
Dim f As Form
Set f = Forms!Taschenrechner
f!memoryfield = 0
f!Anzeige = 0
f!zeichen = ""
f!operator = 0
gmDezimal = 0
End Function
Function ziffern(z As Integer) '********************
'** Dezimalstellen **
Dim f As Form '********************
Set f = Forms!Taschenrechner
Dim g As Integer
If gmDezimal >= 1 Then
f!Anzeige = f!Anzeige + z / (10 ^ gmDezimal)
gmDezimal = gmDezimal + 1
Else
f!Anzeige = z + 10 * f!Anzeige
End If
End Function
Function rad() '*******************
'** Wurzelziehen **
'*******************
Dim x As Form
Set x = Forms!Taschenrechner
x!zeichen = "rad"
x!operator = x!operator & Sqr(x!Anzeige)
x!Anzeige = ""
End Function
Function rechnen(q As String)
Dim g As Integer
'********************
'** Rechnen **
'********************
Dim f As Form
Set f = Forms!Taschenrechner
gmDezimal = 0
If f!operator = 0 Or f!operator = "" Or f!operator = Null Then
f!operator = f!Anzeige & q
Else
f!operator = f!operator & f!Anzeige & q
End If
f!Anzeige = 0
End Function
Function result()
Dim f As Form
Dim str_Rechnen As String ' Länge der Zeichenfolge
Dim arr_Rechnen() As String 'Array
Dim len_Rechnen As Long 'Langzahlen
Dim operand As Boolean 'Zahl oder Rechenzeichen
Dim arr_Position As Integer 'Zahlen
Dim i As Integer 'Variable definieren
Dim msg As String
Dim o As Integer 'Variable definieren
Set f = Forms!Taschenrechner
f!operator = f!operator & f!Anzeige 'weiterführende Rechnung
str_Rechnen = f!operator 'Ganze Rechnung?
ReDim arr_Rechnen(len_Rechnen)
arr_Position = 0 'Anfang
For i = 1 To len_Rechnen
If i = 1 Or Mid(str_Rechnen, i, 1) = "," Then 'ertes Zeichen oder "," gehört immer zum operand deshalb operand immer True
operand = True
ElseIf operand = False Then 'Rechenzeichen
operand = True ' nach einem operator kommt immer ein operand
arr_Position = arr_Position + 1 'Ein Schritt weiter
Else
operand = IsNumeric(Mid(str_Rechnen, i, 1)) 'wird überprüft ob Zeichen Zahl ist
End If
If operand = True Then 'Dezimalzahl festlegen
If Mid(str_Rechnen, i, 1) = "," Then 'wenn ein komma getippt wird
arr_Rechnen(arr_Position) = arr_Rechnen(arr_Position) & "." 'Dann mit Punkt statt Komma rechnen
Else
arr_Rechnen(arr_Position) = arr_Rechnen(arr_Position) & Mid(str_Rechnen, i, 1) 'Wenn Zeichen eine Zahl dann ist sie dem gleichen Array angefügt
End If
Else 'ist ein operator Array wir um 1 erhöht und operator dem Array zugefügt
arr_Position = arr_Position + 1 'Ein Schritt weiter wenn kein Komma
arr_Rechnen(arr_Position) = Mid(str_Rechnen, i, 1)
End If
Next i
'Ausgabe zur Überprüfung des Arrays
For i = 0 To arr_Position
msg = msg & i & ": " & arr_Rechnen(i) & vbCrLf
Next i
Debug.Print (msg)
'*******
For i = 0 To arr_Position 'In dieser Schleife wird die Rechung gurchgeführt
If arr_Rechnen(i) = "*" Or arr_Rechnen(i) = "/" Then 'Wegen punkt vor strich muss zuerst * oder / gerechnet werden wenn das zutrifft, nimmt er den operand vor und nachdem operator und rechnet
'danach wird das Ergebnis auf die Position auf des ersten Operanten ins Array geschrieben
If arr_Rechnen(i) = "*" Then
o = i - 1
Do Until arr_Rechnen(o) <> "" 'Wenn Operant = "" dann ArrPosition zurück
o = o - 1
Loop
arr_Rechnen(o) = Str(Val(arr_Rechnen(o)) * Val(arr_Rechnen(i + 1)))
arr_Rechnen(i) = ""
arr_Rechnen(i + 1) = ""
Else
o = i - 1
Do Until arr_Rechnen(o) <> ""
o = o - 1
Loop
arr_Rechnen(o) = Str(Val(arr_Rechnen(o)) / Val(arr_Rechnen(i + 1)))
arr_Rechnen(i) = ""
arr_Rechnen(i + 1) = ""
End If
End If
Next i
For i = 0 To arr_Position
msg = msg & i & ": " & arr_Rechnen(i) & vbCrLf
Next i
Debug.Print (msg)
For i = 0 To arr_Position
If arr_Rechnen(i) = "+" Or arr_Rechnen(i) = "-" Then
If arr_Rechnen(i) = "+" Then
o = i - 1
Do Until arr_Rechnen(o) <> ""
o = o - 1
Loop
arr_Rechnen(o) = Str(Val(arr_Rechnen(o)) + Val(arr_Rechnen(i + 1)))
arr_Rechnen(i) = ""
arr_Rechnen(i + 1) = ""
Else
o = i - 1
Do Until arr_Rechnen(o) <> ""
o = o - 1
Loop
arr_Rechnen(o) = Str(Val(arr_Rechnen(o)) - Val(arr_Rechnen(i + 1)))
arr_Rechnen(i) = ""
arr_Rechnen(i + 1) = ""
End If
End If
Next i
For i = 0 To arr_Position
msg = msg & i & ": " & arr_Rechnen(i) & vbCrLf
Next i
Debug.Print (msg)
f!Anzeige = Val(arr_Rechnen(o))
'Case "*": f!Anzeige = f!Anzeige * f!operator
'f!operator = ""
'End Select
'f!operator = 0
End Function
Function plusminus()
'***********************
'** Vorzeichen ändern **
'***********************
Dim f As Form
Set f = Forms!Taschenrechner
f!Anzeige = f!Anzeige * (-1)
End Function
Function komma()
Debug.Print gmDezimal
If gmDezimal = 0 Then
gmDezimal = 1
End If
End Function
Function Back()
'*********************
'** Ziffern löschen **
'*********************
Dim f As Form
Set f = Forms!Taschenrechner
Debug.Print gmDezimal
If gmDezimal >= 2 Then
f!Anzeige = f!Anzeige * 10 ^ (gmDezimal - 2)
f!Anzeige = Int(f!Anzeige)
f!Anzeige = f!Anzeige / 10 ^ (gmDezimal - 2)
gmDezimal = gmDezimal - 1
Else
f!Anzeige = Int(f!Anzeige / 10)
gmDezimal = 0
End If
End Function
Function Taxplus() '********************
'** Plus Steuer **
'********************
Dim f As Form
Set f = Forms!Taschenrechner
f!Anzeige = f!Anzeige + f!Anzeige * (19 / 100)
End Function
Function Taxminus()
'********************
'** minus Steuer **
'********************
Dim f As Form
Set f = Forms!Taschenrechner
f!Anzeige = f!Anzeige - f!Anzeige * (19 / 100)
End Function
Function Memoryplus()
'****************************************
'** Addition des vorherigen Ergebnis **
'****************************************
Dim x As Form
Set x = Forms!Taschenrechner
x!memoryfield = x!operator
x!Anzeige = x!Anzeige + x!memoryfield
End Function
Function Memoryminus()
'*******************************************
'** Subtraktion des vorherigen Ergebnis **
'*******************************************
Dim x As Form
Set x = Forms!Taschenrechner
x!memoryfield = x!operator
x!Anzeige = x!Anzeige - x!memoryfield
End Function
Function memoryclear()
'****************************************
'** Löschen des vorherigen Ergebnis **
'****************************************
Dim x As Form
Set x = Forms!Taschenrechner
x!memoryfield = 0
End Function
Function etod()
'****************************************
'** Euro Dollar Wechsel **
'****************************************
Dim x As Form
Set x = Forms!Taschenrechner
x!operator = x!Anzeige * 1.336
End Function
Function dtoe()
'****************************************
'** Dollar Euro Wechsel **
'****************************************
Dim x As Form
Set x = Forms!Taschenrechner
x!operator = x!Anzeige / 1.336
End Function
Function hoch3()
'****************************************
'****** Potenz hoch 3 ******
'****************************************
Dim x As Form
Set x = Forms!Taschenrechner
x!zeichen = "^3"
x!operator = x!operator & x!Anzeige ^ 3
x!Anzeige = ""
End Function
Function hoch2()
'****************************************
'****** Potenz hoch 2 ******
'****************************************
Dim x As Form
Set x = Forms!Taschenrechner
x!zeichen = "^2"
x!operator = x!operator & x!Anzeige ^ 2
x!Anzeige = ""
End Function
Function hochx()
'****************************************
'****** Potenz hoch x ******
'****************************************
Dim x As Form
Set x = Forms!Taschenrechner
x!zeichen = "x^y"
x!operator = x!Anzeige
x!Anzeige = 0
End Function