home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l406 / 1.ddi / CALC.FR_ / CALC.bin (.txt)
Encoding:
Visual Basic Form  |  1992-10-21  |  13.6 KB  |  445 lines

  1. VERSION 2.00
  2. Begin Form Calculator 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Calculator"
  5.    ClipControls    =   0   'False
  6.    FontBold        =   -1  'True
  7.    FontItalic      =   0   'False
  8.    FontName        =   "System"
  9.    FontSize        =   9.75
  10.    FontStrikethru  =   0   'False
  11.    FontUnderline   =   0   'False
  12.    Height          =   3390
  13.    Icon            =   CALC.FRX:0000
  14.    Left            =   3075
  15.    LinkMode        =   1  'Source
  16.    LinkTopic       =   "Form1"
  17.    MaxButton       =   0   'False
  18.    ScaleHeight     =   2985
  19.    ScaleWidth      =   3240
  20.    Top             =   1665
  21.    Width           =   3360
  22.    Begin CommandButton Number 
  23.       Caption         =   "7"
  24.       FontBold        =   -1  'True
  25.       FontItalic      =   0   'False
  26.       FontName        =   "System"
  27.       FontSize        =   9.75
  28.       FontStrikethru  =   0   'False
  29.       FontUnderline   =   0   'False
  30.       Height          =   480
  31.       Index           =   7
  32.       Left            =   120
  33.       TabIndex        =   7
  34.       Top             =   600
  35.       Width           =   480
  36.    End
  37.    Begin CommandButton Number 
  38.       Caption         =   "8"
  39.       FontBold        =   -1  'True
  40.       FontItalic      =   0   'False
  41.       FontName        =   "System"
  42.       FontSize        =   9.75
  43.       FontStrikethru  =   0   'False
  44.       FontUnderline   =   0   'False
  45.       Height          =   480
  46.       Index           =   8
  47.       Left            =   720
  48.       TabIndex        =   8
  49.       Top             =   600
  50.       Width           =   480
  51.    End
  52.    Begin CommandButton Number 
  53.       Caption         =   "9"
  54.       FontBold        =   -1  'True
  55.       FontItalic      =   0   'False
  56.       FontName        =   "System"
  57.       FontSize        =   9.75
  58.       FontStrikethru  =   0   'False
  59.       FontUnderline   =   0   'False
  60.       Height          =   480
  61.       Index           =   9
  62.       Left            =   1320
  63.       TabIndex        =   9
  64.       Top             =   600
  65.       Width           =   480
  66.    End
  67.    Begin CommandButton Cancel 
  68.       Caption         =   "C"
  69.       FontBold        =   -1  'True
  70.       FontItalic      =   0   'False
  71.       FontName        =   "System"
  72.       FontSize        =   9.75
  73.       FontStrikethru  =   0   'False
  74.       FontUnderline   =   0   'False
  75.       Height          =   480
  76.       Left            =   2040
  77.       TabIndex        =   10
  78.       Top             =   600
  79.       Width           =   480
  80.    End
  81.    Begin CommandButton CancelEntry 
  82.       Caption         =   "CE"
  83.       FontBold        =   -1  'True
  84.       FontItalic      =   0   'False
  85.       FontName        =   "System"
  86.       FontSize        =   9.75
  87.       FontStrikethru  =   0   'False
  88.       FontUnderline   =   0   'False
  89.       Height          =   480
  90.       Left            =   2640
  91.       TabIndex        =   11
  92.       Top             =   600
  93.       Width           =   480
  94.    End
  95.    Begin CommandButton Number 
  96.       Caption         =   "4"
  97.       FontBold        =   -1  'True
  98.       FontItalic      =   0   'False
  99.       FontName        =   "System"
  100.       FontSize        =   9.75
  101.       FontStrikethru  =   0   'False
  102.       FontUnderline   =   0   'False
  103.       Height          =   480
  104.       Index           =   4
  105.       Left            =   120
  106.       TabIndex        =   4
  107.       Top             =   1200
  108.       Width           =   480
  109.    End
  110.    Begin CommandButton Number 
  111.       Caption         =   "5"
  112.       FontBold        =   -1  'True
  113.       FontItalic      =   0   'False
  114.       FontName        =   "System"
  115.       FontSize        =   9.75
  116.       FontStrikethru  =   0   'False
  117.       FontUnderline   =   0   'False
  118.       Height          =   480
  119.       Index           =   5
  120.       Left            =   720
  121.       TabIndex        =   5
  122.       Top             =   1200
  123.       Width           =   480
  124.    End
  125.    Begin CommandButton Number 
  126.       Caption         =   "6"
  127.       FontBold        =   -1  'True
  128.       FontItalic      =   0   'False
  129.       FontName        =   "System"
  130.       FontSize        =   9.75
  131.       FontStrikethru  =   0   'False
  132.       FontUnderline   =   0   'False
  133.       Height          =   480
  134.       Index           =   6
  135.       Left            =   1320
  136.       TabIndex        =   6
  137.       Top             =   1200
  138.       Width           =   480
  139.    End
  140.    Begin CommandButton Operator 
  141.       Caption         =   "+"
  142.       FontBold        =   -1  'True
  143.       FontItalic      =   0   'False
  144.       FontName        =   "System"
  145.       FontSize        =   9.75
  146.       FontStrikethru  =   0   'False
  147.       FontUnderline   =   0   'False
  148.       Height          =   480
  149.       Index           =   1
  150.       Left            =   2040
  151.       TabIndex        =   12
  152.       Top             =   1200
  153.       Width           =   480
  154.    End
  155.    Begin CommandButton Operator 
  156.       Caption         =   "-"
  157.       FontBold        =   -1  'True
  158.       FontItalic      =   0   'False
  159.       FontName        =   "System"
  160.       FontSize        =   9.75
  161.       FontStrikethru  =   0   'False
  162.       FontUnderline   =   0   'False
  163.       Height          =   480
  164.       Index           =   3
  165.       Left            =   2640
  166.       TabIndex        =   13
  167.       Top             =   1200
  168.       Width           =   480
  169.    End
  170.    Begin CommandButton Number 
  171.       Caption         =   "1"
  172.       FontBold        =   -1  'True
  173.       FontItalic      =   0   'False
  174.       FontName        =   "System"
  175.       FontSize        =   9.75
  176.       FontStrikethru  =   0   'False
  177.       FontUnderline   =   0   'False
  178.       Height          =   480
  179.       Index           =   1
  180.       Left            =   120
  181.       TabIndex        =   1
  182.       Top             =   1800
  183.       Width           =   480
  184.    End
  185.    Begin CommandButton Number 
  186.       Caption         =   "2"
  187.       FontBold        =   -1  'True
  188.       FontItalic      =   0   'False
  189.       FontName        =   "System"
  190.       FontSize        =   9.75
  191.       FontStrikethru  =   0   'False
  192.       FontUnderline   =   0   'False
  193.       Height          =   480
  194.       Index           =   2
  195.       Left            =   720
  196.       TabIndex        =   2
  197.       Top             =   1800
  198.       Width           =   480
  199.    End
  200.    Begin CommandButton Number 
  201.       Caption         =   "3"
  202.       FontBold        =   -1  'True
  203.       FontItalic      =   0   'False
  204.       FontName        =   "System"
  205.       FontSize        =   9.75
  206.       FontStrikethru  =   0   'False
  207.       FontUnderline   =   0   'False
  208.       Height          =   480
  209.       Index           =   3
  210.       Left            =   1320
  211.       TabIndex        =   3
  212.       Top             =   1800
  213.       Width           =   480
  214.    End
  215.    Begin CommandButton Operator 
  216.       Caption         =   "X"
  217.       FontBold        =   -1  'True
  218.       FontItalic      =   0   'False
  219.       FontName        =   "System"
  220.       FontSize        =   9.75
  221.       FontStrikethru  =   0   'False
  222.       FontUnderline   =   0   'False
  223.       Height          =   480
  224.       Index           =   2
  225.       Left            =   2040
  226.       TabIndex        =   14
  227.       Top             =   1800
  228.       Width           =   480
  229.    End
  230.    Begin CommandButton Operator 
  231.       Caption         =   "/"
  232.       FontBold        =   -1  'True
  233.       FontItalic      =   0   'False
  234.       FontName        =   "System"
  235.       FontSize        =   9.75
  236.       FontStrikethru  =   0   'False
  237.       FontUnderline   =   0   'False
  238.       Height          =   480
  239.       Index           =   0
  240.       Left            =   2640
  241.       TabIndex        =   15
  242.       Top             =   1800
  243.       Width           =   480
  244.    End
  245.    Begin CommandButton Number 
  246.       Caption         =   "0"
  247.       FontBold        =   -1  'True
  248.       FontItalic      =   0   'False
  249.       FontName        =   "System"
  250.       FontSize        =   9.75
  251.       FontStrikethru  =   0   'False
  252.       FontUnderline   =   0   'False
  253.       Height          =   480
  254.       Index           =   0
  255.       Left            =   120
  256.       TabIndex        =   0
  257.       Top             =   2400
  258.       Width           =   1080
  259.    End
  260.    Begin CommandButton Decimal 
  261.       Caption         =   "."
  262.       FontBold        =   -1  'True
  263.       FontItalic      =   0   'False
  264.       FontName        =   "System"
  265.       FontSize        =   9.75
  266.       FontStrikethru  =   0   'False
  267.       FontUnderline   =   0   'False
  268.       Height          =   480
  269.       Left            =   1320
  270.       TabIndex        =   18
  271.       Top             =   2400
  272.       Width           =   480
  273.    End
  274.    Begin CommandButton Operator 
  275.       Caption         =   "="
  276.       FontBold        =   -1  'True
  277.       FontItalic      =   0   'False
  278.       FontName        =   "System"
  279.       FontSize        =   9.75
  280.       FontStrikethru  =   0   'False
  281.       FontUnderline   =   0   'False
  282.       Height          =   480
  283.       Index           =   4
  284.       Left            =   2040
  285.       TabIndex        =   16
  286.       Top             =   2400
  287.       Width           =   480
  288.    End
  289.    Begin CommandButton Percent 
  290.       Caption         =   "%"
  291.       FontBold        =   -1  'True
  292.       FontItalic      =   0   'False
  293.       FontName        =   "System"
  294.       FontSize        =   9.75
  295.       FontStrikethru  =   0   'False
  296.       FontUnderline   =   0   'False
  297.       Height          =   480
  298.       Left            =   2640
  299.       TabIndex        =   17
  300.       Top             =   2400
  301.       Width           =   480
  302.    End
  303.    Begin Label Readout 
  304.       Alignment       =   1  'Right Justify
  305.       BackColor       =   &H0000FFFF&
  306.       BorderStyle     =   1  'Fixed Single
  307.       Caption         =   "0."
  308.       FontBold        =   -1  'True
  309.       FontItalic      =   0   'False
  310.       FontName        =   "MS Sans Serif"
  311.       FontSize        =   13.5
  312.       FontStrikethru  =   0   'False
  313.       FontUnderline   =   0   'False
  314.       ForeColor       =   &H00000000&
  315.       Height          =   375
  316.       Left            =   120
  317.       TabIndex        =   19
  318.       Top             =   105
  319.       Width           =   3000
  320.    End
  321. ' ------------------------------------------------------------------------
  322. '               Copyright (C) 1991 Microsoft Corporation
  323. ' You have a royalty-free right to use, modify, reproduce and distribute
  324. ' the Sample Application Files (and/or any modified version) in any way
  325. ' you find useful, provided that you agree that Microsoft has no warranty,
  326. ' obligations or liability for any Sample Application Files.
  327. ' ------------------------------------------------------------------------
  328. Option Explicit
  329. Dim Op1, Op2                ' Previously input operand.
  330. Dim DecimalFlag As Integer  ' Decimal point present yet?
  331. Dim NumOps As Integer       ' Number of operands.
  332. Dim LastInput               ' Indicate type of last keypress.
  333. Dim OpFlag                  ' Indicate pending operation.
  334. Dim TempReadout
  335. ' Click event procedure for C (cancel) key.
  336. ' Reset the display and initializes variables.
  337. Sub Cancel_Click ()
  338.     ReadOut = "0."
  339.     Op1 = 0
  340.     Op2 = 0
  341.     Form_Load
  342. End Sub
  343. ' Click event procedure for CE (cancel entry) key.
  344. Sub CancelEntry_Click ()
  345.     ReadOut = "0."
  346.     DecimalFlag = False
  347.     LastInput = "CE"
  348. End Sub
  349. ' Click event procedure for decimal point (.) key.
  350. ' If last keypress was an operator, initialize
  351. ' readout to "0." Otherwise, append a decimal
  352. ' point to the display.
  353. Sub Decimal_Click ()
  354.     If LastInput = "NEG" Then
  355.     ReadOut = "-0."
  356.     ElseIf LastInput <> "NUMS" Then
  357.     ReadOut = "0."
  358.     End If
  359.     DecimalFlag = True
  360.     LastInput = "NUMS"
  361. End Sub
  362. ' Initialization routine for the form.
  363. ' Set all variables to initial values.
  364. Sub Form_Load ()
  365.     DecimalFlag = False
  366.     NumOps = 0
  367.     LastInput = "NONE"
  368.     OpFlag = " "
  369. End Sub
  370. ' Click event procedure for number keys (0-9).
  371. ' Appends new number to the number in the display.
  372. Sub Number_Click (Index As Integer)
  373.     If LastInput <> "NUMS" Then
  374.     ReadOut = "."
  375.     DecimalFlag = False
  376.     End If
  377.     If DecimalFlag Then
  378.     ReadOut = ReadOut + Number(Index).Caption
  379.     Else
  380.     ReadOut = Left(ReadOut, InStr(ReadOut, ".") - 1) + Number(Index).Caption + "."
  381.     End If
  382.     If LastInput = "NEG" Then ReadOut = "-" & ReadOut
  383.     LastInput = "NUMS"
  384. End Sub
  385. ' Click event procedure for operator keys (+, -, x, /, =).
  386. ' If the immediately preceeding keypress was part of a
  387. ' number, increment NumOps. If one operand is present,
  388. ' set Op1. If two are present, set Op1 equal to the
  389. ' result of the operation on Op1 and the current
  390. ' input string, and display the result.
  391. Sub Operator_Click (Index As Integer)
  392.     TempReadout = ReadOut
  393.     If LastInput = "NUMS" Then
  394.     NumOps = NumOps + 1
  395.     End If
  396.     Select Case NumOps
  397.     Case 0
  398.     If Operator(Index).Caption = "-" And LastInput <> "NEG" Then
  399.         ReadOut = "-" & ReadOut
  400.         LastInput = "NEG"
  401.     End If
  402.     Case 1
  403.     Op1 = ReadOut
  404.     If Operator(Index).Caption = "-" And LastInput <> "NUMS" And OpFlag <> "=" Then
  405.         ReadOut = "-"
  406.         LastInput = "NEG"
  407.     End If
  408.     Case 2
  409.     Op2 = TempReadout
  410.     Select Case OpFlag
  411.         Case "+"
  412.         Op1 = Val(Op1) + Val(Op2)
  413.         Case "-"
  414.         Op1 = Op1 - Op2
  415.         Case "X"
  416.         Op1 = Op1 * Op2
  417.         Case "/"
  418.         If Op2 = 0 Then
  419.            MsgBox "Can't divide by zero", 48, "Calculator"
  420.         Else
  421.            Op1 = Op1 / Op2
  422.         End If
  423.         Case "="
  424.         Op1 = Op2
  425.         Case "%"
  426.         Op1 = Op1 * Op2
  427.         End Select
  428.     ReadOut = Op1
  429.     NumOps = 1
  430.     End Select
  431.     If LastInput <> "NEG" Then
  432.     LastInput = "OPS"
  433.     OpFlag = Operator(Index).Caption
  434.     End If
  435. End Sub
  436. ' Click event procedure for percent key (%).
  437. ' Compute and display a percentage of the first operand.
  438. Sub Percent_Click ()
  439.     ReadOut = ReadOut / 100
  440.     LastInput = "Ops"
  441.     OpFlag = "%"
  442.     NumOps = NumOps + 1
  443.     DecimalFlag = True
  444. End Sub
  445.