home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Power Pack / Visual_Basic4_Power_Pack.bin / vb4files / vbmaxlcd / calc.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-11-20  |  10.7 KB  |  348 lines

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