home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual BASIC 5.0 (Ent. Edition) / Vb5ent Extractor.EXE / VB / SAMPLES / PGUIDE / CALC / CALC.FRM (.txt) next >
Encoding:
Visual Basic Form  |  1996-10-15  |  10.6 KB  |  346 lines

  1. VERSION 5.00
  2. Begin VB.Form Calculator 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Calculator"
  5.    ClientHeight    =   2970
  6.    ClientLeft      =   2580
  7.    ClientTop       =   1485
  8.    ClientWidth     =   3270
  9.    ClipControls    =   0   'False
  10.    BeginProperty Font 
  11.       Name            =   "System"
  12.       Size            =   9.75
  13.       Charset         =   0
  14.       Weight          =   700
  15.       Underline       =   0   'False
  16.       Italic          =   0   'False
  17.       Strikethrough   =   0   'False
  18.    EndProperty
  19.    Icon            =   "CALC.frx":0000
  20.    LinkMode        =   1  'Source
  21.    LinkTopic       =   "Form1"
  22.    MaxButton       =   0   'False
  23.    PaletteMode     =   1  'UseZOrder
  24.    ScaleHeight     =   2970
  25.    ScaleWidth      =   3270
  26.    WhatsThisHelp   =   -1  'True
  27.    Begin VB.CommandButton Number 
  28.       Caption         =   "7"
  29.       Height          =   480
  30.       Index           =   7
  31.       Left            =   120
  32.       TabIndex        =   7
  33.       Top             =   600
  34.       Width           =   480
  35.    End
  36.    Begin VB.CommandButton Number 
  37.       Caption         =   "8"
  38.       Height          =   480
  39.       Index           =   8
  40.       Left            =   720
  41.       TabIndex        =   8
  42.       Top             =   600
  43.       Width           =   480
  44.    End
  45.    Begin VB.CommandButton Number 
  46.       Caption         =   "9"
  47.       Height          =   480
  48.       Index           =   9
  49.       Left            =   1320
  50.       TabIndex        =   9
  51.       Top             =   600
  52.       Width           =   480
  53.    End
  54.    Begin VB.CommandButton Cancel 
  55.       Caption         =   "C"
  56.       Height          =   480
  57.       Left            =   2040
  58.       TabIndex        =   10
  59.       Top             =   600
  60.       Width           =   480
  61.    End
  62.    Begin VB.CommandButton CancelEntry 
  63.       Caption         =   "CE"
  64.       Height          =   480
  65.       Left            =   2640
  66.       TabIndex        =   11
  67.       Top             =   600
  68.       Width           =   480
  69.    End
  70.    Begin VB.CommandButton Number 
  71.       Caption         =   "4"
  72.       Height          =   480
  73.       Index           =   4
  74.       Left            =   120
  75.       TabIndex        =   4
  76.       Top             =   1200
  77.       Width           =   480
  78.    End
  79.    Begin VB.CommandButton Number 
  80.       Caption         =   "5"
  81.       Height          =   480
  82.       Index           =   5
  83.       Left            =   720
  84.       TabIndex        =   5
  85.       Top             =   1200
  86.       Width           =   480
  87.    End
  88.    Begin VB.CommandButton Number 
  89.       Caption         =   "6"
  90.       Height          =   480
  91.       Index           =   6
  92.       Left            =   1320
  93.       TabIndex        =   6
  94.       Top             =   1200
  95.       Width           =   480
  96.    End
  97.    Begin VB.CommandButton Operator 
  98.       Caption         =   "+"
  99.       Height          =   480
  100.       Index           =   1
  101.       Left            =   2040
  102.       TabIndex        =   12
  103.       Top             =   1200
  104.       Width           =   480
  105.    End
  106.    Begin VB.CommandButton Operator 
  107.       Caption         =   "-"
  108.       Height          =   480
  109.       Index           =   3
  110.       Left            =   2640
  111.       TabIndex        =   13
  112.       Top             =   1200
  113.       Width           =   480
  114.    End
  115.    Begin VB.CommandButton Number 
  116.       Caption         =   "1"
  117.       Height          =   480
  118.       Index           =   1
  119.       Left            =   120
  120.       TabIndex        =   1
  121.       Top             =   1800
  122.       Width           =   480
  123.    End
  124.    Begin VB.CommandButton Number 
  125.       Caption         =   "2"
  126.       Height          =   480
  127.       Index           =   2
  128.       Left            =   720
  129.       TabIndex        =   2
  130.       Top             =   1800
  131.       Width           =   480
  132.    End
  133.    Begin VB.CommandButton Number 
  134.       Caption         =   "3"
  135.       Height          =   480
  136.       Index           =   3
  137.       Left            =   1320
  138.       TabIndex        =   3
  139.       Top             =   1800
  140.       Width           =   480
  141.    End
  142.    Begin VB.CommandButton Operator 
  143.       Caption         =   "X"
  144.       Height          =   480
  145.       Index           =   2
  146.       Left            =   2040
  147.       TabIndex        =   14
  148.       Top             =   1800
  149.       Width           =   480
  150.    End
  151.    Begin VB.CommandButton Operator 
  152.       Caption         =   "/"
  153.       Height          =   480
  154.       Index           =   0
  155.       Left            =   2640
  156.       TabIndex        =   15
  157.       Top             =   1800
  158.       Width           =   480
  159.    End
  160.    Begin VB.CommandButton Number 
  161.       Caption         =   "0"
  162.       Height          =   480
  163.       Index           =   0
  164.       Left            =   120
  165.       TabIndex        =   0
  166.       Top             =   2400
  167.       Width           =   1080
  168.    End
  169.    Begin VB.CommandButton Decimal 
  170.       Caption         =   "."
  171.       Height          =   480
  172.       Left            =   1320
  173.       TabIndex        =   18
  174.       Top             =   2400
  175.       Width           =   480
  176.    End
  177.    Begin VB.CommandButton Operator 
  178.       Caption         =   "="
  179.       Height          =   480
  180.       Index           =   4
  181.       Left            =   2040
  182.       TabIndex        =   16
  183.       Top             =   2400
  184.       Width           =   480
  185.    End
  186.    Begin VB.CommandButton Percent 
  187.       Caption         =   "%"
  188.       Height          =   480
  189.       Left            =   2640
  190.       TabIndex        =   17
  191.       Top             =   2400
  192.       Width           =   480
  193.    End
  194.    Begin VB.Label Readout 
  195.       Alignment       =   1  'Right Justify
  196.       BackColor       =   &H0000FFFF&
  197.       BorderStyle     =   1  'Fixed Single
  198.       Caption         =   "0."
  199.       BeginProperty Font 
  200.          Name            =   "MS Sans Serif"
  201.          Size            =   12
  202.          Charset         =   0
  203.          Weight          =   700
  204.          Underline       =   0   'False
  205.          Italic          =   0   'False
  206.          Strikethrough   =   0   'False
  207.       EndProperty
  208.       ForeColor       =   &H00000000&
  209.       Height          =   375
  210.       Left            =   120
  211.       TabIndex        =   19
  212.       Top             =   105
  213.       Width           =   3000
  214.    End
  215. Attribute VB_Name = "Calculator"
  216. Attribute VB_GlobalNameSpace = False
  217. Attribute VB_Creatable = False
  218. Attribute VB_PredeclaredId = True
  219. Attribute VB_Exposed = False
  220. ' ------------------------------------------------------------------------
  221. '               Copyright (C) 1994 Microsoft Corporation
  222. ' You have a royalty-free right to use, modify, reproduce and distribute
  223. ' the Sample Application Files (and/or any modified version) in any way
  224. ' you find useful, provided that you agree that Microsoft has no warranty,
  225. ' obligations or liability for any Sample Application Files.
  226. ' ------------------------------------------------------------------------
  227. Option Explicit
  228. Dim Op1, Op2                ' Previously input operand.
  229. Dim DecimalFlag As Integer  ' Decimal point present yet?
  230. Dim NumOps As Integer       ' Number of operands.
  231. Dim LastInput               ' Indicate type of last keypress event.
  232. Dim OpFlag                  ' Indicate pending operation.
  233. Dim TempReadout
  234. ' Click event procedure for C (cancel) key.
  235. ' Reset the display and initializes variables.
  236. Private Sub Cancel_Click()
  237.     Readout = Format(0, "0.")
  238.     Op1 = 0
  239.     Op2 = 0
  240.     Form_Load
  241. End Sub
  242. ' Click event procedure for CE (cancel entry) key.
  243. Private Sub CancelEntry_Click()
  244.     Readout = Format(0, "0.")
  245.     DecimalFlag = False
  246.     LastInput = "CE"
  247. End Sub
  248. ' Click event procedure for decimal point (.) key.
  249. ' If last keypress was an operator, initialize
  250. ' readout to "0." Otherwise, append a decimal
  251. ' point to the display.
  252. Private Sub Decimal_Click()
  253.     If LastInput = "NEG" Then
  254.         Readout = Format(0, "-0.")
  255.     ElseIf LastInput <> "NUMS" Then
  256.         Readout = Format(0, "0.")
  257.     End If
  258.     DecimalFlag = True
  259.     LastInput = "NUMS"
  260. End Sub
  261. ' Initialization routine for the form.
  262. ' Set all variables to initial values.
  263. Private Sub Form_Load()
  264.     DecimalFlag = False
  265.     NumOps = 0
  266.     LastInput = "NONE"
  267.     OpFlag = " "
  268.     Readout = Format(0, "0.")
  269.     'Decimal.Caption = Format(0, ".")
  270. End Sub
  271. ' Click event procedure for number keys (0-9).
  272. ' Append new number to the number in the display.
  273. Private Sub Number_Click(Index As Integer)
  274.     If LastInput <> "NUMS" Then
  275.         Readout = Format(0, ".")
  276.         DecimalFlag = False
  277.     End If
  278.     If DecimalFlag Then
  279.         Readout = Readout + Number(Index).Caption
  280.     Else
  281.         Readout = Left(Readout, InStr(Readout, Format(0, ".")) - 1) + Number(Index).Caption + Format(0, ".")
  282.     End If
  283.     If LastInput = "NEG" Then Readout = "-" & Readout
  284.     LastInput = "NUMS"
  285. End Sub
  286. ' Click event procedure for operator keys (+, -, x, /, =).
  287. ' If the immediately preceeding keypress was part of a
  288. ' number, increments NumOps. If one operand is present,
  289. ' set Op1. If two are present, set Op1 equal to the
  290. ' result of the operation on Op1 and the current
  291. ' input string, and display the result.
  292. Private Sub Operator_Click(Index As Integer)
  293.     TempReadout = Readout
  294.     If LastInput = "NUMS" Then
  295.         NumOps = NumOps + 1
  296.     End If
  297.     Select Case NumOps
  298.         Case 0
  299.         If Operator(Index).Caption = "-" And LastInput <> "NEG" Then
  300.             Readout = "-" & Readout
  301.             LastInput = "NEG"
  302.         End If
  303.         Case 1
  304.         Op1 = Readout
  305.         If Operator(Index).Caption = "-" And LastInput <> "NUMS" And OpFlag <> "=" Then
  306.             Readout = "-"
  307.             LastInput = "NEG"
  308.         End If
  309.         Case 2
  310.         Op2 = TempReadout
  311.         Select Case OpFlag
  312.             Case "+"
  313.                 Op1 = CDbl(Op1) + CDbl(Op2)
  314.             Case "-"
  315.                 Op1 = CDbl(Op1) - CDbl(Op2)
  316.             Case "X"
  317.                 Op1 = CDbl(Op1) * CDbl(Op2)
  318.             Case "/"
  319.                 If Op2 = 0 Then
  320.                    MsgBox "Can't divide by zero", 48, "Calculator"
  321.                 Else
  322.                    Op1 = CDbl(Op1) / CDbl(Op2)
  323.                 End If
  324.             Case "="
  325.                 Op1 = CDbl(Op2)
  326.             Case "%"
  327.                 Op1 = CDbl(Op1) * CDbl(Op2)
  328.             End Select
  329.         Readout = Op1
  330.         NumOps = 1
  331.     End Select
  332.     If LastInput <> "NEG" Then
  333.         LastInput = "OPS"
  334.         OpFlag = Operator(Index).Caption
  335.     End If
  336. End Sub
  337. ' Click event procedure for percent key (%).
  338. ' Compute and display a percentage of the first operand.
  339. Private Sub Percent_Click()
  340.     Readout = Readout / 100
  341.     LastInput = "Ops"
  342.     OpFlag = "%"
  343.     NumOps = NumOps + 1
  344.     DecimalFlag = True
  345. End Sub
  346.