home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Advanced_P53335252002.psc / frmSample2.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2002-02-02  |  5.5 KB  |  170 lines

  1. VERSION 5.00
  2. Begin VB.Form frmSample2 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Sample 2: Calculator"
  5.    ClientHeight    =   3540
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   5235
  9.    Icon            =   "frmSample2.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    ScaleHeight     =   3540
  13.    ScaleWidth      =   5235
  14.    StartUpPosition =   2  'CenterScreen
  15.    Begin VB.CommandButton cmdClose 
  16.       Cancel          =   -1  'True
  17.       Caption         =   "&Close"
  18.       Height          =   375
  19.       Left            =   120
  20.       TabIndex        =   8
  21.       Top             =   3120
  22.       Width           =   1215
  23.    End
  24.    Begin VB.CommandButton cmdDivide 
  25.       Caption         =   "&Divide!"
  26.       Height          =   375
  27.       Left            =   3240
  28.       TabIndex        =   6
  29.       Top             =   1170
  30.       Width           =   1095
  31.    End
  32.    Begin VB.TextBox txtSecondNumber 
  33.       Height          =   285
  34.       Left            =   1560
  35.       TabIndex        =   3
  36.       Top             =   1200
  37.       Width           =   495
  38.    End
  39.    Begin VB.TextBox txtFirstNumber 
  40.       Height          =   285
  41.       Left            =   720
  42.       TabIndex        =   2
  43.       Top             =   1200
  44.       Width           =   495
  45.    End
  46.    Begin VB.Label Label4 
  47.       Caption         =   $"frmSample2.frx":0442
  48.       Height          =   615
  49.       Left            =   120
  50.       TabIndex        =   10
  51.       Top             =   1800
  52.       Width           =   4935
  53.    End
  54.    Begin VB.Label Label3 
  55.       Caption         =   "Closes this and returns to the previous example."
  56.       Height          =   255
  57.       Left            =   1440
  58.       TabIndex        =   9
  59.       Top             =   3240
  60.       Width           =   3495
  61.    End
  62.    Begin VB.Label lblQuotient 
  63.       BorderStyle     =   1  'Fixed Single
  64.       Height          =   255
  65.       Left            =   2415
  66.       TabIndex        =   7
  67.       Top             =   1215
  68.       Width           =   735
  69.    End
  70.    Begin VB.Label lblEqualsSign 
  71.       Caption         =   "="
  72.       Height          =   255
  73.       Left            =   2160
  74.       TabIndex        =   5
  75.       Top             =   1200
  76.       Width           =   135
  77.    End
  78.    Begin VB.Label lblDivisionSign 
  79.       Caption         =   "/"
  80.       Height          =   255
  81.       Left            =   1320
  82.       TabIndex        =   4
  83.       Top             =   1230
  84.       Width           =   135
  85.    End
  86.    Begin VB.Label Label2 
  87.       Caption         =   "Enter two numbers to divide below, and press the ""Divide!"" button:"
  88.       Height          =   255
  89.       Left            =   120
  90.       TabIndex        =   1
  91.       Top             =   720
  92.       Width           =   4935
  93.    End
  94.    Begin VB.Label Label1 
  95.       Alignment       =   2  'Center
  96.       Caption         =   "Calculator"
  97.       BeginProperty Font 
  98.          Name            =   "Arial"
  99.          Size            =   12
  100.          Charset         =   0
  101.          Weight          =   700
  102.          Underline       =   0   'False
  103.          Italic          =   0   'False
  104.          Strikethrough   =   0   'False
  105.       EndProperty
  106.       Height          =   255
  107.       Left            =   120
  108.       TabIndex        =   0
  109.       Top             =   120
  110.       Width           =   4935
  111.    End
  112. Attribute VB_Name = "frmSample2"
  113. Attribute VB_GlobalNameSpace = False
  114. Attribute VB_Creatable = False
  115. Attribute VB_PredeclaredId = True
  116. Attribute VB_Exposed = False
  117. Private Sub cmdClose_Click()
  118. Unload Me
  119. frmSample.Show
  120. End Sub
  121. Private Sub cmdDivide_Click()
  122. 'Variables used if balloon is shown:
  123. Dim WinRect As RECT
  124. Dim WinPoint As POINTAPI
  125. Dim BalloonXY As BalloonCoords
  126. ' Check for division by zero before we start to divide, because
  127. ' it would cause an error if we didn't
  128. If txtSecondNumber.Text = "0" Then 'Show the error balloon
  129.     Call GetWindowRect(txtSecondNumber.hwnd, WinRect)
  130.     BalloonXY.X = WinRect.Left * Screen.TwipsPerPixelX
  131.     BalloonXY.Y = WinRect.Bottom * Screen.TwipsPerPixelY
  132.     Dim frmDivisionByZero As New frmTip
  133.     frmDivisionByZero.SetBalloon "Division by Zero", "You have attempted a " & _
  134.         "division by zero, which is not possible. Please check your second number " & _
  135.         "and try again.", BalloonXY.X, BalloonXY.Y, _
  136.         "x", True, 10000
  137.     frmDivisionByZero.Show , Me
  138.     Me.SetFocus
  139.     Exit Sub
  140. End If
  141. ' Divide the two numbers
  142. On Error GoTo DivisionError
  143. lblQuotient.Caption = Me.txtFirstNumber.Text / Me.txtSecondNumber.Text
  144. Exit Sub
  145. DivisionError:
  146. Call GetWindowRect(cmdDivide.hwnd, WinRect)
  147. BalloonXY.X = WinRect.Left * Screen.TwipsPerPixelX
  148. BalloonXY.Y = WinRect.Bottom * Screen.TwipsPerPixelY
  149. Dim frmDivisionError As New frmTip
  150. frmDivisionError.SetBalloon "Division Error", "An error occured trying to " & _
  151.     "divide the numbers. Make sure they are both valid numbers, don't contain " & _
  152.     "letters, etc., and try again." & vbCrLf & vbCrLf & "This also " & _
  153.     "demonstrates a balloon with a different font!", BalloonXY.X, BalloonXY.Y, _
  154.     "x", True, 10000, 1720, , "Arial"
  155. frmDivisionError.Show , Me
  156. Me.SetFocus
  157. End Sub
  158. Private Sub Form_Load()
  159. End Sub
  160. Private Sub txtFirstNumber_KeyPress(KeyAscii As Integer)
  161. If KeyAscii = vbKeyReturn Then
  162.     txtSecondNumber.SetFocus
  163. End If
  164. End Sub
  165. Private Sub txtSecondNumber_KeyPress(KeyAscii As Integer)
  166. If KeyAscii = vbKeyReturn Then
  167.     cmdDivide_Click
  168. End If
  169. End Sub
  170.