VERSION 5.00
Begin VB.Form frmMain 
   BorderStyle     =   1  'Fest Einfach
   Caption         =   "Casio fx-115WA"
   ClientHeight    =   2820
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   2550
   Icon            =   "frmMain.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2820
   ScaleWidth      =   2550
   StartUpPosition =   1  'Fenstermitte
   Begin VB.Frame Frame1 
      Caption         =   "Debug "
      Height          =   2535
      Left            =   2640
      TabIndex        =   20
      Top             =   120
      Width           =   2535
      Begin VB.ListBox lsfDebug 
         Height          =   2205
         ItemData        =   "frmMain.frx":030A
         Left            =   120
         List            =   "frmMain.frx":030C
         TabIndex        =   21
         Top             =   240
         Width           =   2295
      End
   End
   Begin VB.CommandButton btnReset 
      Caption         =   "C"
      Height          =   255
      Left            =   1920
      TabIndex        =   18
      Top             =   480
      Width           =   495
   End
   Begin VB.CommandButton btnClear 
      Caption         =   "CE"
      Height          =   255
      Left            =   1320
      TabIndex        =   17
      Top             =   480
      Width           =   495
   End
   Begin VB.CommandButton btnOperator 
      Caption         =   "+"
      Height          =   435
      Index           =   4
      Left            =   1920
      TabIndex        =   16
      Top             =   2280
      Width           =   495
   End
   Begin VB.CommandButton btnOperator 
      Caption         =   "-"
      Height          =   435
      Index           =   3
      Left            =   1920
      TabIndex        =   15
      Top             =   1800
      Width           =   495
   End
   Begin VB.CommandButton btnOperator 
      Caption         =   "x"
      Height          =   435
      Index           =   2
      Left            =   1920
      TabIndex        =   14
      Top             =   1320
      Width           =   495
   End
   Begin VB.CommandButton btnOperator 
      Caption         =   "/"
      Height          =   435
      Index           =   1
      Left            =   1920
      TabIndex        =   13
      Top             =   840
      Width           =   495
   End
   Begin VB.CommandButton btnDoIt 
      Caption         =   "="
      Height          =   435
      Index           =   11
      Left            =   1320
      TabIndex        =   12
      Top             =   2280
      Width           =   495
   End
   Begin VB.CommandButton btnKomma 
      Caption         =   ","
      Height          =   435
      Index           =   10
      Left            =   720
      TabIndex        =   11
      Top             =   2280
      Width           =   495
   End
   Begin VB.CommandButton btnZahl 
      Caption         =   "0"
      Height          =   435
      Index           =   0
      Left            =   120
      TabIndex        =   10
      Top             =   2280
      Width           =   495
   End
   Begin VB.CommandButton btnZahl 
      Caption         =   "3"
      Height          =   435
      Index           =   3
      Left            =   1320
      TabIndex        =   9
      Top             =   1800
      Width           =   495
   End
   Begin VB.CommandButton btnZahl 
      Caption         =   "2"
      Height          =   435
      Index           =   2
      Left            =   720
      TabIndex        =   8
      Top             =   1800
      Width           =   495
   End
   Begin VB.CommandButton btnZahl 
      Caption         =   "1"
      Height          =   435
      Index           =   1
      Left            =   120
      TabIndex        =   7
      Top             =   1800
      Width           =   495
   End
   Begin VB.CommandButton btnZahl 
      Caption         =   "6"
      Height          =   435
      Index           =   6
      Left            =   1320
      TabIndex        =   6
      Top             =   1320
      Width           =   495
   End
   Begin VB.CommandButton btnZahl 
      Caption         =   "5"
      Height          =   435
      Index           =   5
      Left            =   720
      TabIndex        =   5
      Top             =   1320
      Width           =   495
   End
   Begin VB.CommandButton btnZahl 
      Caption         =   "4"
      Height          =   435
      Index           =   4
      Left            =   120
      TabIndex        =   4
      Top             =   1320
      Width           =   495
   End
   Begin VB.CommandButton btnZahl 
      Caption         =   "9"
      Height          =   435
      Index           =   9
      Left            =   1320
      TabIndex        =   3
      Top             =   840
      Width           =   495
   End
   Begin VB.CommandButton btnZahl 
      Caption         =   "8"
      Height          =   435
      Index           =   8
      Left            =   720
      TabIndex        =   2
      Top             =   840
      Width           =   495
   End
   Begin VB.CommandButton btnZahl 
      Caption         =   "7"
      Height          =   435
      Index           =   7
      Left            =   120
      TabIndex        =   1
      Top             =   840
      Width           =   495
   End
   Begin VB.TextBox edtAnzeige 
      Alignment       =   1  'Rechts
      Height          =   285
      Left            =   120
      Locked          =   -1  'True
      TabIndex        =   0
      Top             =   120
      Width           =   2295
   End
   Begin VB.Label Label1 
      Alignment       =   2  'Zentriert
      Appearance      =   0  '2D
      BorderStyle     =   1  'Fest Einfach
      Caption         =   "Casio fx-115"
      ForeColor       =   &H80000008&
      Height          =   255
      Left            =   120
      TabIndex        =   19
      Top             =   480
      Width           =   1095
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim intOperator As Integer  ' verwendeter Operator
Dim dblValue As Double      ' zuletzt eingegebener Wert
Dim bolClear As Boolean     ' Flag zum lölschen der Anzeige
Dim bolNew As Boolean       ' Flag zur Erkennung neuer Rechnung
Dim bolKomma As Boolean     ' Flag zur Kommasetzung
Dim bolFirst As Boolean     ' Erste Zahl eingegeben


' Die Berechnung
Public Sub doCalc()
    Select Case intOperator
        Case 1  ' Division
            dblValue = dblValue / CDbl(edtAnzeige.Text)
            lsfDebug.AddItem ("/" + CStr(edtAnzeige.Text) _
            + "    =" + CStr(dblValue))
            
        Case 2  ' Multiplikation
            dblValue = dblValue * CDbl(edtAnzeige.Text)
            lsfDebug.AddItem ("x" + CStr(edtAnzeige.Text) _
            + "    =" + CStr(dblValue))
            
        Case 3  ' Subtraktion
            dblValue = dblValue - CDbl(edtAnzeige.Text)
            lsfDebug.AddItem ("-" + CStr(edtAnzeige.Text) _
            + "    =" + CStr(dblValue))
            
        Case 4  ' Addition
            dblValue = dblValue + CDbl(edtAnzeige.Text)
            lsfDebug.AddItem ("+" + CStr(edtAnzeige.Text) _
            + "    =" + CStr(dblValue))
            
    End Select
    
    edtAnzeige.Text = CStr(dblValue)
    bolClear = True
    bolFirst = True
    bolKomma = False
End Sub


' Wenn das ClearFlag gesetzt ist wird die Anzeige gelöscht
' ansonsten passiert nix
Public Sub clearAnzeige()
    If bolClear Then
        edtAnzeige.Text = ""
        bolClear = False
    End If
End Sub


' löscht nur die Anzeige bei Falscheingabe
' Operatoren und letzte Eingabe bleibt erhalten
Private Sub btnClear_Click()
    edtAnzeige.Text = ""
    bolFirst = True
    bolKomma = False
End Sub


' Kompletter Reset
' es geht alles verloren
Private Sub btnReset_Click()
    lsfDebug.Clear
    edtAnzeige.Text = ""
    bolFirst = True
    bolKomma = False
    bolClear = False
    bolNew = True
    dblValue = 0
End Sub


' Der "=" Button
' alles wird berechnet und die Flags geresetet
Private Sub btnDoIt_Click(Index As Integer)
    doCalc
    bolNew = False
    intOperator = 0
    dblValue = 0
    bolClear = True
    bolFirst = True
    bolKomma = False
End Sub


' Operatorbutton gedrückt
' Operator speichern
' oder
' Operation ausführen und dann Operator speichern
Private Sub btnOperator_Click(Index As Integer)
    'If bolNew Then
    'lsfDebug.AddItem ("*** new ***")
    'End If
    If bolFirst Then
        intOperator = Index
        Exit Sub
    End If
    Select Case Index
        Case 1  ' Division
            If dblValue <> 0 And Not bolNew Then
                doCalc
                intOperator = 1
            Else
                dblValue = CDbl(edtAnzeige.Text)
                lsfDebug.AddItem (CStr(dblValue))
                intOperator = 1
                bolNew = False
            End If
            
        Case 2  ' Multiplikation
            If dblValue <> 0 And Not bolNew Then
                doCalc
                intOperator = 2
            Else
                dblValue = CDbl(edtAnzeige.Text)
                lsfDebug.AddItem (CStr(dblValue))
                intOperator = 2
                bolNew = False
            End If
            
        Case 3  ' Subtraktion
            If dblValue <> 0 And Not bolNew Then
                doCalc
                intOperator = 3
            Else
                dblValue = CDbl(edtAnzeige.Text)
                lsfDebug.AddItem (CStr(dblValue))
                intOperator = 3
                bolNew = False
            End If
            
        Case 4  ' Addition
            If dblValue <> 0 And Not bolNew Then
                doCalc
                intOperator = 4
            Else
                dblValue = CDbl(edtAnzeige.Text)
                lsfDebug.AddItem (CStr(dblValue))
                intOperator = 4
                bolNew = False
            End If
    End Select
    bolClear = True
    bolFirst = True
    bolKomma = False
End Sub


' Zahlenbutton gedrückt
' führende 0 ist verboten
Private Sub btnZahl_Click(Index As Integer)
    clearAnzeige
    If Index = 0 And Not bolFirst Then
        edtAnzeige.Text = edtAnzeige.Text + CStr(Index)
    ElseIf Index <> 0 Then
        edtAnzeige.Text = edtAnzeige.Text + CStr(Index)
        bolFirst = False
    End If
End Sub


' Kommabutton
' nur erlaubt wenn es das erste Komma ist
' wenn das Komma die erste Eingabe ist dann wird eine 0 vorgestellt
Private Sub btnKomma_Click(Index As Integer)
    clearAnzeige
    If bolFirst Then
        If Not bolKomma Then
            edtAnzeige.Text = "0,"
            bolKomma = True
            bolFirst = False
        End If
    Else
        If Not bolKomma Then
            edtAnzeige.Text = edtAnzeige.Text + ","
            bolKomma = True
            bolFirst = False
        End If
    End If
End Sub


' Initialisierung der Flags
Private Sub Form_Load()
    bolFirst = True
    bolKomma = False
    lsfDebug.Clear
End Sub

Private Sub Label1_Click()
    If frmMain.Width < 3000 Then
        frmMain.Width = 5415
    Else
        frmMain.Width = 2640
    End If
End Sub
