VERSION 5.00
Begin VB.Form MainDialog 
   AutoRedraw      =   -1  'True
   Caption         =   "Magn1 Tutorial: Lesson2"
   ClientHeight    =   6810
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   11535
   LinkTopic       =   "Form1"
   ScaleHeight     =   454
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   769
   StartUpPosition =   3  'Windows Default
   Begin VB.Frame Frame1 
      Caption         =   "Choose Picture"
      Height          =   1695
      Left            =   6600
      TabIndex        =   23
      Top             =   4440
      Width           =   3015
      Begin VB.OptionButton optSketch 
         Caption         =   "View Result"
         Enabled         =   0   'False
         Height          =   375
         Index           =   2
         Left            =   240
         TabIndex        =   25
         Top             =   1080
         Width           =   1815
      End
      Begin VB.OptionButton optSketch 
         Caption         =   "View Geometry"
         Enabled         =   0   'False
         Height          =   375
         Index           =   1
         Left            =   240
         TabIndex        =   24
         Top             =   720
         Width           =   1575
      End
      Begin VB.OptionButton optSketch 
         Caption         =   "View Sketch"
         Height          =   375
         Index           =   0
         Left            =   240
         TabIndex        =   11
         Top             =   360
         Value           =   -1  'True
         Width           =   1455
      End
   End
   Begin VB.TextBox txtForce 
      ForeColor       =   &H00000000&
      Height          =   315
      Left            =   8400
      Locked          =   -1  'True
      TabIndex        =   9
      Top             =   3840
      Width           =   1695
   End
   Begin VB.TextBox txtHc 
      Height          =   315
      Left            =   8400
      TabIndex        =   8
      Text            =   "147218"
      Top             =   3000
      Width           =   1695
   End
   Begin VB.TextBox txtHy 
      Height          =   315
      Left            =   9600
      TabIndex        =   2
      Text            =   "20"
      Top             =   960
      Width           =   1455
   End
   Begin VB.TextBox txtWy 
      Height          =   315
      Left            =   7680
      TabIndex        =   1
      Text            =   "80"
      Top             =   960
      Width           =   1455
   End
   Begin VB.TextBox txtGap 
      Height          =   315
      Left            =   9600
      TabIndex        =   7
      Text            =   "10"
      Top             =   2040
      Width           =   1455
   End
   Begin VB.TextBox txtHk 
      Height          =   315
      Left            =   9600
      TabIndex        =   6
      Text            =   "40"
      Top             =   1680
      Width           =   1455
   End
   Begin VB.TextBox txtHm 
      Height          =   315
      Left            =   9600
      TabIndex        =   4
      Text            =   "20"
      Top             =   1320
      Width           =   1455
   End
   Begin VB.TextBox txtWk 
      Height          =   315
      Left            =   7680
      TabIndex        =   5
      Text            =   "80"
      Top             =   1680
      Width           =   1455
   End
   Begin VB.TextBox txtWm 
      Height          =   315
      Left            =   7680
      TabIndex        =   3
      Text            =   "20"
      Top             =   1320
      Width           =   1455
   End
   Begin VB.CommandButton cmdClose 
      Caption         =   "Close"
      Height          =   420
      Left            =   10080
      TabIndex        =   12
      Top             =   6360
      Width           =   1275
   End
   Begin VB.CommandButton cmdCalculate 
      Caption         =   "&Calculate"
      Height          =   420
      Left            =   10080
      TabIndex        =   10
      Top             =   4680
      Width           =   1275
   End
   Begin VB.PictureBox ctlPicture 
      BackColor       =   &H00FFFFFF&
      Height          =   6435
      Left            =   0
      Picture         =   "MainDialog.frx":0000
      ScaleHeight     =   6340.327
      ScaleMode       =   0  'User
      ScaleWidth      =   6340.327
      TabIndex        =   0
      Top             =   240
      Width           =   6435
   End
   Begin VB.Line Line8 
      X1              =   440
      X2              =   760
      Y1              =   416
      Y2              =   416
   End
   Begin VB.Label Label3 
      Caption         =   "(N)"
      Height          =   255
      Left            =   10320
      TabIndex        =   22
      Top             =   3840
      Width           =   255
   End
   Begin VB.Label Label2 
      Caption         =   "Magnet Lift Power:"
      Height          =   375
      Left            =   6600
      TabIndex        =   21
      Top             =   3840
      Width           =   1455
   End
   Begin VB.Line Line7 
      X1              =   440
      X2              =   760
      Y1              =   240
      Y2              =   240
   End
   Begin VB.Label lblHcUnit 
      Caption         =   "(A/m)"
      Height          =   375
      Left            =   10320
      TabIndex        =   20
      Top             =   3000
      Width           =   735
   End
   Begin VB.Label lblHc 
      Caption         =   "Magnet Coercive Force"
      Height          =   375
      Left            =   6600
      TabIndex        =   19
      Top             =   3000
      Width           =   2175
   End
   Begin VB.Line Line6 
      X1              =   752
      X2              =   752
      Y1              =   16
      Y2              =   176
   End
   Begin VB.Label lblWidth 
      Caption         =   "Width"
      Height          =   255
      Left            =   8160
      TabIndex        =   18
      Top             =   360
      Width           =   1095
   End
   Begin VB.Label lblHeight 
      Caption         =   "Height"
      Height          =   255
      Left            =   10080
      TabIndex        =   17
      Top             =   360
      Width           =   615
   End
   Begin VB.Label lblYoke 
      Caption         =   "Frame Yoke"
      Height          =   255
      Left            =   6720
      TabIndex        =   16
      Top             =   960
      Width           =   975
   End
   Begin VB.Label lblMagnet 
      Caption         =   "Magnet"
      Height          =   255
      Left            =   6720
      TabIndex        =   15
      Top             =   1320
      Width           =   975
   End
   Begin VB.Label lblKeeper 
      Caption         =   "Keeper"
      Height          =   255
      Left            =   6720
      TabIndex        =   14
      Top             =   1680
      Width           =   975
   End
   Begin VB.Line Line4 
      X1              =   624
      X2              =   624
      Y1              =   16
      Y2              =   176
   End
   Begin VB.Line Line5 
      X1              =   440
      X2              =   752
      Y1              =   176
      Y2              =   176
   End
   Begin VB.Line Line2 
      X1              =   440
      X2              =   440
      Y1              =   16
      Y2              =   176
   End
   Begin VB.Label lblGap 
      Caption         =   "Air Gap"
      Height          =   255
      Left            =   6720
      TabIndex        =   13
      Top             =   2040
      Width           =   975
   End
   Begin VB.Line Line3 
      X1              =   440
      X2              =   752
      Y1              =   48
      Y2              =   48
   End
   Begin VB.Line Line1 
      X1              =   440
      X2              =   752
      Y1              =   16
      Y2              =   16
   End
End
Attribute VB_Name = "MainDialog"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub Form_Initialize()
    ' Remember the Sketch to be able show it again
    Set sketchPicture = ctlPicture.Picture
End Sub

Private Sub cmdCalculate_Click()
    If GetInputParameters() Then
        DoCalculation
        optSketch(1).Enabled = True
        optSketch(2).Enabled = True
    End If
End Sub

Private Sub cmdClose_Click()
    Unload Me
End Sub

Public Function GetInputParameters() As Boolean
    On Error GoTo InvalidData
    yokeWidth = txtWy.Text
    yokeHeight = txtHy.Text
    maghetWidth = txtWm.Text
    magnetHeight = txtHm.Text
    keeperWidth = txtWk.Text
    keeperHeight = txtHk.Text
    airGap = txtGap.Text
    Hc = txtHc.Text
    GetInputParameters = True
    
    optSketch(1).Enabled = False
    optSketch(2).Enabled = False
    Exit Function
    
InvalidData:
    GetInputParameters = False
End Function

Public Sub DisplayForce(ByVal force As Double)
    txtForce.Text = FormatNumber(force, 3)
End Sub

Private Sub optSketch_Click(Index As Integer)
    Select Case Index
    Case 0
        Set ctlPicture.Picture = sketchPicture
    Case 1
        Set ctlPicture.Picture = geomPicture
    Case 2
        Set ctlPicture.Picture = resultPicture
    End Select
End Sub

