Berechnungen   →   ohne Beispiele zurück zu VBA-Wissen.de 
Befehl / Beispiele Beschreibung
+
Beispiel:   MsgBox 12  + 34     -->  46
Addition
 
-
Beispiel:   MsgBox 123 - 54     -->  69
Subtraktion
 
*
Beispiel:   MsgBox 34 * 65      -->  2210
Multiplikation
 
/
Beispiel:   MsgBox 2210 / 34    -->  65
Division
 
\
Beispiel:   MsgBox 25 \ 7       -->  3
Ganzzahliger Wert einer Division
 
Mod
Beispiel:   MsgBox 10 Mod 7     -->  3
Rest einer Division
 
Abs(<Zahl>)
Beispiel:   MsgBox Abs(-23)     -->  23
Positive Zahl
Int(<Zahl>)
Beispiel:   MsgBox Int( 12.1)   -->  12
         MsgBox Int( 12.9)   -->  12
         MsgBox Int(-12.1)   --> -13
         MsgBox Int(-12.9)   --> -13
Schneidet die Kommastelle ab.



 
Fix(<Zahl>)
Beispiel:
   MsgBox Fix( 12.1)   -->  12
         MsgBox Fix( 12.9)   -->  12
         MsgBox Fix(-12.1)   --> -12
         MsgBox Fix(-12.9)   --> -12
Schneidet die Kommastelle ab.



 
Round(<Zahl>)
Beispiel:   MsgBox Round(12.123, 2)    -->  12,12
         MsgBox Round(-12.123, 2)   --> -12,12
         MsgBox Round(12.987, 2)    -->  12,99
         MsgBox Round(-12.987, 2)   --> -12,99
Runden eine Zahl nach Angaben von Nachkommastellen auf / ab



 
Sgn(<Zahl>)
Beispiel:   MsgBox Sgn(125)      -->  1
         MsgBox Sgn(-125)     --> -1
Vorzeichen einer Zahl bestimmen

 
Rnd
Beispiel:   Zufallszahl = Rnd
Zufallszahl erstellen
gibt eine Zufallszahl zwischen 0 und 1 aus
Int(Rnd*(Obergrenze - Untergrenze + 1)  + Untergrenze)
Beispiel:   Würfelzahl = Int(Rnd*( 6 - 1 + 1)  + 1)
         Lottozahl  = Int(Rnd*(49 - 1 + 1)  + 1)
Zufallszahl zwischen 2 Grenzen erstellen
 
^
Beispiel:   MsgBox 2^8          --> 256   2 hoch 8
Potenzrechnung
 
Sqr
Beispiel:   MsgBox Sqr(100)     --> 10    2. Wurzel aus 100
Quadratwurzel
 
^(1/n)
Beispiel:   Msgbox 256^(1/8)    --> 2     8. Wurzel aus 256
n-te Wurzel
 
Sin(<Bogenmaßwinkel>)
Beispiel:   Pi = Application.WorksheetFunction.Pi
         MsgBox Sin(Pi / 2)                       --> 1
Sinus
Der Winkel muss als Bogenmaß angegeben werden
 
Cos(<Bogenmaßwinkel>)
Beispiel:   Pi = Application.WorksheetFunction.Pi
         MsgBox Cos(Pi)                           --> -1
Kosinus
Der Winkel muss als Bogenmaß angegeben werden
 
Tan(<Bogenmaßwinkel>)
Beispiel:   Pi = Application.WorksheetFunction.Pi
         MsgBox Tan(Pi / 4)                       --> 1
Tangens
Der Winkel muss als Bogenmaß angegeben werden.
 
Atn(<Wert>)
Beispiel:   Pi = Application.WorksheetFunction.Pi
         MsgBox Atn(1) * 4                        --> 3,1415...
Arkus Tangens

 
Application.WorksheetFunction.ASin
Beispiel:   MsgBox Application.WorksheetFunction.Asin(1)  --> 1,5707...
Arkus Sinus
 
Application.WorksheetFunction.ACos
Beispiel:   MsgBox Application.WorksheetFunction.Acos(0)  --> 1,5707... 
Arkus Kosinus
 
Log(<Zahl>)
Beispiel:   MsgBox Log(10)     --> 2,302585... 
natürlicher Logarithmus
 
Ln(<Wert>)
Beispiel:   Basis = 10
         Zahl = 100
         MsgBox Log(Zahl) / Log(Basis)   --> 2
Logarithmus zur Basis n


 
Exp(<Zahl>)
Beispiel:   Zahl = Exp(1)    --> Eulersche Zahl
                              = 2,71828182845905
eZahl

 
Application.WorksheetFunction.Pi
Beispiel:   Pi = Application.WorksheetFunction.Pi
         Pi = Atn(1)*4                      --> es geht auch so
Die Kreiszahl p

 
<Farbwert>= RGB(<Rot>,<Grün>,<Blau>) RGB
Beispiel:
Farbzahl = RGB(Rot, Grün, Blau)                    ' Die Werte für Rot, Grün und Blau
                                                   ' liegen zwischen 0 und 255
' entspricht folgende Zeile:
FarbZahl = Rot + 256# * Grün + 256# * 256# * Blau

' Farbwerte aus einer Farbzahl errechnen:
Rot  =  Farbzahl And 255
Grün = (Farbzahl And 255# * 256#) / 256#
Blau = (Farbzahl And 255# * 256# * 256#) / 256# / 256#
Hex(<Zahl>) Umwandlung einer Dezimalzahl in eine Hexadezimalzahl
Oct(<Zahl>) Umwandlung einer Dezimalzahl in eine Oktalzahl
nicht vorhanden, selber schreiben ... siehe unten Umwandlung einer Dezimalzahl in eine Dualzahl ( binäre Zahl )
Function BinärZahl(Zahl As Long, _
                   Optional WunschStellen As Byte, _
                   Optional Trenner As String) As String
'+-----------------------------------------------------------------+
'| Gibt eine positive Zahl im Bereich von                          |
'| 0 und 2.147.483.647 als Binärzahl wieder.                       |
'+-----------------------------------------------------------------+
'| WunschStellen = Anzahl der wiederzugebenden Ziffern             |
'| Trenner = Trennzeichenfolgen nach jeweils 8 Ziffern             |
'| Beisoiel: BinärZahl(32345;16;" ") --> 01111110 01011001         |
'+-----------------------------------------------------------------+
   Dim Azstellen  As Byte
   Dim Stelle     As Integer

   Azstellen = Int(Log(Zahl) / Log(2) + 0.000000000000001) + 1
   If IsMissing(WunschStellen) = False Then
   If WunschStellen > Azstellen Then Azstellen = WunschStellen
   End If

   For Stelle = 0 To Azstellen - 1
       BinärZahl = (Zahl And 2 ^ Stelle) / 2 ^ Stelle & BinärZahl
       If IsMissing(Trenner) = False Then
          If (Stelle + 1) Mod 8 = 0 Then
             BinärZahl = Trenner & BinärZahl
          End If
       End If
   Next Stelle
End Function

Binäre-Vergleichstabelle



 
And
Beispiel:   MsgBox 200 And 100   -->  64
         
Binärer Und- Vergleich




 
Or
Beispiel:   MsgBox 200 Or 100    --> 236
         
Binärer Oder- Vergleich




 
Eqv
Beispiel:   MsgBox 200 Eqv 100   --> -173
         
Binärer Äquivalenz Vergleich




 
Xor
Beispiel:   MsgBox 200 Xor 100   -->  172
         
Binärer Exclusiv- Oder Vergleich




 
Imp
Beispiel:   MsgBox 200 Imp 100   --> -137
         
Binärer Implikations- Vergleich