home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / calcu_2 / calc.frm < prev    next >
Text File  |  1992-12-08  |  18KB  |  563 lines

  1. VERSION 2.00
  2. Begin Form Calculator 
  3.    BorderStyle     =   0  'None
  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          =   4125
  13.    Icon            =   CALC.FRX:0000
  14.    Left            =   2010
  15.    LinkMode        =   1  'Source
  16.    LinkTopic       =   "Form1"
  17.    MaxButton       =   0   'False
  18.    ScaleHeight     =   3720
  19.    ScaleWidth      =   3660
  20.    Top             =   2670
  21.    Width           =   3780
  22.    Begin PictureBox picShade 
  23.       AutoSize        =   -1  'True
  24.       BorderStyle     =   0  'None
  25.       Height          =   120
  26.       Left            =   0
  27.       Picture         =   CALC.FRX:0302
  28.       ScaleHeight     =   120
  29.       ScaleWidth      =   120
  30.       TabIndex        =   22
  31.       Top             =   0
  32.       Visible         =   0   'False
  33.       Width           =   120
  34.    End
  35.    Begin PictureBox Gadget 
  36.       BackColor       =   &H00C0C0C0&
  37.       BorderStyle     =   0  'None
  38.       Height          =   3390
  39.       Left            =   240
  40.       ScaleHeight     =   3390
  41.       ScaleWidth      =   3255
  42.       TabIndex        =   0
  43.       Top             =   240
  44.       Width           =   3255
  45.       Begin SSPanel Panel3D1 
  46.          BackColor       =   &H00C0C0C0&
  47.          Caption         =   "Panel3D1"
  48.          Height          =   285
  49.          Left            =   120
  50.          TabIndex        =   23
  51.          Top             =   90
  52.          Width           =   3030
  53.          Begin PictureBox Picture1 
  54.             BackColor       =   &H00C0C0C0&
  55.             BorderStyle     =   0  'None
  56.             Height          =   255
  57.             Left            =   15
  58.             ScaleHeight     =   255
  59.             ScaleWidth      =   3000
  60.             TabIndex        =   24
  61.             Top             =   15
  62.             Width           =   3000
  63.          End
  64.       End
  65.       Begin SSCommand Command3D1 
  66.          Caption         =   "OFF"
  67.          ForeColor       =   &H000000FF&
  68.          Height          =   375
  69.          Left            =   120
  70.          TabIndex        =   21
  71.          Top             =   480
  72.          Width           =   615
  73.       End
  74.       Begin CommandButton Percent 
  75.          Caption         =   "%"
  76.          FontBold        =   -1  'True
  77.          FontItalic      =   0   'False
  78.          FontName        =   "System"
  79.          FontSize        =   9.75
  80.          FontStrikethru  =   0   'False
  81.          FontUnderline   =   0   'False
  82.          Height          =   480
  83.          Left            =   2640
  84.          TabIndex        =   19
  85.          Top             =   2760
  86.          Width           =   480
  87.       End
  88.       Begin CommandButton Operator 
  89.          Caption         =   "="
  90.          FontBold        =   -1  'True
  91.          FontItalic      =   0   'False
  92.          FontName        =   "System"
  93.          FontSize        =   9.75
  94.          FontStrikethru  =   0   'False
  95.          FontUnderline   =   0   'False
  96.          Height          =   480
  97.          Index           =   4
  98.          Left            =   2040
  99.          TabIndex        =   18
  100.          Top             =   2760
  101.          Width           =   480
  102.       End
  103.       Begin CommandButton Decimal 
  104.          Caption         =   "."
  105.          FontBold        =   -1  'True
  106.          FontItalic      =   0   'False
  107.          FontName        =   "System"
  108.          FontSize        =   9.75
  109.          FontStrikethru  =   0   'False
  110.          FontUnderline   =   0   'False
  111.          Height          =   480
  112.          Left            =   1320
  113.          TabIndex        =   17
  114.          Top             =   2760
  115.          Width           =   480
  116.       End
  117.       Begin CommandButton Number 
  118.          Caption         =   "0"
  119.          FontBold        =   -1  'True
  120.          FontItalic      =   0   'False
  121.          FontName        =   "System"
  122.          FontSize        =   9.75
  123.          FontStrikethru  =   0   'False
  124.          FontUnderline   =   0   'False
  125.          Height          =   480
  126.          Index           =   0
  127.          Left            =   120
  128.          TabIndex        =   16
  129.          Top             =   2760
  130.          Width           =   1080
  131.       End
  132.       Begin CommandButton Operator 
  133.          Caption         =   "/"
  134.          FontBold        =   -1  'True
  135.          FontItalic      =   0   'False
  136.          FontName        =   "System"
  137.          FontSize        =   9.75
  138.          FontStrikethru  =   0   'False
  139.          FontUnderline   =   0   'False
  140.          Height          =   480
  141.          Index           =   0
  142.          Left            =   2640
  143.          TabIndex        =   15
  144.          Top             =   2160
  145.          Width           =   480
  146.       End
  147.       Begin CommandButton Operator 
  148.          Caption         =   "X"
  149.          FontBold        =   -1  'True
  150.          FontItalic      =   0   'False
  151.          FontName        =   "System"
  152.          FontSize        =   9.75
  153.          FontStrikethru  =   0   'False
  154.          FontUnderline   =   0   'False
  155.          Height          =   480
  156.          Index           =   2
  157.          Left            =   2040
  158.          TabIndex        =   14
  159.          Top             =   2160
  160.          Width           =   480
  161.       End
  162.       Begin CommandButton Number 
  163.          Caption         =   "3"
  164.          FontBold        =   -1  'True
  165.          FontItalic      =   0   'False
  166.          FontName        =   "System"
  167.          FontSize        =   9.75
  168.          FontStrikethru  =   0   'False
  169.          FontUnderline   =   0   'False
  170.          Height          =   480
  171.          Index           =   3
  172.          Left            =   1320
  173.          TabIndex        =   13
  174.          Top             =   2160
  175.          Width           =   480
  176.       End
  177.       Begin CommandButton Number 
  178.          Caption         =   "2"
  179.          FontBold        =   -1  'True
  180.          FontItalic      =   0   'False
  181.          FontName        =   "System"
  182.          FontSize        =   9.75
  183.          FontStrikethru  =   0   'False
  184.          FontUnderline   =   0   'False
  185.          Height          =   480
  186.          Index           =   2
  187.          Left            =   720
  188.          TabIndex        =   12
  189.          Top             =   2160
  190.          Width           =   480
  191.       End
  192.       Begin CommandButton Number 
  193.          Caption         =   "1"
  194.          FontBold        =   -1  'True
  195.          FontItalic      =   0   'False
  196.          FontName        =   "System"
  197.          FontSize        =   9.75
  198.          FontStrikethru  =   0   'False
  199.          FontUnderline   =   0   'False
  200.          Height          =   480
  201.          Index           =   1
  202.          Left            =   120
  203.          TabIndex        =   11
  204.          Top             =   2160
  205.          Width           =   480
  206.       End
  207.       Begin CommandButton Operator 
  208.          Caption         =   "-"
  209.          FontBold        =   -1  'True
  210.          FontItalic      =   0   'False
  211.          FontName        =   "System"
  212.          FontSize        =   9.75
  213.          FontStrikethru  =   0   'False
  214.          FontUnderline   =   0   'False
  215.          Height          =   480
  216.          Index           =   3
  217.          Left            =   2640
  218.          TabIndex        =   10
  219.          Top             =   1560
  220.          Width           =   480
  221.       End
  222.       Begin CommandButton Operator 
  223.          Caption         =   "+"
  224.          FontBold        =   -1  'True
  225.          FontItalic      =   0   'False
  226.          FontName        =   "System"
  227.          FontSize        =   9.75
  228.          FontStrikethru  =   0   'False
  229.          FontUnderline   =   0   'False
  230.          Height          =   480
  231.          Index           =   1
  232.          Left            =   2040
  233.          TabIndex        =   9
  234.          Top             =   1560
  235.          Width           =   480
  236.       End
  237.       Begin CommandButton Number 
  238.          Caption         =   "6"
  239.          FontBold        =   -1  'True
  240.          FontItalic      =   0   'False
  241.          FontName        =   "System"
  242.          FontSize        =   9.75
  243.          FontStrikethru  =   0   'False
  244.          FontUnderline   =   0   'False
  245.          Height          =   480
  246.          Index           =   6
  247.          Left            =   1320
  248.          TabIndex        =   8
  249.          Top             =   1560
  250.          Width           =   480
  251.       End
  252.       Begin CommandButton Number 
  253.          Caption         =   "5"
  254.          FontBold        =   -1  'True
  255.          FontItalic      =   0   'False
  256.          FontName        =   "System"
  257.          FontSize        =   9.75
  258.          FontStrikethru  =   0   'False
  259.          FontUnderline   =   0   'False
  260.          Height          =   480
  261.          Index           =   5
  262.          Left            =   720
  263.          TabIndex        =   7
  264.          Top             =   1560
  265.          Width           =   480
  266.       End
  267.       Begin CommandButton Number 
  268.          Caption         =   "4"
  269.          FontBold        =   -1  'True
  270.          FontItalic      =   0   'False
  271.          FontName        =   "System"
  272.          FontSize        =   9.75
  273.          FontStrikethru  =   0   'False
  274.          FontUnderline   =   0   'False
  275.          Height          =   480
  276.          Index           =   4
  277.          Left            =   120
  278.          TabIndex        =   6
  279.          Top             =   1560
  280.          Width           =   480
  281.       End
  282.       Begin CommandButton CancelEntry 
  283.          Caption         =   "CE"
  284.          FontBold        =   -1  'True
  285.          FontItalic      =   0   'False
  286.          FontName        =   "System"
  287.          FontSize        =   9.75
  288.          FontStrikethru  =   0   'False
  289.          FontUnderline   =   0   'False
  290.          Height          =   480
  291.          Left            =   2640
  292.          TabIndex        =   5
  293.          Top             =   960
  294.          Width           =   480
  295.       End
  296.       Begin CommandButton Cancel 
  297.          Caption         =   "C"
  298.          FontBold        =   -1  'True
  299.          FontItalic      =   0   'False
  300.          FontName        =   "System"
  301.          FontSize        =   9.75
  302.          FontStrikethru  =   0   'False
  303.          FontUnderline   =   0   'False
  304.          Height          =   480
  305.          Left            =   2040
  306.          TabIndex        =   4
  307.          Top             =   960
  308.          Width           =   480
  309.       End
  310.       Begin CommandButton Number 
  311.          Caption         =   "9"
  312.          FontBold        =   -1  'True
  313.          FontItalic      =   0   'False
  314.          FontName        =   "System"
  315.          FontSize        =   9.75
  316.          FontStrikethru  =   0   'False
  317.          FontUnderline   =   0   'False
  318.          Height          =   480
  319.          Index           =   9
  320.          Left            =   1320
  321.          TabIndex        =   3
  322.          Top             =   960
  323.          Width           =   480
  324.       End
  325.       Begin CommandButton Number 
  326.          Caption         =   "8"
  327.          FontBold        =   -1  'True
  328.          FontItalic      =   0   'False
  329.          FontName        =   "System"
  330.          FontSize        =   9.75
  331.          FontStrikethru  =   0   'False
  332.          FontUnderline   =   0   'False
  333.          Height          =   480
  334.          Index           =   8
  335.          Left            =   720
  336.          TabIndex        =   2
  337.          Top             =   960
  338.          Width           =   480
  339.       End
  340.       Begin CommandButton Number 
  341.          Caption         =   "7"
  342.          FontBold        =   -1  'True
  343.          FontItalic      =   0   'False
  344.          FontName        =   "System"
  345.          FontSize        =   9.75
  346.          FontStrikethru  =   0   'False
  347.          FontUnderline   =   0   'False
  348.          Height          =   480
  349.          Index           =   7
  350.          Left            =   120
  351.          TabIndex        =   1
  352.          Top             =   960
  353.          Width           =   480
  354.       End
  355.       Begin Label Readout 
  356.          Alignment       =   1  'Right Justify
  357.          BackColor       =   &H0000FFFF&
  358.          BorderStyle     =   1  'Fixed Single
  359.          Caption         =   "0."
  360.          FontBold        =   -1  'True
  361.          FontItalic      =   0   'False
  362.          FontName        =   "MS Sans Serif"
  363.          FontSize        =   12
  364.          FontStrikethru  =   0   'False
  365.          FontUnderline   =   0   'False
  366.          ForeColor       =   &H00000000&
  367.          Height          =   375
  368.          Left            =   840
  369.          TabIndex        =   20
  370.          Top             =   480
  371.          Width           =   2280
  372.       End
  373.    End
  374. End
  375. ' ------------------------------------------------------------------------
  376. '               Copyright (C) 1991 Microsoft Corporation
  377. '
  378. ' You have a royalty-free right to use, modify, reproduce and distribute
  379. ' the Sample Application Files (and/or any modified version) in any way
  380. ' you find useful, provided that you agree that Microsoft has no warranty,
  381. ' obligations or liability for any Sample Application Files.
  382. ' ------------------------------------------------------------------------
  383. Option Explicit
  384. Dim Op1, Op2                ' Previously input operand.
  385. Dim DecimalFlag As Integer  ' Decimal point present yet?
  386. Dim NumOps As Integer       ' Number of operands.
  387. Dim LastInput               ' Indicate type of last keypress.
  388. Dim OpFlag                  ' Indicate pending operation.
  389. Dim TempReadout
  390.  
  391. ' Click event procedure for C (cancel) key.
  392. ' Reset the display and initializes variables.
  393. '
  394. Sub Cancel_Click ()
  395.     ReadOut = "0."
  396.     Op1 = 0
  397.     Op2 = 0
  398.     Form_Load
  399. End Sub
  400.  
  401. ' Click event procedure for CE (cancel entry) key.
  402. '
  403. Sub CancelEntry_Click ()
  404.     ReadOut = "0."
  405.     DecimalFlag = False
  406.     LastInput = "CE"
  407. End Sub
  408.  
  409. Sub Command3D1_Click ()
  410.     Unload Calculator
  411. End Sub
  412.  
  413. ' Click event procedure for decimal point (.) key.
  414. ' If last keypress was an operator, initialize
  415. ' readout to "0." Otherwise, append a decimal
  416. ' point to the display.
  417. '
  418. Sub Decimal_Click ()
  419.     If LastInput = "NEG" Then
  420.     ReadOut = "-0."
  421.     ElseIf LastInput <> "NUMS" Then
  422.     ReadOut = "0."
  423.     End If
  424.     DecimalFlag = True
  425.     LastInput = "NUMS"
  426. End Sub
  427.  
  428. ' Initialization routine for the form.
  429. ' Set all variables to initial values.
  430. '
  431. Sub Form_Load ()
  432.     DecimalFlag = False
  433.     NumOps = 0
  434.     LastInput = "NONE"
  435.     OpFlag = " "
  436.  
  437.     Call AllignForm(Calculator)
  438.  
  439. End Sub
  440.  
  441. Sub Form_Paint ()
  442.     Make3DForm Calculator, Gadget
  443. End Sub
  444.  
  445. Sub Form_Unload (Cancel As Integer)
  446.     Dim res As Integer
  447. End Sub
  448.  
  449. ' Click event procedure for number keys (0-9).
  450. ' Appends new number to the number in the display.
  451. '
  452. Sub Number_Click (Index As Integer)
  453.     If LastInput <> "NUMS" Then
  454.     ReadOut = "."
  455.     DecimalFlag = False
  456.     End If
  457.     If DecimalFlag Then
  458.     ReadOut = ReadOut + Number(Index).Caption
  459.     Else
  460.     ReadOut = Left(ReadOut, InStr(ReadOut, ".") - 1) + Number(Index).Caption + "."
  461.     End If
  462.     If LastInput = "NEG" Then ReadOut = "-" & ReadOut
  463.     LastInput = "NUMS"
  464. End Sub
  465.  
  466. ' Click event procedure for operator keys (+, -, x, /, =).
  467. ' If the immediately preceeding keypress was part of a
  468. ' number, increment NumOps. If one operand is present,
  469. ' set Op1. If two are present, set Op1 equal to the
  470. ' result of the operation on Op1 and the current
  471. ' input string, and display the result.
  472. '
  473. Sub Operator_Click (Index As Integer)
  474.     TempReadout = ReadOut
  475.     If LastInput = "NUMS" Then
  476.     NumOps = NumOps + 1
  477.     End If
  478.     Select Case NumOps
  479.     Case 0
  480.     If Operator(Index).Caption = "-" And LastInput <> "NEG" Then
  481.         ReadOut = "-" & ReadOut
  482.         LastInput = "NEG"
  483.     End If
  484.     Case 1
  485.     Op1 = ReadOut
  486.     If Operator(Index).Caption = "-" And LastInput <> "NUMS" And OpFlag <> "=" Then
  487.         ReadOut = "-"
  488.         LastInput = "NEG"
  489.     End If
  490.     Case 2
  491.     Op2 = TempReadout
  492.     Select Case OpFlag
  493.         Case "+"
  494.         Op1 = Val(Op1) + Val(Op2)
  495.         Case "-"
  496.         Op1 = Op1 - Op2
  497.         Case "X"
  498.         Op1 = Op1 * Op2
  499.         Case "/"
  500.         If Op2 = 0 Then
  501.            MsgBox "Can't divide by zero", 48, "Calculator"
  502.         Else
  503.            Op1 = Op1 / Op2
  504.         End If
  505.         Case "="
  506.         Op1 = Op2
  507.         Case "%"
  508.         Op1 = Op1 * Op2
  509.         End Select
  510.     ReadOut = Op1
  511.     NumOps = 1
  512.     End Select
  513.     If LastInput <> "NEG" Then
  514.     LastInput = "OPS"
  515.     OpFlag = Operator(Index).Caption
  516.     End If
  517. End Sub
  518.  
  519. ' Click event procedure for percent key (%).
  520. ' Compute and display a percentage of the first operand.
  521. '
  522. Sub Percent_Click ()
  523.     ReadOut = ReadOut / 100
  524.     LastInput = "Ops"
  525.     OpFlag = "%"
  526.     NumOps = NumOps + 1
  527.     DecimalFlag = True
  528. End Sub
  529.  
  530. Sub Picture1_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  531.     PixStartX = (Calculator.Left) / TPRatio
  532.     PixStartY = (Calculator.Top) / TPRatio
  533.     PixOffsetX = Int(X / TPRatio)
  534.     PixOffsetY = Int(Y / TPRatio)
  535.     OkToMove = True
  536.     GhostForm PixStartX, PixStartY, PixStartX + (Calculator.Width / TPRatio), PixStartY + (Calculator.Height / TPRatio)
  537. End Sub
  538.  
  539. Sub Picture1_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  540.     If Button = 1 And OkToMove = True Then
  541.     OkToMove = False
  542.     PixX = Int(X / TPRatio) - PixOffsetX
  543.     PixY = Int(Y / TPRatio) - PixOffsetY
  544.     GhostForm PixStartX, PixStartY, PixStartX + (Calculator.Width / TPRatio), PixStartY + (Calculator.Height / TPRatio)
  545.     GhostForm PixStartX + PixX, PixStartY + PixY, PixStartX + PixX + (Calculator.Width / TPRatio), PixStartY + PixY + (Calculator.Height / TPRatio)
  546.     PixOffsetX = Int(X / TPRatio)
  547.     PixOffsetY = Int(Y / TPRatio)
  548.     PixStartX = PixStartX + PixX
  549.     PixStartY = PixStartY + PixY
  550.     OkToMove = True
  551.     End If
  552. End Sub
  553.  
  554. Sub Picture1_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
  555.     GhostForm PixStartX, PixStartY, PixStartX + (Calculator.Width / TPRatio), PixStartY + (Calculator.Height / TPRatio)
  556.     Calculator.Move (PixStartX) * TPRatio, (PixStartY) * TPRatio
  557. End Sub
  558.  
  559. Sub Picture1_Paint ()
  560.     ShadeControl Picture1, picShade
  561. End Sub
  562.  
  563.