VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Dual-Zahl in Dekadische Zahl (und umgekehrt) verwandeln"
   ClientHeight    =   5865
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7365
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   ScaleHeight     =   5865
   ScaleWidth      =   7365
   StartUpPosition =   2  'Bildschirmmitte
   Begin VB.Frame Frame2 
      Caption         =   "Rechnen..."
      Enabled         =   0   'False
      Height          =   2520
      Left            =   1170
      TabIndex        =   10
      Top             =   2685
      Width           =   6135
      Begin VB.Frame Frame3 
         Caption         =   "Lsung"
         ForeColor       =   &H000000FF&
         Height          =   1515
         Left            =   1635
         TabIndex        =   24
         Top             =   930
         Width           =   4440
         Begin VB.TextBox Text8 
            BackColor       =   &H00E0E0E0&
            Height          =   315
            Left            =   1035
            TabIndex        =   31
            Top             =   1095
            Width           =   3345
         End
         Begin VB.TextBox Text7 
            BackColor       =   &H00E0E0E0&
            Height          =   315
            Left            =   2955
            TabIndex        =   29
            Top             =   645
            Width           =   1425
         End
         Begin VB.TextBox Text6 
            BackColor       =   &H00E0E0E0&
            Height          =   315
            Left            =   1035
            TabIndex        =   28
            Top             =   645
            Width           =   1425
         End
         Begin VB.TextBox Text5 
            Height          =   315
            Left            =   1035
            TabIndex        =   27
            Top             =   225
            Width           =   3345
         End
         Begin VB.Label Label10 
            Caption         =   "Dekadische Zahl:"
            Height          =   375
            Left            =   135
            TabIndex        =   32
            Top             =   1035
            Width           =   855
         End
         Begin VB.Label Label9 
            Alignment       =   2  'Zentriert
            BackColor       =   &H00C0C0C0&
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   24
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ForeColor       =   &H000000FF&
            Height          =   495
            Left            =   2550
            TabIndex        =   30
            Top             =   525
            Width           =   330
         End
         Begin VB.Label Label8 
            Caption         =   "Kontrolle:"
            Height          =   225
            Left            =   150
            TabIndex        =   26
            Top             =   690
            Width           =   735
         End
         Begin VB.Label Label7 
            Caption         =   "Dualzahl:"
            Height          =   240
            Left            =   150
            TabIndex        =   25
            Top             =   285
            Width           =   900
         End
      End
      Begin VB.TextBox Text4 
         Height          =   315
         Left            =   3900
         TabIndex        =   22
         Top             =   435
         Width           =   2175
      End
      Begin VB.TextBox Text3 
         Height          =   315
         Left            =   1320
         TabIndex        =   21
         Top             =   435
         Width           =   2175
      End
      Begin VB.OptionButton Option6 
         Caption         =   "Division"
         Height          =   270
         Left            =   90
         TabIndex        =   14
         Top             =   2025
         Width           =   1245
      End
      Begin VB.OptionButton Option5 
         Caption         =   "Multiplikation"
         Height          =   270
         Left            =   90
         TabIndex        =   13
         Top             =   1470
         Width           =   1335
      End
      Begin VB.OptionButton Option4 
         Caption         =   "Subtraktion"
         Height          =   270
         Left            =   90
         TabIndex        =   12
         Top             =   900
         Width           =   1125
      End
      Begin VB.OptionButton Option3 
         Caption         =   "Additon"
         Height          =   270
         Left            =   90
         TabIndex        =   11
         Top             =   420
         Width           =   1170
      End
      Begin VB.Label Label6 
         Alignment       =   2  'Zentriert
         BackColor       =   &H00C0C0C0&
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   24
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H000000FF&
         Height          =   495
         Left            =   3555
         TabIndex        =   23
         Top             =   330
         Width           =   330
      End
   End
   Begin VB.CommandButton Command3 
      Cancel          =   -1  'True
      Caption         =   "&Ende"
      Height          =   525
      Left            =   6255
      TabIndex        =   9
      Top             =   5295
      Width           =   1050
   End
   Begin VB.CommandButton Command2 
      Caption         =   "&Neu"
      Enabled         =   0   'False
      Height          =   525
      Left            =   5025
      TabIndex        =   8
      Top             =   5295
      Width           =   1050
   End
   Begin VB.CommandButton Command1 
      Caption         =   "&Rechne"
      Enabled         =   0   'False
      Height          =   525
      Left            =   3780
      TabIndex        =   7
      Top             =   5295
      Width           =   1050
   End
   Begin VB.Frame Frame1 
      Caption         =   "Umwandeln von ..."
      Enabled         =   0   'False
      Height          =   1575
      Left            =   1155
      TabIndex        =   0
      Top             =   990
      Width           =   6150
      Begin VB.CommandButton Command4 
         Caption         =   "1"
         Height          =   315
         Left            =   5415
         TabIndex        =   16
         Top             =   405
         Visible         =   0   'False
         Width           =   330
      End
      Begin VB.CommandButton Command5 
         Caption         =   "0"
         Height          =   315
         Left            =   5745
         TabIndex        =   15
         Top             =   405
         Visible         =   0   'False
         Width           =   330
      End
      Begin VB.TextBox Text2 
         Height          =   330
         Left            =   2010
         TabIndex        =   6
         Top             =   915
         Width           =   3345
      End
      Begin VB.TextBox Text1 
         Height          =   330
         Left            =   2010
         TabIndex        =   5
         Top             =   390
         Width           =   3345
      End
      Begin VB.OptionButton Option2 
         Height          =   270
         Left            =   195
         TabIndex        =   2
         Top             =   870
         Width           =   195
      End
      Begin VB.OptionButton Option1 
         Height          =   270
         Left            =   195
         TabIndex        =   1
         Top             =   405
         Width           =   195
      End
      Begin VB.Label Label1 
         BackColor       =   &H00C0FFC0&
         Caption         =   "Dekadische Zahl in Dualzahl"
         Height          =   465
         Index           =   1
         Left            =   480
         TabIndex        =   4
         Top             =   855
         Width           =   1440
      End
      Begin VB.Label Label1 
         BackColor       =   &H00C0FFC0&
         Caption         =   "Dualzahl in   dekadische Zahl"
         Height          =   465
         Index           =   0
         Left            =   495
         TabIndex        =   3
         Top             =   315
         Width           =   1440
      End
   End
   Begin VB.Shape Shape1 
      Height          =   735
      Left            =   1155
      Top             =   135
      Width           =   6135
   End
   Begin VB.Label Label5 
      Caption         =   "?"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   18
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   390
      Left            =   6570
      TabIndex        =   20
      Top             =   255
      Width           =   345
   End
   Begin VB.Label Label4 
      Caption         =   "Rechnen"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   18
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   4710
      TabIndex        =   19
      Top             =   255
      Width           =   1515
   End
   Begin VB.Label Label3 
      Caption         =   "oder"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   3765
      TabIndex        =   18
      Top             =   315
      Width           =   630
   End
   Begin VB.Label Label2 
      Caption         =   "&Umwandeln"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   18
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   1380
      TabIndex        =   17
      Top             =   255
      Width           =   1920
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim K(0 To 30) As String
Dim Zahl(0 To 30) As Integer

Private Sub Command1_Click()
Cls
If Frame1.Enabled = True Then
  If Option1 = True And Text1 = "" Then
    MsgBox "Erst eine Dualzahl eingeben!", 48, "Achtung!"
    Command4.SetFocus
    Exit Sub
  ElseIf Option2 = True And Text2 = "" Then
    MsgBox "Erst eine Dezimalzahl eingeben!", 48, "Achtung!"
    Text2.SetFocus
    Exit Sub
  End If
  If Text1 <> "" Then
    Dualzahl$ = Text1.Text
    Stellenzahl = Len(Dualzahl$)
    For i = 0 To Stellenzahl - 1
      K(Stellenzahl - 1 - i) = Mid(Dualzahl$, i + 1, 1)
    Next
    For i = 0 To Stellenzahl - 1
      Dezimalzahl = Dezimalzahl + Val(K(i)) * 2 ^ i
      Print Val(K(i)) * 2 ^ i
    Next
      Text2 = Str(Dezimalzahl)
  Else
    DekadischeZahl = Val(Text2.Text)
    If DekadischeZahl > 1000000000 Then
      MsgBox "Nur Zahlen unter 1 Milliarde zulssig!", 48, "Achtung"
      Text2 = "": Text2.SetFocus: Exit Sub
    End If
    For i = 29 To 0 Step -1
      'Hchster Exponent von 2^i wird bestimmt,
      'der in der Zahl enthalten ist.
      'Wenn gefunden, dann Schleife verlassen
      If 2 ^ i <= DekadischeZahl Then Exit For
    Next
    MaxExponent = i
    Rest = DekadischeZahl
    For j = MaxExponent To 0 Step -1
      If 2 ^ j > Rest Then Zahl(j) = 0: GoTo weiter1
      Rest = Rest - 2 ^ j
      Zahl(j) = 1
weiter1:
      Text1 = Trim(Text1) & Trim(Str(Zahl(j)))
    Next
  End If
  Command2.SetFocus
Else
  If (Option3 Or Option4 Or Option5 Or Option6) _
  And Text3 = "" Then
    MsgBox "Erst eine Dualzahl eingeben!", 48, "Achtung!"
    Text3.SetFocus
    Exit Sub
  ElseIf (Option3 Or Option4 Or Option5 Or Option6) _
  And Text4 = "" Then
    MsgBox "Zweite Dezimalzahl eingeben!", 48, "Achtung!"
    Text4.SetFocus
    Exit Sub
  End If
  If Text3 <> "" Then
    Dualzahl$ = Text3.Text
    Stellenzahl = Len(Dualzahl$)
    For i = 0 To Stellenzahl - 1
      K(Stellenzahl - 1 - i) = Mid(Dualzahl$, i + 1, 1)
    Next
    For i = 0 To Stellenzahl - 1
      Dezimalzahl = Dezimalzahl + Val(K(i)) * 2 ^ i
      Print Val(K(i)) * 2 ^ i
    Next
      Text6 = Str(Dezimalzahl)
      ErgebnisDekadisch = Dezimalzahl
  End If
    Dezimalzahl = 0
  If Text4 <> "" Then
    Dualzahl$ = Text4.Text
    Stellenzahl = Len(Dualzahl$)
    For i = 0 To Stellenzahl - 1
      K(Stellenzahl - 1 - i) = Mid(Dualzahl$, i + 1, 1)
    Next
    For i = 0 To Stellenzahl - 1
      Dezimalzahl = Dezimalzahl + Val(K(i)) * 2 ^ i
      Print Val(K(i)) * 2 ^ i
    Next
      Text7 = Str(Dezimalzahl)
  End If
    If Option3 = True Then
      ErgebnisDekadisch = ErgebnisDekadisch + Dezimalzahl
    ElseIf Option4 = True Then
      ErgebnisDekadisch = ErgebnisDekadisch - Dezimalzahl
    ElseIf Option5 = True Then
      ErgebnisDekadisch = ErgebnisDekadisch * Dezimalzahl
    Else
      ErgebnisDekadisch = ErgebnisDekadisch / Dezimalzahl
      ErgebnisDekadisch = Int(ErgebnisDekadisch)
    End If
      
    DekadischeZahl = ErgebnisDekadisch
    If DekadischeZahl > 1000000000 Then
      MsgBox "Nur Zahlen unter 1 Milliarde zulssig!", 48, "Achtung"
    End If
    For i = 29 To 0 Step -1
      'Hchster Exponent von 2^i wird bestimmt,
      'der in der Zahl enthalten ist.
      'Wenn gefunden, dann Schleife verlassen
      If 2 ^ i < DekadischeZahl Then Exit For
    Next
    MaxExponent = i
    Rest = DekadischeZahl
    For j = MaxExponent To 0 Step -1
      If 2 ^ j > Rest Then Zahl(j) = 0: GoTo weiter2
      Rest = Rest - 2 ^ j
      Zahl(j) = 1
weiter2:
      Text5 = Trim(Text5) & Trim(Str(Zahl(j)))
    Next
  Text8 = ErgebnisDekadisch
  Command2.SetFocus
End If
End Sub

Private Sub Command2_Click()
If Frame1.Enabled = True Then
  If Option1 = True Then
    Text1 = "": Text2 = "": Command4.SetFocus
  Else
    Text1 = "": Text2 = "": Text2.SetFocus
  End If
Else
  Text3 = "": Text4 = "": Text5 = ""
  Text6 = "": Text7 = "": Text8 = ""
  Text3.SetFocus
End If
  Cls
End Sub

Private Sub Command3_Click()
  End
End Sub

Private Sub Command4_Click()
  If Len(Text1.Text) = 30 Then
    If KeyAscii = 48 Or KeyAscii = 49 Then KeyAscii = 0
    If KeyAscii = 8 Then KeyAscii = 8: Exit Sub
    MsgBox "Max. 30 Stellen zugelassen", 48, "Hinweis"
    Command1.SetFocus
    Exit Sub
  End If
  Text1 = Trim(Text1) & Trim(Str(1))
End Sub

Private Sub Command5_Click()
  If Len(Text1.Text) = 30 Then
    If KeyAscii = 48 Or KeyAscii = 49 Then KeyAscii = 0
    If KeyAscii = 8 Then KeyAscii = 8: Exit Sub
    MsgBox "Max. 30 Stellen zugelassen", 48, "Hinweis"
    Command1.SetFocus
    Exit Sub
  End If
  Text1 = Trim(Text1) & Trim(Str(0))
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  Label2.ForeColor = QBColor(0)
  Label4.ForeColor = QBColor(0)
End Sub

Private Sub Label2_Click()
  Frame1.Enabled = True
  Frame1.ForeColor = QBColor(9)
  Frame2.Enabled = False
  Option1 = True
  Command1.Enabled = True
  Command2.Enabled = True
End Sub

Private Sub Label2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  Label2.ForeColor = QBColor(13)
End Sub

Private Sub Label4_Click()
  Frame1.Enabled = False
  Frame2.Enabled = True
  Frame2.ForeColor = QBColor(9)
  Command1.Enabled = True
  Command2.Enabled = True
  Option1 = False: Option2 = False
  If Option6 Then
    Option6 = True
  ElseIf Option5 Then
    Option5 = True
  ElseIf Option4 Then
    Option4 = True
  Else
    Option3 = True
  End If
  Text3.SetFocus
End Sub

Private Sub Label4_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  Label4.ForeColor = QBColor(13)
End Sub

Private Sub Option1_Click()
  Cls
  Text1 = "": Text2 = ""
  Command4.Visible = True: Command5.Visible = True
  Text2.Locked = True: Text1.Locked = False: Command4.SetFocus
End Sub

Private Sub Option2_Click()
  Cls
  Text1 = "": Text2 = ""
  Text1.Locked = True: Text2.Locked = False: Text2.SetFocus
  Command4.Visible = False
  Command5.Visible = False
End Sub

Private Sub Option3_Click()
  Option1 = False: Option2 = False
  Text3.Visible = True: Text4.Visible = True: Text3.SetFocus
  Label6.FontSize = 24: Label6.FontBold = True
  Label6.Caption = "+"
  Label9.FontSize = 24: Label9.FontBold = True
  Label9.Caption = "+"
End Sub

Private Sub Option4_Click()
  Option1 = False: Option2 = False
  Text3.Visible = True: Text4.Visible = True: Text3.SetFocus
  Label6.FontSize = 24: Label6.FontBold = True
  Label6.Caption = "-"
  Label9.FontSize = 24: Label9.FontBold = True
  Label9.Caption = "-"
End Sub

Private Sub Option5_Click()
  Option1 = False: Option2 = False
  Text3.Visible = True: Text4.Visible = True: Text3.SetFocus
  Label6.FontSize = 24: Label6.FontBold = True
  Label6.Caption = "*"
  Label9.FontSize = 24: Label9.FontBold = True
  Label9.Caption = "*"
End Sub

Private Sub Option6_Click()
  Option1 = False: Option2 = False
  Text3.Visible = True: Text4.Visible = True: Text3.SetFocus
  Label6.FontSize = 24: Label6.FontBold = True
  Label6.Caption = ":"
  Label9.FontSize = 24: Label9.FontBold = True
  Label9.Caption = ":"
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
  If Len(Text1.Text) = 30 Then
    If KeyAscii = 48 Or KeyAscii = 49 Then KeyAscii = 0
    If KeyAscii = 8 Then KeyAscii = 8: Exit Sub
    MsgBox "Max. 30 Stellen zugelassen", 48, "Hinweis"
    Command1.SetFocus
    Exit Sub
  End If
  Select Case KeyAscii
  Case 8, 48, 49   'Bei Dualzahl nur Lschen und 0 oder 1 zugelassen
    'leer
  Case Else
    KeyAscii = 0
  End Select
End Sub

Private Sub Text2_Click()
'  If Text1 <> "" Then Text1.SetFocus: Exit Sub
  If Text2 = "" Then Option2 = True
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
  If Len(Text2.Text) = 9 Then
    If KeyAscii > 48 And KeyAscii < 57 Then KeyAscii = 0
    If KeyAscii = 8 Then KeyAscii = 8: Exit Sub
    MsgBox "Max. 9 Stellen zugelassen", 48, "Hinweis"
    KeyAscii = 0
    Command1.SetFocus
    Exit Sub
  End If
  Select Case KeyAscii
  Case 8, 48 To 57   'Bei dekadischer Zahl nur Lschen, 0 bis 9 zugelassen
    'leer
  Case Else
    KeyAscii = 0
  End Select
End Sub

Private Sub Text3_KeyPress(KeyAscii As Integer)
  If Len(Text3.Text) = 20 Then
    If KeyAscii = 48 Or KeyAscii = 49 Then KeyAscii = 0
    If KeyAscii = 8 Then KeyAscii = 8: Exit Sub
    MsgBox "Max. 20 Stellen zugelassen", 48, "Hinweis"
    Text4.SetFocus
    Exit Sub
  End If
  Select Case KeyAscii
  Case 8, 48, 49   'Bei Dualzahl nur Lschen und 0 oder 1 zugelassen
    'leer
  Case Else
    KeyAscii = 0
  End Select
End Sub

Private Sub Text4_KeyPress(KeyAscii As Integer)
  If Len(Text4.Text) = 20 Then
    If KeyAscii = 48 Or KeyAscii = 49 Then KeyAscii = 0
    If KeyAscii = 8 Then KeyAscii = 8: Exit Sub
    MsgBox "Max. 20 Stellen zugelassen", 48, "Hinweis"
    'Command1.SetFocus
    Exit Sub
  End If
  Select Case KeyAscii
  Case 8, 48, 49   'Bei Dualzahl nur Lschen und 0 oder 1 zugelassen
    'leer
  Case Else
    KeyAscii = 0
  End Select
End Sub
