home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1996 November / VPR9611A.ISO / vpr_data / vb32 / vb4wm / vb4-3.cab / calc.frm < prev    next >
Text File  |  1996-01-12  |  12KB  |  465 lines

  1. VERSION 4.00
  2. Begin VB.Form Calculator 
  3.    BorderStyle     =   1  '固定 (実線)
  4.    Caption         =   "電卓"
  5.    ClientHeight    =   2970
  6.    ClientLeft      =   2580
  7.    ClientTop       =   1485
  8.    ClientWidth     =   3270
  9.    ClipControls    =   0   'False
  10.    BeginProperty Font 
  11. name = "標準ゴシック"
  12.       charset         =   1
  13.       weight          =   700
  14.       size            =   9.75
  15.       underline       =   0   'False
  16.       italic          =   0   'False
  17.       strikethrough   =   0   'False
  18.  
  19. Bold = 0
  20.    EndProperty
  21.    Height          =   3375
  22.    Icon            =   "CALC.frx":0000
  23.    Left            =   2520
  24.    LinkMode        =   1  'ソース
  25.    LinkTopic       =   "Form1"
  26.    MaxButton       =   0   'False
  27.    ScaleHeight     =   2970
  28.    ScaleWidth      =   3270
  29.    Top             =   1140
  30.    Width           =   3390
  31.    Begin VB.CommandButton Number 
  32.       Caption         =   "7"
  33.       Height          =   480
  34.       Index           =   7
  35.       Left            =   120
  36.       TabIndex        =   7
  37.       Top             =   600
  38.       Width           =   480
  39. BeginProperty Font
  40. name = "標準ゴシック"
  41. size = 9
  42.  
  43. Bold = 0
  44. EndProperty
  45.    End
  46.    Begin VB.CommandButton Number 
  47.       Caption         =   "8"
  48.       Height          =   480
  49.       Index           =   8
  50.       Left            =   720
  51.       TabIndex        =   8
  52.       Top             =   600
  53.       Width           =   480
  54. BeginProperty Font
  55. name = "標準ゴシック"
  56. size = 9
  57.  
  58. Bold = 0
  59. EndProperty
  60.    End
  61.    Begin VB.CommandButton Number 
  62.       Caption         =   "9"
  63.       Height          =   480
  64.       Index           =   9
  65.       Left            =   1320
  66.       TabIndex        =   9
  67.       Top             =   600
  68.       Width           =   480
  69. BeginProperty Font
  70. name = "標準ゴシック"
  71. size = 9
  72.  
  73. Bold = 0
  74. EndProperty
  75.    End
  76.    Begin VB.CommandButton Cancel 
  77.       Caption         =   "C"
  78.       Height          =   480
  79.       Left            =   2040
  80.       TabIndex        =   10
  81.       Top             =   600
  82.       Width           =   480
  83. BeginProperty Font
  84. name = "標準ゴシック"
  85. size = 9
  86.  
  87. Bold = 0
  88. EndProperty
  89.    End
  90.    Begin VB.CommandButton CancelEntry 
  91.       Caption         =   "CE"
  92.       Height          =   480
  93.       Left            =   2640
  94.       TabIndex        =   11
  95.       Top             =   600
  96.       Width           =   480
  97. BeginProperty Font
  98. name = "標準ゴシック"
  99. size = 9
  100.  
  101. Bold = 0
  102. EndProperty
  103.    End
  104.    Begin VB.CommandButton Number 
  105.       Caption         =   "4"
  106.       Height          =   480
  107.       Index           =   4
  108.       Left            =   120
  109.       TabIndex        =   4
  110.       Top             =   1200
  111.       Width           =   480
  112. BeginProperty Font
  113. name = "標準ゴシック"
  114. size = 9
  115.  
  116. Bold = 0
  117. EndProperty
  118.    End
  119.    Begin VB.CommandButton Number 
  120.       Caption         =   "5"
  121.       Height          =   480
  122.       Index           =   5
  123.       Left            =   720
  124.       TabIndex        =   5
  125.       Top             =   1200
  126.       Width           =   480
  127. BeginProperty Font
  128. name = "標準ゴシック"
  129. size = 9
  130.  
  131. Bold = 0
  132. EndProperty
  133.    End
  134.    Begin VB.CommandButton Number 
  135.       Caption         =   "6"
  136.       Height          =   480
  137.       Index           =   6
  138.       Left            =   1320
  139.       TabIndex        =   6
  140.       Top             =   1200
  141.       Width           =   480
  142. BeginProperty Font
  143. name = "標準ゴシック"
  144. size = 9
  145.  
  146. Bold = 0
  147. EndProperty
  148.    End
  149.    Begin VB.CommandButton Operator 
  150.       Caption         =   "+"
  151.       Height          =   480
  152.       Index           =   1
  153.       Left            =   2040
  154.       TabIndex        =   12
  155.       Top             =   1200
  156.       Width           =   480
  157. BeginProperty Font
  158. name = "標準ゴシック"
  159. size = 9
  160.  
  161. Bold = 0
  162. EndProperty
  163.    End
  164.    Begin VB.CommandButton Operator 
  165.       Caption         =   "-"
  166.       Height          =   480
  167.       Index           =   3
  168.       Left            =   2640
  169.       TabIndex        =   13
  170.       Top             =   1200
  171.       Width           =   480
  172. BeginProperty Font
  173. name = "標準ゴシック"
  174. size = 9
  175.  
  176. Bold = 0
  177. EndProperty
  178.    End
  179.    Begin VB.CommandButton Number 
  180.       Caption         =   "1"
  181.       Height          =   480
  182.       Index           =   1
  183.       Left            =   120
  184.       TabIndex        =   1
  185.       Top             =   1800
  186.       Width           =   480
  187. BeginProperty Font
  188. name = "標準ゴシック"
  189. size = 9
  190.  
  191. Bold = 0
  192. EndProperty
  193.    End
  194.    Begin VB.CommandButton Number 
  195.       Caption         =   "2"
  196.       Height          =   480
  197.       Index           =   2
  198.       Left            =   720
  199.       TabIndex        =   2
  200.       Top             =   1800
  201.       Width           =   480
  202. BeginProperty Font
  203. name = "標準ゴシック"
  204. size = 9
  205.  
  206. Bold = 0
  207. EndProperty
  208.    End
  209.    Begin VB.CommandButton Number 
  210.       Caption         =   "3"
  211.       Height          =   480
  212.       Index           =   3
  213.       Left            =   1320
  214.       TabIndex        =   3
  215.       Top             =   1800
  216.       Width           =   480
  217. BeginProperty Font
  218. name = "標準ゴシック"
  219. size = 9
  220.  
  221. Bold = 0
  222. EndProperty
  223.    End
  224.    Begin VB.CommandButton Operator 
  225.       Caption         =   "X"
  226.       Height          =   480
  227.       Index           =   2
  228.       Left            =   2040
  229.       TabIndex        =   14
  230.       Top             =   1800
  231.       Width           =   480
  232. BeginProperty Font
  233. name = "標準ゴシック"
  234. size = 9
  235.  
  236. Bold = 0
  237. EndProperty
  238.    End
  239.    Begin VB.CommandButton Operator 
  240.       Caption         =   "/"
  241.       Height          =   480
  242.       Index           =   0
  243.       Left            =   2640
  244.       TabIndex        =   15
  245.       Top             =   1800
  246.       Width           =   480
  247. BeginProperty Font
  248. name = "標準ゴシック"
  249. size = 9
  250.  
  251. Bold = 0
  252. EndProperty
  253.    End
  254.    Begin VB.CommandButton Number 
  255.       Caption         =   "0"
  256.       Height          =   480
  257.       Index           =   0
  258.       Left            =   120
  259.       TabIndex        =   0
  260.       Top             =   2400
  261.       Width           =   1080
  262. BeginProperty Font
  263. name = "標準ゴシック"
  264. size = 9
  265.  
  266. Bold = 0
  267. EndProperty
  268.    End
  269.    Begin VB.CommandButton Decimal 
  270.       Caption         =   "."
  271.       Height          =   480
  272.       Left            =   1320
  273.       TabIndex        =   18
  274.       Top             =   2400
  275.       Width           =   480
  276. BeginProperty Font
  277. name = "標準ゴシック"
  278. size = 9
  279.  
  280. Bold = 0
  281. EndProperty
  282.    End
  283.    Begin VB.CommandButton Operator 
  284.       Caption         =   "="
  285.       Height          =   480
  286.       Index           =   4
  287.       Left            =   2040
  288.       TabIndex        =   16
  289.       Top             =   2400
  290.       Width           =   480
  291. BeginProperty Font
  292. name = "標準ゴシック"
  293. size = 9
  294.  
  295. Bold = 0
  296. EndProperty
  297.    End
  298.    Begin VB.CommandButton Percent 
  299.       Caption         =   "%"
  300.       Height          =   480
  301.       Left            =   2640
  302.       TabIndex        =   17
  303.       Top             =   2400
  304.       Width           =   480
  305. BeginProperty Font
  306. name = "標準ゴシック"
  307. size = 9
  308.  
  309. Bold = 0
  310. EndProperty
  311.    End
  312.    Begin VB.Label Readout 
  313.       Alignment       =   1  '右揃え
  314.       BackColor       =   &H0000FFFF&
  315.       BorderStyle     =   1  '実線
  316.       Caption         =   "0."
  317.       BeginProperty Font 
  318. name = "標準ゴシック"
  319.          charset         =   1
  320.          weight          =   700
  321.          size            =   12
  322.          underline       =   0   'False
  323.          italic          =   0   'False
  324.          strikethrough   =   0   'False
  325.  
  326. Bold = 0
  327.       EndProperty
  328.       ForeColor       =   &H00000000&
  329.       Height          =   375
  330.       Left            =   120
  331.       TabIndex        =   19
  332.       Top             =   105
  333.       Width           =   3000
  334.    End
  335. End
  336. Attribute VB_Name = "Calculator"
  337. Attribute VB_Creatable = False
  338. Attribute VB_Exposed = False
  339.  
  340. Option Explicit
  341. Dim Op1, Op2                ' 直前に入力されたオペランド
  342. Dim DecimalFlag As Integer  ' 小数点の有無
  343. Dim NumOps As Integer       ' オペランドの数
  344. Dim LastInput               ' 直前にクリックされたボタンの種類
  345. Dim OpFlag                  ' 保留中の演算
  346. Dim TempReadout
  347.  
  348. ' [C] ボタン (取り消し) の Click イベント プロシージャ
  349. ' 表示をリセットして、変数を初期化します。
  350. Private Sub Cancel_Click()
  351.     ReadOut = Format(0, "0.")
  352.     Op1 = 0
  353.     Op2 = 0
  354.     Form_Load
  355. End Sub
  356.  
  357. ' [CE] ボタン (入力取り消し) の Click イベント プロシージャ
  358. Private Sub CancelEntry_Click()
  359.     ReadOut = Format(0, "0.")
  360.     DecimalFlag = False
  361.     LastInput = "CE"
  362. End Sub
  363.  
  364. ' [.] ボタン (小数点)の Click イベント プロシージャ
  365. ' 直前にクリックされたボタンが演算子の場合、表示を "0." に初期化します。
  366. ' 直前にクリックされたボタンが演算子以外の場合、表示に小数点を追加します。
  367. Private Sub Decimal_Click()
  368.     If LastInput = "NEG" Then
  369.         ReadOut = Format(0, "-0.")
  370.     ElseIf LastInput <> "NUMS" Then
  371.         ReadOut = Format(0, "0.")
  372.     End If
  373.     DecimalFlag = True
  374.     LastInput = "NUMS"
  375. End Sub
  376.  
  377. ' フォームの初期化ルーチン
  378. ' 変数をすべて初期値に設定します。
  379. Private Sub Form_Load()
  380.     DecimalFlag = False
  381.     NumOps = 0
  382.     LastInput = "NONE"
  383.     OpFlag = " "
  384.     ReadOut = Format(0, "0.")
  385.     Decimal.Caption = Format(0, ".")
  386. End Sub
  387.  
  388. ' 数値ボタン (0-9) の Click イベント プロシージャ
  389. ' 表示されている数に新しい数を追加します。
  390. Private Sub Number_Click(Index As Integer)
  391.     If LastInput <> "NUMS" Then
  392.         ReadOut = Format(0, ".")
  393.         DecimalFlag = False
  394.     End If
  395.     If DecimalFlag Then
  396.         ReadOut = ReadOut + Number(Index).Caption
  397.     Else
  398.         ReadOut = Left(ReadOut, InStr(ReadOut, Format(0, ".")) - 1) + Number(Index).Caption + Format(0, ".")
  399.     End If
  400.     If LastInput = "NEG" Then ReadOut = "-" & ReadOut
  401.     LastInput = "NUMS"
  402. End Sub
  403.  
  404. ' 演算ボタン (+, -, x, /, =) の Click イベント プロシージャ
  405. ' 直前にクリックされたボタンが数値の場合、NumOps を増加させます。
  406. ' オペランドが 1 つのときは、Op1 を設定します。
  407. ' オペランドが 2 つのときは、Op1 と現在の入力文字列の演算結果を
  408. ' Op1 として設定し、表示します。
  409. Private Sub Operator_Click(Index As Integer)
  410.     TempReadout = ReadOut
  411.     If LastInput = "NUMS" Then
  412.         NumOps = NumOps + 1
  413.     End If
  414.     Select Case NumOps
  415.         Case 0
  416.         If Operator(Index).Caption = "-" And LastInput <> "NEG" Then
  417.             ReadOut = "-" & ReadOut
  418.             LastInput = "NEG"
  419.         End If
  420.         Case 1
  421.         Op1 = ReadOut
  422.         If Operator(Index).Caption = "-" And LastInput <> "NUMS" And OpFlag <> "=" Then
  423.             ReadOut = "-"
  424.             LastInput = "NEG"
  425.         End If
  426.         Case 2
  427.         Op2 = TempReadout
  428.         Select Case OpFlag
  429.             Case "+"
  430.                 Op1 = CDbl(Op1) + CDbl(Op2)
  431.             Case "-"
  432.                 Op1 = CDbl(Op1) - CDbl(Op2)
  433.             Case "X"
  434.                 Op1 = CDbl(Op1) * CDbl(Op2)
  435.             Case "/"
  436.                 If Op2 = 0 Then
  437.                    MsgBox "ゼロでは除算できません。", 48, "電卓"
  438.                 Else
  439.                    Op1 = CDbl(Op1) / CDbl(Op2)
  440.                 End If
  441.             Case "="
  442.                 Op1 = CDbl(Op2)
  443.             Case "%"
  444.                 Op1 = CDbl(Op1) * CDbl(Op2)
  445.             End Select
  446.         ReadOut = Op1
  447.         NumOps = 1
  448.     End Select
  449.     If LastInput <> "NEG" Then
  450.         LastInput = "OPS"
  451.         OpFlag = Operator(Index).Caption
  452.     End If
  453. End Sub
  454.  
  455. ' [%] ボタン (パーセント) の Click イベント プロシージャ
  456. ' 最初のオペランドのパーセンテージを計算して表示します。
  457. Private Sub Percent_Click()
  458.     ReadOut = ReadOut / 100
  459.     LastInput = "Ops"
  460.     OpFlag = "%"
  461.     NumOps = NumOps + 1
  462.     DecimalFlag = True
  463. End Sub
  464.  
  465.