'===========================================================================
' Subject: Math-Expression Evaluator          Date: 09-29-01 (  :  )       
'  Author: Achilles B. Mina                   Code: rapidq                 
'  Origin: wasaywasay@i-manila.com.ph       Packet: RAPIDQ.ABC
'===========================================================================
'QEDTukak 1.54
'Math-Expression Evaluator
'By Achilles B.Mina
'Updated: 9/29/2001

'This utility is one of the modules of Calculait, a full-featured
'scientific calculator with a world clock. It's downloadable at
'ZDNet, CNet, RocketDownload, CNet and other freeware sites, and
'at my website at http://pages.zdnet.com/wasaywasay/wasaywasay/

'You can do as you please with this code.

$INCLUDE "RAPIDQ.INC"
$ESCAPECHARS ON

'$RESOURCE QEDTukak AS "qedtukak.ico"
'$RESOURCE lionroar AS "lionroar.wav"
'$RESOURCE camera AS "camera.wav"
'$RESOURCE cashreg AS "cashreg.wav"
'$RESOURCE chicken AS "chicken.wav"
'$RESOURCE cuckoo AS "cuckoo.wav"
'$RESOURCE wipe AS "wipe.wav"
'$RESOURCE gong AS "gong.wav"
'$RESOURCE handbell AS "handbell.wav"
'$RESOURCE laser AS "laser.wav"
'$RESOURCE typing AS "typing.wav"
'$RESOURCE whooh AS "whooh.wav"
'$RESOURCE whoosh AS "whoosh.wav


DECLARE FUNCTION AnimateWindow Lib "user32" Alias "AnimateWindow"(ByVal hwnd As Long, ByVal dwTime As Long, ByVal dwFlags As Long) As Integer
DECLARE SUB Animate(Handle AS INTEGER)
DECLARE SUB Deanimate(Handle AS INTEGER)
DECLARE SUB CloseHistory
DECLARE SUB CloseFunctions
DECLARE SUB CloseVariables
DECLARE FUNCTION PaintDesktop LIB "USER32" ALIAS "PaintDesktop" (HDC AS INTEGER) AS INTEGER
DECLARE FUNCTION GetDC LIB "USER32" ALIAS "GetDC" (HWND AS INTEGER) AS INTEGER
Declare Function SetForegroundWindow Lib "user32" ALIAS "SetForegroundWindow" (hwnd As Long) As Long
DECLARE SUB SetWindowPos Lib "User32" ALIAS "SetWindowPos"(hWnd As Long, hWndInsertAfter As Long, X As Long, Y As Long, cx As Long, cy As Long, wFlags As Long)
DECLARE Function GetFocus Lib "user32" Alias "GetFocus"() As Long
DECLARE FUNCTION SetFocus LIB "USER32" ALIAS "SetFocus" (HWnd AS LONG) AS LONG
DECLARE FUNCTION LoadCursorFromFile LIB "USER32" ALIAS "LoadCursorFromFileA" _
                 (CursorFileName AS STRING) AS LONG
DECLARE SUB DummyMin(Hwnd&, uMsg&, wParam&, lParam&)
DECLARE SUB OnTop
DECLARE SUB Click
DECLARE SUB ChangeMode
DECLARE SUB EmailMe
DECLARE SUB SendMe
DECLARE SUB CloseSolver
DECLARE SUB ClrLastExpEdit
DECLARE SUB ClrExpEdit
DECLARE SUB OperatorButts 
DECLARE SUB MathButts(Sender AS QBUTTON)
DECLARE SUB CheckE(newstring$ AS STRING)
DECLARE SUB ExpSolver
DECLARE SUB ExpSolverEdit
DECLARE SUB Functions(par1 AS INTEGER, mathval$ AS STRING)
DECLARE SUB DoInPrecision(value AS DOUBLE, value$ AS STRING)
DECLARE SUB DoPrecision
DECLARE SUB preCheckSyntax
DECLARE SUB CheckSyntax(key AS BYTE)
DECLARE SUB SaveFile
DECLARE SUB PrintFile
DECLARE SUB OutUser(Sender AS QMENUITEM)
DECLARE SUB OutScientific
DECLARE SUB OutFinancial
DECLARE SUB OutComma
DECLARE SUB OutNone
DECLARE SUB OutFormat
DECLARE SUB OutFormatType
DECLARE SUB NotesShow
DECLARE SUB CloseNotes
DECLARE SUB ShowNotes
DECLARE SUB SoundOnOff
DECLARE SUB ClipboardCopy
DECLARE SUB ClipboardPaste
DECLARE SUB Time
DECLARE SUB MilSTDTime
DECLARE SUB ConstantsAll(Sender AS QMENUITEM)
DECLARE SUB ConstantsShow
DECLARE SUB FunctionsShow
DECLARE SUB HistoryShow
DECLARE SUB SendAnswer
DECLARE SUB changeE
DECLARE SUB Initialize
DECLARE SUB ConversionsShow
DECLARE SUB ConversionsAll(Sender AS QMENUITEM)
DECLARE SUB PaintForm
DECLARE SUB ResizeView
DECLARE SUB OutPrecision
DECLARE SUB VariablesShow
DECLARE SUB VariablesEntered(key AS BYTE)


DIM Math(1 TO 39) AS STRING
DEFSTR memvalue, outform$, precision$, MathText, formula$, oldexpression
DEFBYTE soundoff, dochecktag, military, always
DEFDBL CMode, CModeN

Const AW_CENTER = &H10 'Makes the window appear to collapse inward if AW_HIDE is used or expand outward if the AW_HIDE is not used.
Const AW_HIDE = &H10000 'Hides the window. By default, the window is shown.
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2

CREATE Arial10B AS QFONT
    Name = "Arial"
    Color = clBlack '&HEEFE   
    AddStyles(fsBold)
    Size = 10
END CREATE

CREATE ArialW AS QFONT
    Name = "Arial"
    Color = clWhite
    AddStyles(fsBold)
    Size = 12
END CREATE

CREATE ArialB AS QFONT
    Name = "Arial"
    Color = clBlack
    AddStyles(fsBold)
    Size = 12
END CREATE

CREATE Arial9B AS QFONT
    Name = "Arial"
    Color = clBlack
    AddStyles(fsBold)
    Size = 9
END CREATE

CREATE Arial9G AS QFONT
    Name = "Arial"
    Color = clGreen
    AddStyles(fsBold)
    Size = 9
END CREATE

CREATE Arial10W AS QFONT
    Name = "Arial"
    Color = clWhite
    AddStyles(fsBold)
    Size = 10
END CREATE

CREATE Arial9W AS QFONT
    Name = "Arial"
    Color = clWhite
    AddStyles(fsBold)
    Size = 9
END CREATE

CREATE Verdana10W AS QFONT
    Name = "Verdana"
    Color = clWhite
    AddStyles(fsBold)
    Size = 10
END CREATE

CREATE Timer1 AS QTIMER
  Enabled = 1
  Interval = 1000
  OnTimer = Time
END CREATE

CREATE Timer2 AS QTIMER
  Enabled = 0
  Interval = 1
  OnTimer = NotesShow
END CREATE

CREATE ExpSolverForm AS QFORM
  Center
  Height = 55
  Width = 430
  Color = &HABC777
  FormStyle = fsStayOnTop
  DelBorderIcons(biMaximize)
  BorderStyle = bsSingle
  Caption = "QEDTukak"
  Hint = "Right-click to bring up the menus, left-click to\n\rinvoke the Functions Selector & History View"
  ShowHint = 1
  WndProc = DummyMin
  OnClose = CloseSolver
  CREATE PopUp AS QPOPUPMENU
    CREATE ConstantsMenu AS QMENUITEM
      Caption = "&Constants"
      OnClick = ConstantsShow
    END CREATE
    CREATE ConsversionsMenu AS QMENUITEM
      Caption = "C&onversions"
      OnClick = ConversionsShow
    END CREATE
    CREATE FunctionsMenu AS QMENUITEM
      Caption = "F&unctions"
      OnClick = FunctionsShow
    END CREATE
    CREATE HistoryMenu AS QMENUITEM
      Caption = "&History"
      OnClick = HistoryShow
    END CREATE
    CREATE VarialblesMenu AS QMENUITEM
      Caption = "&Variables"
      OnClick = VariablesShow
    END CREATE        
    CREATE Edit AS QMENUITEM
      Caption = "&Edit"
      CREATE Copy AS QMENUITEM
        Caption = "&Copy    Ctrl+C"
        OnClick = ClipboardCopy
      END CREATE
      CREATE Paste AS QMENUITEM
        Caption = "&Paste   Ctrl+V"
        OnClick = ClipboardPaste
      END CREATE
    END CREATE
    CREATE File AS QMENUITEM
      Caption = "&File"
      CREATE SaveP AS QMENUITEM
        Caption = "&Save"
        OnClick = SaveFile
      END CREATE
      CREATE PrintP AS QMENUITEM
        Caption = "&Print"
        OnClick = PrintFile
      END CREATE 
    END CREATE    
    CREATE Format AS QMENUITEM
      Caption = "Fo&rmat"
      CREATE OutFin AS QMENUITEM
        Caption = "&Financial"
        OnClick = OutFinancial
      END CREATE
      CREATE OutSci AS QMENUITEM
        Caption = "&Scientific"
        OnClick = OutScientific
      END CREATE
      CREATE OutCom AS QMENUITEM
        Caption = "&Comma separated"
        OnClick = OutComma
      END CREATE
      CREATE OutNon AS QMENUITEM
        Caption = "&No format"
        OnClick = OutNone
      END CREATE
      CREATE OutNoForm AS QMENUITEM
        Caption = "&User-set precision"
        CREATE OutPrecise1 AS QMENUITEM
          Caption = "1"
          OnClick = OutUser
        END CREATE
        CREATE OutPrecise2 AS QMENUITEM
          Caption = "2"
          OnClick = OutUser
        END CREATE
        CREATE OutPrecise3 AS QMENUITEM
          Caption = "3"
          OnClick = OutUser
        END CREATE
        CREATE OutPrecise4 AS QMENUITEM
          Caption = "4"
          OnClick = OutUser
        END CREATE
        CREATE OutPrecise5 AS QMENUITEM
          Caption = "5"
          OnClick = OutUser
        END CREATE
        CREATE OutPrecise6 AS QMENUITEM
          Caption = "6"
          OnClick = OutUser
        END CREATE
        CREATE OutPrecise7 AS QMENUITEM
          Caption = "7"
          OnClick = OutUser
        END CREATE
        CREATE OutPrecise8 AS QMENUITEM
          Caption = "8"
          OnClick = OutUser
        END CREATE
        CREATE OutPrecise9 AS QMENUITEM
          Caption = "9"
          OnClick = OutUser
        END CREATE
        CREATE OutPrecise10 AS QMENUITEM
          Caption = "10"
          OnClick = OutUser
        END CREATE
        CREATE OutPrecise11 AS QMENUITEM
          Caption = "11"
          OnClick = OutUser
        END CREATE
        CREATE OutPrecise12 AS QMENUITEM
          Caption = "12"
          OnClick = OutUser
        END CREATE
        CREATE OutPrecise13 AS QMENUITEM
          Caption = "13"
          OnClick = OutUser
        END CREATE
        CREATE OutPrecise14 AS QMENUITEM
          Caption = "14"
          OnClick = OutUser
        END CREATE
        CREATE OutPrecise15 AS QMENUITEM
          Caption = "15"
          OnClick = OutUser
        END CREATE
      END CREATE                  
    END CREATE
    CREATE Options AS QMENUITEM
      Caption = "O&ptions"
      CREATE AlwaysTop AS QMENUITEM
        Caption = "&Always on top"
        OnClick = OnTop
      END CREATE   
      CREATE Sounds AS QMENUITEM
        Caption = "Switch sounds o&ff"
        OnClick = SoundOnOff
      END CREATE
      CREATE Times AS QMENUITEM
        Caption = "Switch to &Military Time"
        OnClick = MilSTDTime
      END CREATE
    END CREATE
    CREATE Notes AS QMENUITEM
      Caption = "&Notes"
      OnClick = ShowNotes
    END CREATE
  END CREATE
  CREATE ExpEdit AS QEDIT
    Top = 3
    Left = 3
    Height = 23
    Width = 317 '423
    Font = Arial10W
    Hint = "Type in entry then press Enter to get answer"
    ShowHint = 1
    Color = 0 '&HABC999
    OnKeyPress = CheckSyntax
  END CREATE
  CREATE DegRad AS QPANEL    'QBUTTON
    BevelOuter = 0
    BevelInner = 0
    BorderStyle = 1
    Color = 0
    Top = 4
    Left = 321
    Height = 23
    Width = 20
    Font = Arial9G
    Caption = "D"
    Hint = "Now in Degrees. Click for Radians."
    ShowHint= 1
    OnClick = ChangeMode
    Cursor = -21
  END CREATE
  CREATE TimePanel AS QPANEL
    Top = 3
    Left = 343
    Width = 78
    Height = 23
    Color = 0 '&HABC999
    BevelOuter = 0
    BevelInner = 0
    BorderStyle = 1
    Font = Arial10W
    Caption = TIME$
    Cursor = -21
    OnClick = Click 
  END CREATE
  CREATE VariablesForm AS QFORM
    Top = Screen.Height/2 + 29
    Left = Screen.Width/2 - 215
    Height = 112
    Width = 430
    FormStyle = fsStayOnTop
    DelBorderIcons(biMaximize)
    Hint = "Type in value of each variable you used above"
    ShowHint = 1
    Caption = "Variables Input"
    Color = &HABC999
    OnClose = CloseVariables
    CREATE UVarPanel AS QPANEL
      Top = 1
      Left = 5
      Width = 30
      Height = 25
      BevelOuter = 0
      Font = Arial10B
      Caption = " U = "
      Color = &HABC999
    END CREATE
    CREATE UVarEdit AS QEDIT
      Top = 1
      Left = 37
      Width = 170
      Height = 25
      Color = 0
      Font = Arial10W
      OnKeyPress = VariablesEntered
    END CREATE
    CREATE WVarPanel AS QPANEL
      Top = 30
      Left = 5
      Width = 30
      Height = 25
      BevelOuter = 0
      Font = Arial10B
      Caption = " W = "
      Color = &HABC999
    END CREATE
    CREATE WVarEdit AS QEDIT
      Top = 30
      Left = 37
      Width = 170
      Height = 25
      Color = 0
      Font = Arial10W
      OnKeyPress = VariablesEntered
    END CREATE
    CREATE YVarPanel AS QPANEL
      Top = 1
      Left = 215
      Width = 30
      Height = 25
      BevelOuter = 0
      Font = Arial10B
      Caption = " Y = "
      Color = &HABC999
    END CREATE
    CREATE YVarEdit AS QEDIT
      Top = 1
      Left = 247
      Width = 170
      Height = 25
      Color = 0
      Font = Arial10W
      OnKeyPress = VariablesEntered
    END CREATE
    CREATE ZVarPanel AS QPANEL
      Top = 30
      Left = 215
      Width = 30
      Height = 25
      BevelOuter = 0
      Font = Arial10B
      Caption = " Z = "
      Color = &HABC999
    END CREATE
    CREATE ZVarEdit AS QEDIT
      Top = 30
      Left = 247
      Width = 170
      Height = 25
      Color = 0
      Font = Arial10W
      OnKeyPress = VariablesEntered
    END CREATE
    CREATE JVarPanel AS QPANEL
      Top = 59
      Left = 5
      Width = 30
      Height = 25
      BevelOuter = 0
      Font = Arial10B
      Caption = " J = "
      Color = &HABC999
    END CREATE
    CREATE JVarEdit AS QEDIT
      Top = 59
      Left = 37
      Width = 170
      Height = 25
      Color = 0
      Font = Arial10W
      OnKeyPress = VariablesEntered
    END CREATE
    CREATE KVarPanel AS QPANEL
      Top = 59
      Left = 215
      Width = 30
      Height = 25
      BevelOuter = 0
      Font = Arial10B
      Caption = " K = "
      Color = &HABC999
    END CREATE
    CREATE KVarEdit AS QEDIT
      Top = 59
      Left = 247
      Width = 170
      Height = 25
      Color = 0
      Font = Arial10W
      OnKeyPress = VariablesEntered
    END CREATE
  END CREATE
  CREATE HistoryForm AS QFORM
    Color = &HABC111
    Top = Screen.Height/2 - 253
    Left = Screen.Width/2
    Caption = "History View"
    Width =  354 '296
    Height = 225    
    FormStyle = fsStayOnTop
    'DelBorderIcons(biMaximize)
    'BorderStyle = bsSingle
    OnClose = CloseHistory
    OnResize = ResizeView
    CREATE HistoryView AS QLISTBOX
      Top = 5
      Left = 5
      Height = HistoryForm.ClientHeight - 10
      Width = HistoryForm.ClientWidth - 10
      Color = 0 '&HABC999
      Font = Arial10W 'Verdana10W
    END CREATE
  END CREATE
  CREATE FunctionsForm AS QFORM   
    Top = Screen.Height/2 - 253
    Left = Screen.Width/2 - 354
    Caption = "Functions Selector"
    Width =  354 '296
    Height = 225    
    Color = 0 '&HABC999
    FormStyle = fsStayOnTop
    DelBorderIcons(biMaximize)
    BorderStyle = bsSingle
    Hint = "Right-click to bring up Constants Menu"
    ShowHint = 1
    Cursor = -21
    OnClose = CloseFunctions
    CREATE ZeroButt AS QBUTTON
      Font = ArialB
      Top = 5
      Left = 232
      Width = 58
      Height = 18
      Caption = "0"
      OnClick = MathButts
    END CREATE
    CREATE OneButt AS QBUTTON
      Font = ArialW
      Top = 24
      Left = 232
      Width = 58
      Height = 18
      Caption = "1"
      OnClick = MathButts
    END CREATE
    CREATE TwoButt AS QBUTTON
      Font = ArialB
      Top = 43
      Left = 232
      Width = 58
      Height = 18
      Caption = "2"
      OnClick = MathButts
    END CREATE
    CREATE ThreeButt AS QBUTTON
      Font = ArialW
      Top = 62
      Left = 232
      Width = 58
      Height = 18
      Caption = "3"
      OnClick = MathButts
    END CREATE
    CREATE FourButt AS QBUTTON
      Font = ArialB
      Top = 81
      Left = 232
      Width = 58
      Height = 18
      Caption = "4"
      OnClick = MathButts
    END CREATE
    CREATE FiveButt AS QBUTTON
      Font = ArialW
      Top = 100
      Left = 232
      Width = 58
      Height = 18
      Caption = "5"
      OnClick = MathButts
    END CREATE
    CREATE SixButt AS QBUTTON
      Font = ArialB
      Top = 119
      Left = 232
      Width = 58
      Height = 18
      Caption = "6"
      OnClick = MathButts
    END CREATE
    CREATE SevenButt AS QBUTTON
      Font = ArialW
      Top = 138
      Left = 232
      Width = 58
      Height = 18
      Caption = "7"
      OnClick = MathButts
    END CREATE
    CREATE EightButt AS QBUTTON
      Font = ArialB
      Top = 157
      Left = 232
      Width = 58
      Height = 18
      Caption = "8"
      OnClick = MathButts
    END CREATE
    CREATE NineButt AS QBUTTON
      Font = ArialW
      Top = 176
      Left = 232
      Width = 58
      Height = 18
      Caption = "9"
      OnClick = MathButts
    END CREATE
    CREATE ClrButt AS QOVALBTN
      Layout = -1
      Flat = 1
      Font = ArialW
      Top = 5
      Left = 290
      Width = 29
      Height = 18.5
      Caption = "AC"
      Hint = "Clear all"
      ShowHint = 1
      OnClick = ClrExpEdit
    END CREATE
    CREATE LastClrButt AS QOVALBTN
      Layout = -1
      Flat = 1
      Font = ArialW
      Top = 5
      Left = 319
      Width = 29
      Height = 18.5
      Caption = "C"
      Hint = "Clear last entry"
      ShowHint = 1
      OnClick = clrlastExpEdit
    END CREATE
    CREATE SendButt AS QBUTTON
      Font = Arial9B
      Top = 43
      Left = 290
      Width = 58
      Height = 18
      Caption = "Send"
      Hint = "Send answer to expression"
      ShowHint = 1
      OnClick = SendAnswer
    END CREATE
    CREATE AddButt AS QBUTTON
      Font = ArialW
      Top = 62
      Left = 290
      Width = 58
      Height = 18
      Caption = "+"
      Hint = "Addition"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE SubButt AS QBUTTON
      Font = ArialB
      Top = 81
      Left = 290
      Width = 58
      Height = 18
      Caption = "--"
      Hint = "Subtraction"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE MulButt AS QBUTTON
      Font = ArialW
      Top = 100
      Left = 290
      Width = 58
      Height = 18
      Caption = "x"
      Hint = "Multiplication"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE DivButt AS QBUTTON
      Font = ArialB
      Top = 119
      Left = 290
      Width = 58
      Height = 18
      Caption = "÷"
      Hint = "Division"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE PowButt AS QBUTTON
      Font = ArialW
      Top = 138
      Left = 290
      Width = 58
      Height = 18
      Caption = "^"
      Hint = "Raise to power..."
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE AnsButt AS QOVALBTN
      Layout = -1
      Flat = 1
      Font = ArialW
      Top = 175.5
      Left = 290
      Width = 58
      Height = 18.5
      Caption = "Ans"
      Hint = "Get answer"
      ShowHint = 1
      OnClick = preCheckSyntax
    END CREATE
    CREATE SinButt AS QBUTTON
      Font = Arial9B
      Top = 5
      Left = 0
      Width = 58
      Height = 18
      Caption = "Sin"
      Hint = "Sine"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE CosButt AS QBUTTON
      Font = Arial9B
      Top = 5
      Left = 58
      Width = 58
      Height = 18
      Caption = "Cos"
      Hint = "Cosine"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE TanButt AS QBUTTON
      Font = Arial9B
      Top = 5
      Left = 116
      Width = 58
      Height = 18
      Caption = "Tan"
      Hint = "Tangent"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE CotButt AS QBUTTON
      Font = Arial9B
      Top = 5
      Left = 174
      Width = 58
      Height = 18
      Caption = "Cot"
      Hint = "Cotangent"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE ASinButt AS QBUTTON
      Font = Arial9W
      Top = 24
      Left = 0
      Width = 58
      Height = 18
      Caption = "ASin"
      Hint = "Arcsine"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE ACosButt AS QBUTTON
      Font = Arial9W
      Top = 24
      Left = 58
      Width = 58
      Height = 18
      Caption = "ACos"
      Hint = "Arccosine"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE ATanButt AS QBUTTON
      Font = Arial9W
      Top = 24
      Left = 116
      Width = 58
      Height = 18
      Caption = "ATan"
      Hint = "Arctangent"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE ACotButt AS QBUTTON
      Font = Arial9W
      Top = 24
      Left = 174
      Width = 58
      Height = 18
      Caption = "ACot"
      Hint = "Arccotangent"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE SinhButt AS QBUTTON
      Font = Arial9B
      Top = 43
      Left = 0
      Width = 58
      Height = 18
      Caption = "Sinh"
      Hint = "Hyperbolic sine"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE CoshButt AS QBUTTON
      Font = Arial9B
      Top = 43
      Left = 58
      Width = 58
      Height = 18
      Caption = "Cosh"
      Hint = "Hyperbolic cosine"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE TanhButt AS QBUTTON
      Font = Arial9B
      Top = 43
      Left = 116
      Width = 58
      Height = 18
      Caption = "Tanh"
      Hint = "Hyperbolic tangent"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE CothButt AS QBUTTON
      Font = Arial9B
      Top = 43
      Left = 174
      Width = 58
      Height = 18
      Caption = "Coth"
      Hint = "Hyperbolic cotangent"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE ASinhButt AS QBUTTON
      Font = Arial9W
      Top = 62
      Left = 0
      Width = 58
      Height = 18
      Caption = "ASinh"
      Hint = "Hyperbolic arcsine"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE ACoshButt AS QBUTTON
      Font = Arial9W
      Top = 62
      Left = 58
      Width = 58
      Height = 18
      Caption = "ACosh"
      Hint = "Hyperbolic arccosine"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE ATanhButt AS QBUTTON
      Font = Arial9W
      Top = 62
      Left = 116
      Width = 58
      Height = 18
      Caption = "ATanh"
      Hint = "Hyperbolic arctangent"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE ACothButt AS QBUTTON
      Font = Arial9W
      Top = 62
      Left = 174
      Width = 58
      Height = 18
      Caption = "ACoth"
      Hint = "Hyperbolic arccotangent"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE SecButt AS QBUTTON
      Font = Arial9B
      Top = 81
      Left = 0
      Width = 58
      Height = 18
      Caption = "Sec"
      Hint = "Secant"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE CscButt AS QBUTTON
      Font = Arial9B
      Top = 81
      Left = 58
      Width = 58
      Height = 18
      Caption = "Csc"
      Hint = "Cosecant"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE ASecButt AS QBUTTON
      Font = Arial9B
      Top = 81
      Left = 116
      Width = 58
      Height = 18
      Caption = "ASec"
      Hint = "Arcsecant"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE ACscButt AS QBUTTON
      Font = Arial9B
      Top = 81
      Left = 174
      Width = 58
      Height = 18
      Caption = "ACsc"
      Hint = "Arccosecant"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE SechButt AS QBUTTON
      Font = Arial9W
      Top = 100
      Left = 0
      Width = 58
      Height = 18
      Caption = "Sech"
      Hint = "Hyperbolic secant"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE CschButt AS QBUTTON
      Font = Arial9W
      Top = 100
      Left = 58
      Width = 58
      Height = 18
      Caption = "Csch"
      Hint = "Hyperbolic cosecant"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE ASechButt AS QBUTTON
      Font = Arial9W
      Top = 100
      Left = 116
      Width = 58
      Height = 18
      Caption = "ASech"
      Hint = "Hyperbolic arcsecant"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE ACschButt AS QBUTTON
      Font = Arial9W
      Top = 100
      Left = 174
      Width = 58
      Height = 18
      Caption = "ACsch"
      Hint = "Hyperbolic arccosecant"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE IntButt AS QBUTTON
      Font = Arial9B
      Top = 119
      Left = 0
      Width = 58
      Height = 18
      Caption = "Int"
      Hint = "Largest integer less than or equal to input number"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE FracButt AS QBUTTON
      Font = Arial9B
      Top = 119
      Left = 58
      Width = 58
      Height = 18
      Caption = "Frac"
      Hint = "Returns fractional part of input number"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE FloorButt AS QBUTTON
      Font = Arial9B
      Top = 119
      Left = 116
      Width = 58
      Height = 18
      Caption = "Floor"
      Hint = "Rounds input number to integer closest to negative infinity"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE CeilButt AS QBUTTON
      Font = Arial9B
      Top = 119
      Left = 174
      Width = 58
      Height = 18
      Caption = "Ceil"
      Hint = "Rounds input number to integer closest to positive infinity"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE LogButt AS QBUTTON
      Font = Arial9W
      Top = 138
      Left = 0
      Width = 58
      Height = 18
      Caption = "Log"
      Hint = "Logarithm (base 10)"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE LnButt AS QBUTTON
      Font = Arial9W
      Top = 138
      Left = 58
      Width = 58
      Height = 18
      Caption = "Ln"
      Hint = "Natural logarithm (base e)"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE InvButt AS QBUTTON
      Font = Arial9W
      Top = 138
      Left = 116
      Width = 58
      Height = 18
      Caption = "Inv"
      Hint = "Inverse (1/x)"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE PiButt AS QBUTTON
      Font = Arial9W
      Top = 138
      Left = 174
      Width = 58
      Height = 18
      Caption = "Pi"
      Hint = "Pi (3.14159265358979)"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE SqrtButt AS QBUTTON
      Font = Arial9B
      Top = 157
      Left = 0
      Width = 58
      Height = 18
      Caption = "Sqrt"
      Hint = "Square root"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE CbrtButt AS QBUTTON
      Font = Arial9B
      Top = 157
      Left = 58
      Width = 58
      Height = 18
      Caption = "Cbrt"
      Hint = "Cube root"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE AbsButt AS QBUTTON
      Font = Arial9B
      Top = 157
      Left = 116
      Width = 58
      Height = 18
      Caption = "Abs"
      Hint = "Absolute value"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE ExpButt AS QBUTTON
      Font = Arial9B
      Top = 157
      Left = 174
      Width = 58
      Height = 18
      Caption = "Exp"
      Hint = "e raised to the input number"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE sqrButt AS QBUTTON
      Font = Arial9W
      Top = 176
      Left = 0
      Width = 58
      Height = 18
      Caption = "Sqr"
      Hint = "Squared"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE BegParButt AS QBUTTON
      Font = Arial9W
      Top = 24
      Left = 290
      Width = 29
      Height = 18
      Caption = "("
      Hint = "Left parenthesis"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE EndParButt AS QBUTTON
      Font = Arial9W
      Top = 24
      Left = 319
      Width = 29
      Height = 18
      Caption = ")"
      Hint = "Right parenthesis"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE DotButt AS QBUTTON
      Font = Arial9B
      Top = 157
      Left = 290
      Width = 58
      Height = 18
      Caption = "."
      Hint = "Decimal point"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE FactButt AS QBUTTON
      Font = Arial9W
      Top = 176
      Left = 58
      Width = 58
      Height = 18
      Caption = "Fact"
      Hint = "Factorial"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE RandButt AS QBUTTON
      Font = Arial9W
      Top = 176
      Left = 116
      Width = 58
      Height = 18
      Caption = "Rand"
      Hint = "rand() = random decimal; rand(9) = random integer"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE ModButt AS QBUTTON
      Font = Arial9W
      Top = 176
      Left = 174
      Width = 58
      Height = 18
      Caption = "Mod"
      Hint = "Modulus"
      ShowHint = 1
      OnClick = MathButts
    END CREATE
    CREATE Conversions AS QPOPUPMENU
       CREATE ftm AS QMENUITEM
         Caption = "Foot > meter"
         OnClick = ConversionsAll
       END CREATE
       CREATE mft AS QMENUITEM
         Caption = "Meter > foot"
         OnClick = ConversionsAll
       END CREATE
       CREATE incm AS QMENUITEM
         Caption = "Inch > centimeter"
         OnClick = ConversionsAll
       END CREATE
       CREATE cmin AS QMENUITEM
         Caption = "Centimeter > inch"
         OnClick = ConversionsAll
       END CREATE
       CREATE kmmi AS QMENUITEM
         Caption = "Kilometer > mile
         OnClick = ConversionsAll
       END CREATE
       CREATE mikm AS QMENUITEM
         Caption = "Mile > kilometer"
         OnClick = ConversionsAll
       END CREATE
       CREATE inft AS QMENUITEM
         Caption = "Inch > foot"
         OnClick = ConversionsAll
       END CREATE
       CREATE ftin AS QMENUITEM
         Caption = "Foot > inch"
         OnClick = ConversionsAll
       END CREATE
       CREATE ydm AS QMENUITEM
         Caption = "Yard > meter"
         OnClick = ConversionsAll
       END CREATE
       CREATE myd AS QMENUITEM
         Caption = "Meter > yard"
         OnClick = ConversionsAll
       END CREATE
       CREATE fam AS QMENUITEM
         Caption = "Fathom > meter"
         OnClick = ConversionsAll
       END CREATE
       CREATE mfa AS QMENUITEM
         Caption = "Meter > fathom"
         OnClick = ConversionsAll
       END CREATE
       CREATE mily AS QMENUITEM
         Caption = "Mile > light-year"
         OnClick = ConversionsAll
       END CREATE
       CREATE lymi AS QMENUITEM
         Caption = "Light-year > mile"
         OnClick = ConversionsAll
       END CREATE
       CREATE PartoLy AS QMENUITEM
         Caption = "Parsec > light-year"
         OnClick = ConversionsAll
       END CREATE
       CREATE LytoPar AS QMENUITEM
         Caption = "Light-year > parsec"
         OnClick = ConversionsAll
       END CREATE
       CREATE LengthBreak AS QMENUITEM
         Caption = "-"
       END CREATE
       CREATE ft2m2 AS QMENUITEM
         Caption = "Square ft > square m"
         OnClick = ConversionsAll
       END CREATE
       CREATE m2ft2 AS QMENUITEM
         Caption = "Square m > square ft"
         OnClick = ConversionsAll
       END CREATE
       CREATE in2cm2 AS QMENUITEM
         Caption = "Square in > square cm"
         OnClick = ConversionsAll
       END CREATE
       CREATE cm2in2 AS QMENUITEM
         Caption = "Square cm > square in"
         OnClick = ConversionsAll
       END CREATE
       CREATE haac AS QMENUITEM
         Caption = "Hectare > acre"
         OnClick = ConversionsAll
       END CREATE
       CREATE acha AS QMENUITEM
         Caption = "Acre > hectare"
         OnClick = ConversionsAll
       END CREATE
       CREATE AreaBreak AS QMENUITEM
         Caption = "-"
       END CREATE
       CREATE lbkg AS QMENUITEM
         Caption = "Pound > kilogram"
         OnClick = ConversionsAll
       END CREATE
       CREATE kglb AS QMENUITEM
         Caption = "Kilogram > pound"
         OnClick = ConversionsAll
       END CREATE
       CREATE TontoKilo AS QMENUITEM
         Caption = "Ton (metric) > Kilogram"
         OnClick = ConversionsAll
       END CREATE
       CREATE KilotoTon AS QMENUITEM
         Caption = "Kilogram > ton (metric)"
         OnClick = ConversionsAll
       END CREATE       
       CREATE TontoKiloUS AS QMENUITEM
         Caption = "Ton (US) > Kilogram"
         OnClick = ConversionsAll
       END CREATE
       CREATE KilotoTonUS AS QMENUITEM
         Caption = "Kilogram > ton (US)"
         OnClick = ConversionsAll
       END CREATE
       CREATE TontoKiloUK AS QMENUITEM
         Caption = "Ton (UK) > Kilogram"
         OnClick = ConversionsAll
       END CREATE
       CREATE KilotoTonUK AS QMENUITEM
         Caption = "Kilogram > ton (UK)"
         OnClick = ConversionsAll
       END CREATE
       CREATE OztoGram AS QMENUITEM
         Caption = "Ounce (avoirdupois) > gram"
         OnClick = ConversionsAll
       END CREATE
       CREATE GramtoOz AS QMENUITEM
         Caption = "Gram > ounce (avoirdupois)"
         OnClick = ConversionsAll
       END CREATE              
       CREATE OztoGramT AS QMENUITEM
         Caption = "Ounce (troy) > gram"
         OnClick = ConversionsAll
       END CREATE
       CREATE GramtoOzT AS QMENUITEM
         Caption = "Gram > ounce (troy)"
         OnClick = ConversionsAll
       END CREATE
       CREATE MassBreak AS QMENUITEM
         Caption = "-"
       END CREATE
       CREATE FC AS QMENUITEM
         Caption = "Fahrenheit > Celsius"
         OnClick = ConversionsAll
       END CREATE
       CREATE CF AS QMENUITEM
         Caption = "Celsius > Fahrenheit"
         OnClick = ConversionsAll
       END CREATE
       CREATE CK AS QMENUITEM
         Caption = "Celsius > Kelvin"
         OnClick = ConversionsAll
       END CREATE
       CREATE KC AS QMENUITEM
         Caption = "Kelvin > Celsius"
         OnClick = ConversionsAll
       END CREATE
       CREATE TempBreak AS QMENUITEM
         Caption = "-"
       END CREATE
       CREATE GaltoLit AS QMENUITEM
         Caption = "Gallon (US dry) > liter"
         OnClick = ConversionsAll
       END CREATE
       CREATE LittoGal AS QMENUITEM
         Caption = "Liter > gallon (US dry)"
         OnClick = ConversionsAll
       END CREATE
       CREATE GaltoLitL AS QMENUITEM
         Caption = "Gallon (US liquid) > liter"
         OnClick = ConversionsAll
       END CREATE
       CREATE LittoGalL AS QMENUITEM
         Caption = "Liter > gallon (US liquid)"
         OnClick = ConversionsAll
       END CREATE       
       CREATE QrtoGal AS QMENUITEM
         Caption = "Quart (US dry) > gallon (US dry)"
         OnClick = ConversionsAll
       END CREATE
       CREATE GaltoQrt AS QMENUITEM
         Caption = "Gallon (US dry) > quart (US dry)"
         OnClick = ConversionsAll
       END CREATE
       CREATE PinttoLtr AS QMENUITEM
         Caption = "Pint > liter (US dry)"
         OnClick = ConversionsAll
       END CREATE
       CREATE LtrtoPint AS QMENUITEM
         Caption = "Liter > pint (US dry)"
         OnClick = ConversionsAll
       END CREATE       
       CREATE PinttoLtrL AS QMENUITEM
         Caption = "Pint > liter (US liquid)"
         OnClick = ConversionsAll
       END CREATE
       CREATE LtrtoPintL AS QMENUITEM
         Caption = "Liter > pint (US liquid)"
         OnClick = ConversionsAll
       END CREATE
       CREATE ft3m3 AS QMENUITEM
         Caption = "Cubic ft > cubic m"
         OnClick = ConversionsAll
       END CREATE
       CREATE m3ft3 AS QMENUITEM
         Caption = "Cubic m > cubic ft"
         OnClick = ConversionsAll
       END CREATE
       CREATE VolumeBreak AS QMENUITEM
         Caption = "-"
       END CREATE
       CREATE HptoWatt AS QMENUITEM
         Caption = "Horsepower (elec.) > watt"
         OnClick = ConversionsAll
       END CREATE
       CREATE WatttoHp AS QMENUITEM
         Caption = "Watt > horsepower (elec.)"
         OnClick = ConversionsAll
       END CREATE
       CREATE HptoWattM AS QMENUITEM
         Caption = "Horsepower (metric) > watt"
         OnClick = ConversionsAll
       END CREATE
       CREATE WatttoHpM AS QMENUITEM
         Caption = "Watt > horsepower (metric)"
         OnClick = ConversionsAll
       END CREATE       
       CREATE BTUtoWatt AS QMENUITEM
         Caption = "BTU/hour > watt"
         OnClick = ConversionsAll
       END CREATE
       CREATE WatttoBTU AS QMENUITEM
         Caption = "Watt > BTU/hour"
         OnClick = ConversionsAll
       END CREATE
       CREATE KwtoWatt AS QMENUITEM
         Caption = "Kilowatt > watt"  
         OnClick = ConversionsAll
       END CREATE
       CREATE WatttoKw AS QMENUITEM
         Caption = "Watt > kilowatt"
         OnClick = ConversionsAll
       END CREATE
       CREATE PowerBreak AS QMENUITEM
         Caption = "-"
       END CREATE
       CREATE KphtoMph AS QMENUITEM
         Caption = "Kph > mph"
         OnClick = ConversionsAll
       END CREATE
       CREATE MphtoKph AS QMENUITEM
         Caption = "Mph > kph"
         OnClick = ConversionsAll
       END CREATE
       CREATE KnottoMph AS QMENUITEM
         Caption = "Knot > mph"
         OnClick = ConversionsAll
       END CREATE
       CREATE MphtoKnot AS QMENUITEM
         Caption = "Mph > knot"
         OnClick = ConversionsAll
       END CREATE
       CREATE MpstoFps AS QMENUITEM
         Caption = "Meter/sec > ft/sec"
         OnClick = ConversionsAll
       END CREATE
       CREATE FpstoMps AS QMENUITEM
         Caption = "Ft/sec > meter/sec"
         OnClick = ConversionsAll
       END CREATE
       CREATE SpeedBreak AS QMENUITEM
         Caption = "-"
       END CREATE
       CREATE SectoMin AS QMENUITEM
         Caption = "Second > minute"
         OnClick = ConversionsAll 
       END CREATE
       CREATE MintoSec AS QMENUITEM
         Caption = "Minute > second"
         OnClick = ConversionsAll
       END CREATE
       CREATE MintoHr AS QMENUITEM
         Caption = "Minute > hour"
         OnClick = ConversionsAll
       END CREATE
       CREATE HrtoMin AS QMENUITEM
         Caption = "Hour > minute"
         OnClick = ConversionsAll
       END CREATE
       CREATE MintoDay AS QMENUITEM
         Caption = "Minute > day"
         OnClick = ConversionsAll
       END CREATE
       CREATE DaytoMin AS QMENUITEM
         Caption = "Day > minute"
         OnClick = ConversionsAll
       END CREATE
       CREATE DaytoHr AS QMENUITEM
         Caption = "Day > hour"
         OnClick = ConversionsAll
       END CREATE
       CREATE HrtoDay AS QMENUITEM
         Caption = "Hour > day"
         OnClick = ConversionsAll
       END CREATE
       CREATE TimeBreak AS QMENUITEM
         Caption = "-"
       END CREATE
       CREATE PsitoPas AS QMENUITEM
         Caption = "Psi > pascal"
         OnClick = ConversionsAll
       END CREATE
       CREATE PastoPsi AS QMENUITEM
         Caption = "Pascal > psi"
         OnClick = ConversionsAll
       END CREATE
         CREATE PsitoAtm AS QMENUITEM
         Caption = "Psi > atmosphere"
         OnClick = ConversionsAll
       END CREATE
       CREATE Atmtopsi AS QMENUITEM
         Caption = "Atmosphere > psi"
         OnClick = ConversionsAll
       END CREATE
       CREATE PsitoKgscm AS QMENUITEM
         Caption = "Psi > kg/sqcm"
         OnClick = ConversionsAll
       END CREATE
       CREATE KgscmtoPsi AS QMENUITEM
         Caption = "Kg/sqcm > psi"
         OnClick = ConversionsAll
       END CREATE
    END CREATE    
    CREATE Constants AS QPOPUPMENU
      CREATE AccelerationG AS QMENUITEM
        Caption = "Acceleration of gravity (m/sec²)"
        OnClick = ConstantsAll
      END CREATE
      CREATE ADensity AS QMENUITEM
        Caption = "Dry air density at STP (kg/m" + CHR$(0179) + ")"
        OnClick = ConstantsAll
      END CREATE
      CREATE LSpeed AS QMENUITEM
        Caption = "Light speed in a vacuum (m/sec)"
        OnClick = ConstantsAll 
      END CREATE
      CREATE SolarC AS QMENUITEM
        Caption = "Solar constant (watts/m²)"
        OnClick = ConstantsAll
      END CREATE
      CREATE SSpeed AS QMENUITEM
        Caption = "Sound speed at STP (m/sec)"
        OnClick = ConstantsAll
      END CREATE
      CREATE SAtmosphere AS QMENUITEM
        Caption = "Standard atmosphere (nt/m²)"
        OnClick = ConstantsAll
      END CREATE
      CREATE BreakEarth1 AS QMENUITEM
        Caption = "-"
      END CREATE
      CREATE EERadius AS QMENUITEM
        Caption = "Earth equatorial radius (m)"
        OnClick = ConstantsAll
      END CREATE
      CREATE EEscapeV AS QMENUITEM
        Caption = "Earth escape velcity (m/sec)"
        OnClick = ConstantsAll
      END CREATE
      CREATE MEarthDipole AS QMENUITEM
        Caption = "Earth magnetic dipole moment (amp-m²)"
        OnClick = ConstantsAll
      END CREATE
      CREATE MEarth AS QMENUITEM
        Caption = "Earth mass (kg)"
        OnClick = ConstantsAll
      END CREATE
      CREATE MAngularS AS QMENUITEM
        Caption = "Earth mean angular rotational speed (rads/sec)"
        OnClick = ConstantsAll
      END CREATE
      CREATE DEarth AS QMENUITEM
        Caption = "Earth mean density (kg/m" + CHR$(0179) + ")"
        OnClick = ConstantsAll
      END CREATE
      CREATE MOrbitalS AS QMENUITEM
        Caption = "Earth mean orbital speed (m/sec)"
        OnClick = ConstantsAll
      END CREATE
      CREATE PERadius AS QMENUITEM
        Caption = "Earth polar radius (m)"
        OnClick = ConstantsAll
      END CREATE
      CREATE VEarth AS QMENUITEM
        Caption = "Earth volume (m" + CHR$(0179) + ")"
        OnClick = ConstantsAll
      END CREATE
      CREATE BreakEarth2 AS QMENUITEM
        Caption = "-"
      END CREATE
      CREATE AlphaPMass AS QMENUITEM
        Caption = "Alpha particle mass (kg)"
        OnClick = ConstantsAll
      END CREATE
      CREATE ElectronCMassR AS QMENUITEM
        Caption = "Electron charge-mass ratio (coul/kg)"
        OnClick = ConstantsAll
      END CREATE
      CREATE ElectronMass AS QMENUITEM
        Caption = "Electron rest mass (kg)"
        OnClick = ConstantsAll
      END CREATE
      CREATE MuonMass AS QMENUITEM
        Caption = "Muon rest mass (kg)"
        OnClick = ConstantsAll
      END CREATE
      CREATE NeutronMass AS QMENUITEM
        Caption = "Neutron rest mass (kg)"
        OnClick = ConstantsAll
      END CREATE
      CREATE ProtonMass AS QMENUITEM
        Caption = "Proton rest mass (kg)"
        OnClick = ConstantsAll
      END CREATE
      CREATE AtomicBreak AS QMENUITEM
        Caption = "-"
      END CREATE
      CREATE ATomicMC AS QMENUITEM
        Caption = "Atomic mass constant (kg)"
        OnClick = ConstantsAll
      END CREATE
      CREATE AvogadroC AS QMENUITEM
        Caption = "Avogadro constant (1/mole)"
        OnClick = ConstantsAll
      END CREATE
      CREATE BoltzmannC AS QMENUITEM
        Caption = "Boltzmann constant (joule/K)"
        OnClick = ConstantsAll
      END CREATE
      CREATE ECharge AS QMENUITEM
        Caption = "Elementary charge (coul)"
        OnClick = ConstantsAll
      END CREATE
      CREATE FaradayC AS QMENUITEM
        Caption = "Faraday constant (coul/mole)"
        OnClick = ConstantsAll
      END CREATE
      CREATE GravityC AS QMENUITEM
        Caption = "Gravitational constant (nt-m²/kg²)"
        OnClick = ConstantsAll
      END CREATE
      CREATE PermeabilityC AS QMENUITEM
        Caption = "Permeability constant (henry/m)"
        OnClick = ConstantsAll
      END CREATE
      CREATE PermittivityC AS QMENUITEM
        Caption = "Permittivity constant (farad/m)"
        OnClick = ConstantsAll
      END CREATE
      CREATE PlankC AS QMENUITEM
        Caption = "Planck constant (joule-sec)"
        OnClick = ConstantsAll
      END CREATE
      CREATE RydbergC AS QMENUITEM
        Caption = "Rydberg constant (1/m)"
        OnClick = ConstantsAll
      END CREATE
      CREATE SBoltzmannC AS QMENUITEM
        Caption = "Stefan-Boltzmann constant (watt/m²K4)"
        OnClick = ConstantsAll
      END CREATE
      CREATE UnivGasC AS QMENUITEM
        Caption = "Universal gas constant (joule/K-mole)"
        OnClick = ConstantsAll
      END CREATE
      CREATE WienC AS QMENUITEM
        Caption = "Wien displacement constant (m-K)"
        OnClick = ConstantsAll
      END CREATE
    END CREATE
  END CREATE
  CREATE NoteProductForm AS QFORM    
    Top = Screen.Height/2 + 27
    Left = Screen.Width/2 - 170
    Width = 340 '320
    Height = 205
    Visible = 0
    Color = &HABC777
    BorderStyle = bsSingle
    DelBorderIcons(biMaximize)
    'DelBorderIcons(biMinimize)
    FormStyle = fsStayOnTop
    Caption = "Notes on QEDTukak"
    OnClose = CloseNotes
    CREATE DXNotes AS QCanvas
      Top = 21
      Left = 242
      Height = 63
      Width = 84
      Color = 0
      Cursor = -21
      Hint = "Click to email comment or bug report."
      Showhint = 1
      OnClick = EmailMe
    END CREATE
    CREATE ProductList AS QLISTBOX
	Width = 232
      Height = 177
      AddItems ""
      AddItems "Welcome!
      AddItems ""
      AddItems "  »  QEDTukak is an easy-to-use yet 
      AddItems "      powerful expression evaluator
      AddItems "      that can evaluate expressions like:
      AddItems "      Sin(.1)^2 - 3*Ln(Tan(.1*PI)).
      AddItems ""
      AddItems "  »  The precedence rule followed is: 
      AddItems "      ^   *   /   +   -
      AddItems ""
      AddItems "  »  To access the different menus, simply 
      AddItems "      right-click on the Time Panel at the  
      AddItems "      right end of QEDTukak.
      AddItems ""
      AddItems "  »  The Functions Selector, the History 
      AddItems "      View and the Variables Input come up 
      AddItems "      whenever you left-click the Time Panel.
      AddItems ""
      AddItems "  »  To build your math expression, type in 
      AddItems "      the functions or simply click the 
      AddItems "      appropriate buttons.
      AddItems ""
      AddItems "  »  If you're typing, refer to your Functions
      AddItems "      Selector for the function syntax.
      AddItems "      The functions are NOT case-sensitive.
      AddItems "      (When using scientific notation,
      AddItems "      remember not to put + after E: i.e.
      AddItems "      1000 is 1E3 NOT 1E+3. However,
      AddItems "      .001 is 1E-3.)
      AddItems ""
      AddItems "  »  You can use variables in your 
      AddItems "      expressions. There are only 6 valid 
      AddItems "      variable names: J,K,U,W,Y,Z. They  
      AddItems "      are NOT case-sensitive (Y is exactly 
      AddItems "      equal to y). No other variable names 
      AddItems "      are allowed. To assign values to your  
      AddItems "      variables, right-click on the Time 
      AddItems "      Panel and click Variables Input.                      
      AddItems "" 
      AddItems "  »  The answer appears on the title bar
      AddItems "      and on the History View.
      AddItems ""
      AddItems "  »  To clear your entry, press Esc or click
      AddItems "      on Clear on the Functions Selector.
      AddItems ""
      AddItems "  »  To access the Constants Menu, right-
      AddItems "      click on the Functions Selector.
      AddItems "      Alternatively, you can right-click on
      AddItems "      the Time Panel then select Constants.
      AddItems ""
      AddItems "  »  To access the Conversions Menu, right-
      AddItems "      click on the Time Panel then select 
      AddItems "      Conversions."                 
      AddItems ""          
      AddItems "Programming"
      AddItems "  »  QEDTukak was written in Rapid-Q,"
      AddItems "      a compiler developed by William Yu."
      AddItems "      It's also freeware and downloadable"
      AddItems "      at www.basicguru.com/abc/rapidq."     
    END CREATE
    CREATE NotesP0 AS QLABEL
      Top = 5
      Left = 235
      Font = Arial9B
      Layout = -1
      LabelStyle = 1
      Caption = "  QEDTukak 1.54"
      Hint = "Click to visit website"
      ShowHint = 1
      OnClick = SendMe
    END CREATE
    CREATE NotesP1 AS QLABEL
      Top = 85
      Left = 235
      Caption = "  Copyright (c) 2001\n    Achilles B. Mina\n\nThis is FREEWARE.\n Not for commercial\n       distribution."
    END CREATE
  END CREATE
  Show
END CREATE 

SUB ExpSolver
  IF soundoff = 0 THEN PLAYWAV (lionroar,1)
  'CMode = 57.2957795130824       'converts to degrees
  'CModeN = 0.0174532925199433    'converts to radians
  Math(1) = "sin"
  Math(2) = "cos"
  Math(3) = "tan"
  Math(4) = "cot"
  Math(5) = "sec"
  Math(6) = "csc"
  Math(7) = "sqrt"
  Math(8) = "log"
  Math(9) = "ln"
  Math(10) = "asin"
  Math(11) = "acos"
  Math(12) = "atan"
  Math(13) = "acot"
  Math(14) = "asec"
  Math(15) = "acsc"
  Math(16) = "sinh"
  Math(17) = "cosh"
  Math(18) = "tanh"
  Math(19) = "coth"
  Math(20) = "sech"
  Math(21) = "csch"
  Math(22) = "asinh"
  Math(23) = "acosh"
  Math(24) = "atanh"
  Math(25) = "acoth"
  Math(26) = "asech"
  Math(27) = "acsch"
  Math(28) = "inv"
  Math(29) = "exp"
  Math(30) = "abs"
  Math(31) = "int"
  Math(32) = "frac"
  Math(33) = "floor"
  Math(34) = "ceil"
  Math(35) = "cbrt"
  Math(36) = "sqr"
  Math(37) = "fact"
  Math(38) = "rand"
  Math(39) = "mod"
END SUB

SUB ClrExpEdit
  IF soundoff = 0 THEN PLAYWAV (wipe,1)
  ExpEdit.Text = ""
  SetFocus(ExpEdit.Handle)
END SUB

SUB ClrLastExpEdit
  IF soundoff = 0 THEN PLAYWAV (wipe,1)
  ExpEdit.Text = oldexpression
  ExpEdit.SelStart = LEN(ExpEdit.Text)
  SetFocus(ExpEdit.Handle)
END SUB

SUB VariablesEntered(key AS BYTE)
  IF key = 13 THEN 
    preCheckSyntax
  ELSE
    IF soundoff = 0 THEN PLAYWAV (typing,1)
  END IF
END SUB

SUB preCheckSyntax 
  CheckSyntax(13)
  SetFocus(ExpEdit.Handle)
END SUB

SUB CheckSyntax(key AS BYTE)
  DEFSHORT posops, startmath, wherepi
  oldexpression = ExpEdit.Text
  IF soundoff = 0 THEN PLAYWAV (typing,1)
      'formula$ = "2^(1 - (2^2)/2 * (1 + ((2 ^ 2) + 1)) + 1)"
      'formula$ = "(1 + 2+3+4+5+6+7+8+9+10-55)"
      'formula$ = "3+(4*(-3+2*34)+2)^2"
      'formula$ = "-5-4-3-2-1" 
      'formula$ = "(-2)^2 +1"
      'formula$ = "-(-5)+(-4)-(-3)+(2)-(1) + (.5 + 1)^2"
      'formula$ = "Sin(.1)^2-3*Ln(Tan(.1*PI))"
      'formula$ = "Sin(.1)-3*Ln(Tam(.1*PI))"
      'formula$ = "Ln(Tan(.1*PI))"
      'formula$ = "2^30 + 2.14e9*2.14e10 + 5e19 + exp(2) * exp(2)- exp(2) ^exp(2)/exp(2) -sec(35)"
  formula$ = LCASE$(REPLACESUBSTR$(ExpEdit.Text," ",""))
  formula$ = REPLACESUBSTR$(formula$,"pi","3.14159265358979")
  formula$ = REPLACESUBSTR$(formula$,"--","+")
  FOR x = 1 TO 2
    IF JVarEdit.Text <> "" THEN formula$ = REPLACESUBSTR$(formula$,"j",JVarEdit.Text)
    IF KVarEdit.Text <> "" THEN formula$ = REPLACESUBSTR$(formula$,"k",KVarEdit.Text)
    IF UVarEdit.Text <> "" THEN formula$ = REPLACESUBSTR$(formula$,"u",UVarEdit.Text)
    IF WVarEdit.Text <> "" THEN formula$ = REPLACESUBSTR$(formula$,"w",WVarEdit.Text)
    IF YVarEdit.Text <> "" THEN formula$ = REPLACESUBSTR$(formula$,"y",YVarEdit.Text)
    IF ZVarEdit.Text <> "" THEN formula$ = REPLACESUBSTR$(formula$,"z",ZVarEdit.Text)
  NEXT
  IF key = 27 OR (key = 13 AND formula$ = "") THEN
    IF soundoff = 0 THEN PLAYWAV (wipe,1)
    ExpEdit.Text = ""
  ELSEIF (key = 13 OR key = 61) AND ExpEdit.Text <> "" THEN
    changeE
    math$ = ""
    startmath = 0
    errmath$ = ""
    mathchar$ = ""       
    IF TALLY(formula$,")(") <> 0 THEN
      IF soundoff = 0 THEN PLAYWAV (chicken,1)
      MessageDlg("Invalid -> ')('. Please correct syntax.", mtError, mbOK, 0)
      EXIT SUB
    END IF    
    IF TALLY(formula$,"(") <> TALLY(formula$,")") THEN
      IF soundoff = 0 THEN PLAYWAV (chicken,1)
      MessageDlg("Missing parenthesis. Please correct syntax.", mtError, mbOK, 0)
      EXIT SUB
    ELSE
      DO     
        INC startmath
        oldmathchar$ = mathchar$
        mathchar$ = MID$(formula$,startmath,1)
        SELECT CASE mathchar$
          CASE "e"
            SELECT CASE oldmathchar$
              CASE "","^","c","s","-","+","*","/","\"
                math$ = math$ + mathchar$
                errmath$ = math$
            END SELECT
          CASE "a","b","c","d","f","g","h","i","l","m","n","o","p","q","r","s","t","v","x"
            math$ = math$ + mathchar$
            errmath$ = errmath$ + mathchar$
            SELECT CASE oldmathchar$
              CASE "0" TO "9"
                IF soundoff = 0 THEN PLAYWAV (chicken,1)
                MessageDlg(errmath$ + " is invalid. Please correct syntax.", mtError, mbOK, 0)
                EXIT SUB
            END SELECT            
          CASE "j","k","u","w","y","z"
            errmath$ = errmath$ + mathchar$
            FOR x = 1 TO 5
              ops$ = MID$("+-*/^",x,1)
              posops = RINSTR(errmath$,ops$)
              IF posops <> 0 THEN EXIT FOR
            NEXT
            errmath$ = RIGHT$(errmath$,LEN(errmath$)-posops)
            IF soundoff = 0 THEN PLAYWAV (chicken,1)
            MessageDlg(errmath$ + "?" + " Please correct syntax.", mtError, mbOK, 0)
            EXIT SUB
          CASE ")"
            afterendpar$ = MID$(formula$,startmath+1,1)
            SELECT CASE afterendpar$
              CASE "0" TO "9"
                IF soundoff = 0 THEN PLAYWAV (chicken,1)
                MessageDlg(")"+ afterendpar$ + " is invalid." + " Please correct syntax.", mtError, mbOK, 0)
                EXIT SUB
            END SELECT            
          CASE "("
            SELECT CASE oldmathchar$
              CASE "0" TO "9"
                IF soundoff = 0 THEN PLAYWAV (chicken,1)
                MessageDlg(oldmathchar$ + "( is invalid." + " Please correct syntax.", mtError, mbOK, 0)
                EXIT SUB
            END SELECT               
            IF math$ <> "" THEN
              FOR x = 1 TO 39
                IF math$ = Math(x) THEN 
                  math$ = ""
                END IF
              NEXT
              IF math$ <> "" AND math$ <> "pi" THEN      'if there's a match, skip this
                IF soundoff = 0 THEN PLAYWAV (chicken,1)                
                MessageDlg(errmath$ + "?" + " Please correct syntax.", mtError, mbOK, 0)
                EXIT SUB
              END IF
            END IF
          CASE "0" TO "9"
            errmath$ = errmath$ + mathchar$
            SELECT CASE oldmathchar$
              CASE "a" TO "d", "f" TO "z"
                FOR x = 1 TO 5
                  ops$ = MID$("+-*/^",x,1)
                  posops = RINSTR(errmath$,ops$)
                  IF posops <> 0 THEN EXIT FOR
                NEXT
                errmath$ = RIGHT$(errmath$,LEN(errmath$)-posops)
                IF soundoff = 0 THEN PLAYWAV (chicken,1)
                MessageDlg(errmath$ + "?" + " Please correct syntax.", mtError, mbOK, 0)
                EXIT SUB
            END SELECT
          CASE "+","-","*","/","^"
            IF (math$ <> "" AND math$ <> "pi") AND (INSTR(math$,"(") = 0 OR INSTR(math$,")") = 0) THEN
              FOR x = 1 TO 5
                ops$ = MID$("+-*/^",x,1)
                posops = RINSTR(errmath$,ops$)
                IF posops <> 0 THEN EXIT FOR
              NEXT
              math$ = RIGHT$(math$,LEN(math$)-posops)
              IF soundoff = 0 THEN PLAYWAV (chicken,1)
              MessageDlg("Missing parenthesis. Please correct syntax.", mtError, mbOK, 0)
              EXIT SUB
            END IF              
        END SELECT    
      LOOP UNTIL startmath = LEN(formula$)
    END IF
    'formula$ = REPLACESUBSTR$(formula$,"pi","3.14159265358979")
    ExpSolverEdit
  END IF
END SUB

SUB ExpSolverEdit  
  'HistoryView.AddItems formula$ + " ="
  HistoryView.InsertItem(0,formula$ + " =")
  FOR i = 1 TO 1000
    DO
      reformatted = 0
      formula$ = REPLACESUBSTR$(formula$,"--","+")
      formulaL = LEN(formula$)
      par1 = RINSTR(formulaL,formula$,"(")
      par2 = INSTR(par1,formula$,")")
      IF par1 = 0 OR par2 = 0 THEN
        betweenpars$ = formula$
      ELSE
        betweenpars$ = MID$(formula$,par1+1,(par2-1)-par1)
      END IF
      IF INSTR(betweenpars$,"^") <> 0 THEN
        pivotoperator$ = "^"
        operator = INSTR(betweenpars$,"^")      
      ELSEIF INSTR(betweenpars$,"*") <> 0 THEN
        pivotoperator$ = "*"
        operator = INSTR(betweenpars$,"*")
      ELSEIF INSTR(betweenpars$,"/") <> 0 THEN
        pivotoperator$ = "/"
        operator = INSTR(betweenpars$,"/")
      ELSEIF (INSTR(betweenpars$,"+") <> 0 OR INSTR(betweenpars$,"-") <> 0) THEN 'AND INSTR(betweenpars$,"E") = 0 THEN
        IF MID$(betweenpars$,1,1) = "-" THEN 
          start = 2
        ELSE
          start = 1
        END IF
        IF (TALLY(betweenpars$,"-") = 1 AND TALLY(betweenpars$,"+") = 0) AND MID$(betweenpars$,1,1) = "-" THEN
          checkback$ = MID$(formula$,par1-1,1)
          SELECT CASE checkback$
            CASE "c","d","g","h","l","n","p","r","s","t","v"
              Functions(par1,betweenpars$)
            CASE ELSE
              formula$ = DELETE$(formula$,par1,1)
              formula$ = DELETE$(formula$,par2-1,1) 
          END SELECT
          IF formula$ = betweenpars$ THEN
            IF soundoff = 0 THEN PLAYWAV (cashreg,1)
            DoPrecision
            EXIT SUB
          END IF
          reformatted = 1
        ELSE
          FOR y = start TO LEN(betweenpars$)
            operator$ = MID$(betweenpars$,y,1)
            SELECT CASE operator$
              CASE "+","-"
                operator = y
                pivotoperator$ = MID$(betweenpars$,operator,1)
                EXIT FOR
            END SELECT
          NEXT
        END IF
      ELSE
        checkback$ = MID$(formula$,par1-1,1)
        SELECT CASE checkback$
          CASE "c","d","g","h","l","n","p","r","s","t","v"
            Functions(par1,betweenpars$)
          CASE ELSE
            formula$ = DELETE$(formula$,par1,1)
            formula$ = DELETE$(formula$,par2-1,1) 
        END SELECT
        IF formula$ = betweenpars$ THEN
          IF soundoff = 0 THEN PLAYWAV (cashreg,1)
          DoPrecision
          EXIT SUB
        END IF
        reformatted = 1
      END IF
      formula$ = REPLACESUBSTR$(formula$,"--","+")
    LOOP UNTIL reformatted = 0
    x = operator
    DO
      INC x
      IF x >= LEN(betweenpars$) THEN
        postoperator = x
        EXIT DO
      END IF  
      operator$ = MID$(betweenpars$,x,1)
      SELECT CASE operator$
        CASE "+","*","/","^"
          postoperator = x - 1
          EXIT DO
        CASE "-"
          IF x <> operator + 1 THEN
            postoperator = x - 1
            EXIT DO
          END IF
      END SELECT
    LOOP
    x = operator
    DO
      DEC x
      IF x <= 1 THEN
       preoperator = 1
       EXIT DO
      END IF
      operator$ = MID$(betweenpars$,x,1)
      SELECT CASE operator$
        CASE "+","-","*","/","^"
          preoperator = x + 1
          EXIT DO
      END SELECT
    LOOP
    preopnumber = VAL(MID$(betweenpars$,preoperator,(operator-1)-(preoperator-1)))
    postopnumber = VAL(MID$(betweenpars$,operator+1,postoperator-operator))
    oldstring$ = MID$(formula$,par1+preoperator,postoperator-(preoperator-1))
    SELECT CASE pivotoperator$
      CASE "^"
        IF preopnumber < 0 THEN
          IF (postopnumber > 1 AND postopnumber MOD 2 = 0) OR postopnumber = 0 THEN
            newstring = preopnumber ^ postopnumber
          ELSE
            SHOWMESSAGE("You're extracting the root of a negative number." + CHR$(13)_
                      + "QEDTukak will display the real solution only.")
            newstring = SGN(preopnumber)*(ABS(preopnumber) ^ postopnumber)
          END IF
        ELSE
          newstring = preopnumber ^ postopnumber
        END IF
      CASE "*"
        newstring = preopnumber * postopnumber
      CASE "/"
        IF postopnumber = 0 THEN
          IF soundoff = 0 THEN PLAYWAV (chicken,1)
          MessageDlg("Can't divide by zero. Please correct entry.", mtError, mbOK, 0)
          EXIT SUB
        END IF
        newstring = preopnumber / postopnumber
      CASE "+"
        newstring = preopnumber + postopnumber
      CASE "-"
        newstring = preopnumber - postopnumber            
    END SELECT
    DoInPrecision(newstring,@newstring$)
    CheckE(@newstring$)
    formula$ = REPLACESUBSTR$(formula$,oldstring$,newstring$)
    'formula$ = REPLACESUBSTR$(formula$,"--","+")
  NEXT
END SUB

SUB Functions(par1 AS INTEGER,mathval$ AS STRING)
  startmath = par1
  DO        
    DEC startmath
    mathchar$ = MID$(formula$,startmath,1)
    SELECT CASE mathchar$
      CASE "+","-","*","/","^","("
        EXIT DO
      CASE "a","b","c","d","e","f","g","h","i","l","m","n","o","p","q","r","s","t","v","x"
        math$ = mathchar$ + math$
    END SELECT        
  LOOP UNTIL startmath <= 1
  FOR i = 1 TO 39
    IF math$ = Math(i) THEN
      math$ = ""
      oldval$ = Math(i) + "(" + mathval$ + ")"
      SELECT CASE i
        CASE 1
          insertval = SIN(VAL(mathval$)*CModeN)
        CASE 2
          insertval = COS(VAL(mathval$)*CModeN)
        CASE 3
          insertval = TAN(VAL(mathval$)*CModeN)
        CASE 4
          insertval = 1/(TAN(VAL(mathval$)*CModeN))
        CASE 5
          insertval = 1/(COS(VAL(mathval$)*CModeN))
        CASE 6
          insertval = 1/(SIN(VAL(mathval$)*CModeN))
        CASE 7
          IF VAL(mathval$) < 0 THEN
            SHOWMESSAGE("You're extracting the root of a negative number." + CHR$(13)_
                      + "QEDTukak will display the real solution only.")
          END IF
          insertval = SGN(VAL(mathval$))*(ABS(VAL(mathval$))^(1/2))
        CASE 8
          insertval = LOG(VAL(mathval$))/LOG(10)
        CASE 9
          insertval = LOG(VAL(mathval$))
        CASE 10
          IF VAL(mathval$) > 1 THEN
            outformold$ = outform$  
            outform$ = "und"
          ELSEIF VAL(mathval$) = 1 THEN
            IF CMode = 1 THEN
              insertval = 1.5707963267949
            ELSE
              insertval = 90
            END IF           
          ELSE
            insertval = ATN(VAL(mathval$)/SQR(-VAL(mathval$)*VAL(mathval$) +1))*CMode
          END IF  
        CASE 11
          IF VAL(mathval$) > 1 THEN
            outformold$ = outform$  
            outform$ = "und"
          ELSEIF VAL(mathval$) = 0 THEN
            IF CMode = 1 THEN
              insertval = 1.5707963267949
            ELSE
              insertval = 90
            END IF
          ELSEIF VAL(mathval$) = 1 THEN
            insertval = 0                                 
          ELSE        
            insertval = (-ATN(VAL(mathval$)/SQR(-VAL(mathval$)*VAL(mathval$) +1)) + 1.570796)*CMode
          END IF          
        CASE 12
          insertval = ATN(VAL(mathval$))*CMode
        CASE 13
          insertval = (-ATN(VAL(mathval$)) + 1.570796)*CMode
        CASE 14
          IF VAL(mathval$) = 0 THEN
            outformold$ = outform$  
            outform$ = "und"
          ELSE        
            insertval = (ATN(SQR(VAL(mathval$)*VAL(mathval$) -1)) + (SGN(VAL(mathval$)) -1)*1.570796)*CMode
          END IF
        CASE 15
          IF VAL(mathval$) = 0 THEN
            outformold$ = outform$  
            outform$ = "und"       
          ELSEIF VAL(mathval$) = 1 THEN
            IF CMode = 1 THEN
              insertval = 1.5707963267949
            ELSE
              insertval = 90
            END IF 
          ELSE  
            insertval = (ATN(1/SQR(VAL(mathval$)*VAL(mathval$) -1)) + (SGN(VAL(mathval$)) -1)*1.570796)*CMode
          END IF  
        CASE 16
          insertval = (EXP(VAL(mathval$)) - EXP(-VAL(mathval$)))/2
        CASE 17
          insertval = (EXP(VAL(mathval$)) + EXP(-VAL(mathval$)))/2
        CASE 18
          insertval = -EXP(-VAL(mathval$)) /(EXP(VAL(mathval$)) + EXP(-VAL(mathval$)))*2 + 1
        CASE 19
          insertval = EXP(-VAL(mathval$))/(EXP(VAL(mathval$)) - EXP(-VAL(mathval$)))*2 + 1
        CASE 20
          insertval = 2/(EXP(VAL(mathval$)) + EXP(-VAL(mathval$)))
        CASE 21
          insertval = 2/(EXP(VAL(mathval$)) - EXP(-VAL(mathval$)))
        CASE 22
          insertval = LOG(VAL(mathval$) + SQR(VAL(mathval$)*VAL(mathval$) + 1))
        CASE 23
          insertval = LOG(VAL(mathval$) + SQR(VAL(mathval$)*VAL(mathval$) - 1))
        CASE 24
          insertval = LOG((1 + VAL(mathval$))/(1 - VAL(mathval$)))/2
        CASE 25
          insertval = LOG((VAL(mathval$) + 1)/(VAL(mathval$) - 1))/2
        CASE 26
          insertval = LOG((SGN(VAL(mathval$))*SQR(-VAL(mathval$)*VAL(mathval$) + 1) + 1)/VAL(mathval$))
        CASE 27
          insertval = LOG((SGN(VAL(mathval$))*SQR(VAL(mathval$)*VAL(mathval$) + 1) + 1)/VAL(mathval$))
        CASE 28
          IF VAL(mathval$) = 0 THEN
            IF soundoff = 0 THEN PLAYWAV (chicken,1)
            MessageDlg("Can't divide by zero. Please correct entry.", mtError, mbOK, 0)
          ELSE
            insertval = 1/VAL(mathval$)
          END IF
        CASE 29
          insertval = EXP(VAL(mathval$))
        CASE 30
          insertval = ABS(VAL(mathval$))
        CASE 31
          insertval = INT(VAL(mathval$))
        CASE 32
          insertval = FRAC(VAL(mathval$))
        CASE 33
          insertval = FLOOR(VAL(mathval$))
        CASE 34
          insertval = CEIL(VAL(mathval$))
        CASE 35
          IF VAL(mathval$) < 0 THEN
            SHOWMESSAGE("You're extracting the root of a negative number." + CHR$(13)_
                      + "QEDTukak will display the real solution only.")
          END IF
          insertval = SGN(VAL(mathval$))*(ABS(VAL(mathval$))^(1/3))
        CASE 36
          insertval = VAL(mathval$)^2
        CASE 37
          insertval = FIX(VAL(mathval$))
          tempval = insertval-1
          FOR x = 1 TO tempval
            insertval = insertval*tempval
            tempval = tempval-1
          NEXT
        CASE 38
          IF mathval$ = "" THEN
            insertval = RND
          ELSE
            insertval = RND(VAL(mathval$))
          END IF
        CASE 39
          comma = INSTR(mathval$,",")
          IF comma = 0 THEN
            IF soundoff = 0 THEN PLAYWAV (chicken,1)
            MessageDlg("Missing comma. Please correct.", mtError, mbOK, 0)
          ELSE
            IF MID$(mathval$,comma+1,1) = "" THEN
              IF soundoff = 0 THEN PLAYWAV (chicken,1)
              MessageDlg("Missing second argument. Please correct.", mtError, mbOK, 0)
            ELSE
              IF VAL(RIGHT$(mathval$,LEN(mathval$)-comma)) = 0 THEN
                IF soundoff = 0 THEN PLAYWAV (chicken,1)
                MessageDlg("Can't divide by zero. Please correct entry.", mtError, mbOK, 0)
              ELSE
                insertval = VAL(LEFT$(mathval$,comma-1)) MOD VAL(RIGHT$(mathval$,LEN(mathval$)-comma))
              END IF
            END IF
          END IF
      END SELECT
      DoInPrecision(insertval,@insertval$)
    END IF
  NEXT
  CheckE(@insertval$)
  formula$ = REPLACESUBSTR$(formula$,oldval$,insertval$)
END SUB

SUB DoInPrecision(value AS DOUBLE, value$ AS STRING)
  IF dochecktag = 0 THEN
    IF precision$ = "" THEN
      value$ = FORMAT$("%g",value)
    ELSE
      value$ = FORMAT$(precision$,value)    
    END IF
  ELSE
    dochecktag = 0
  END IF
END SUB

SUB changeE
  DEFBYTE posE, x
  x = 0
  DO
    INC x
    E$ = MID$(formula$,x,1)
    IF E$ = "" THEN
      EXIT SUB
    ELSEIF E$ = "e" THEN
      posE = x
      INC x
      E$ = MID$(formula$,x,1)  
      SELECT CASE E$
        CASE "-","0" TO "9"
          formula$ = DELETE$(formula$,posE,1)
          formula$ = INSERT$("*10^",formula$,posE)
        CASE "c","i","x"
        CASE ELSE
          IF sound = 0 THEN PLAYWAV (chicken,1)
          SHOWMESSAGE "Syntax error."
          EXIT SUB
      END SELECT
    END IF
  LOOP                  
END SUB

SUB CheckE(newstring$ AS STRING)
  DEFBYTE whereE, whereDot, x, move, powerEnd
  DEFSHORT power
  whereE = INSTR(newstring$,"E")
  x = whereE
  IF whereE = 0 THEN
    EXIT SUB
  ELSE
    whereDot = RINSTR(whereE,newstring$,".")
    IF whereDot < 2 THEN whereDot = 2      'since in scientific format
    DO
      INC x
      IF x >= LEN(newstring$) THEN
        powerEnd = x
        EXIT DO
      END IF  
      powerEnd$ = MID$(newstring$,x,1)
      SELECT CASE powerEnd$
        CASE "+","*","/",")"
          powerEnd = x - 1
          EXIT DO
        CASE "-"
          IF x <> whereE + 1 THEN
            powerEnd = x - 1
            EXIT DO
          END IF
      END SELECT
    LOOP
    oldbase$ = LEFT$(newstring$,whereE-1)
    base$ = REPLACESUBSTR$(oldbase$,".","")
    power$ = MID$(newstring$,whereE+1,powerEnd-whereE)
    power = VAL(power$)
    IF power => 14 THEN EXIT SUB
    checkneg$ = LEFT$(power$,1)
    IF checkneg$ = "-" THEN
      move = ABS(power)
      newbase$ = "." + STRING$(move-(whereDot-1),"0") + base$
    END IF
    newstring$ = newbase$
  END IF
END SUB

SUB DoPrecision
  answer = VAL(formula$)
  IF outform$ = "und" THEN
    memvalue = "Sorry. Beyond reckoning."
    outform$ = outformold$  
  ELSEIF outform$ = "fin" THEN
    memvalue = FORMAT$("%.2n",answer)
  ELSEIF outform$ = "sci" THEN
    memvalue = FORMAT$("%.9e",answer)   
  ELSEIF outform$ = "com" THEN    
    memvalue = FORMAT$("%.2n",answer)
  ELSEIF outform$ = "non" THEN    
    memvalue = formula$
  ELSEIF outform$ = "use" THEN   
    memvalue = FORMAT$(precision$,answer)
  ELSEIF outform$ = "ima" THEN
    memvalue = "i" + FORMAT$("%.2f",answer) 
  ELSE
    memvalue = formula$
  END IF
  ExpSolverForm.Caption = "QEDTukak:  ANSWER = " + memvalue
  HistoryView.InsertItem(1,memvalue)
  HistoryView.InsertItem(2,"")
END SUB

SUB MathButts(Sender AS QBUTTON)
DEFBYTE countEndPar,index
  oldexpression = ExpEdit.Text
  countEndPar = 0
  SELECT CASE Sender.Handle
    CASE SinButt.Handle
      MathText = "sin()"
    CASE CosButt.Handle
      MathText = "cos()"
    CASE TanButt.Handle
      MathText = "tan()"
    CASE CotButt.Handle
      MathText = "cot()"
    CASE SecButt.Handle
      MathText = "sec()"
    CASE CscButt.Handle
      MathText = "csc()"
    CASE ASinButt.Handle
      MathText = "asin()"
    CASE ACosButt.Handle
      MathText = "acos()"
    CASE ATanButt.Handle
      MathText = "atan()"
    CASE ACotButt.Handle
      MathText = "acot()"
    CASE ASecButt.Handle
      MathText = "asec()"
    CASE ACscButt.Handle
      MathText = "acsc()"
    CASE SinhButt.Handle
      MathText = "sinh()"
    CASE CoshButt.Handle
      MathText = "cosh()"
    CASE TanhButt.Handle
      MathText = "tanh()"
    CASE CothButt.Handle
      MathText = "coth()"
    CASE SechButt.Handle
      MathText = "sech()"
    CASE CschButt.Handle
      MathText = "csch()"
    CASE ASinhButt.Handle
      MathText = "asinh()"
    CASE ACoshButt.Handle
      MathText = "acosh()"
    CASE ATanhButt.Handle
      MathText = "atanh()"
    CASE ACothButt.Handle
      MathText = "acoth()"
    CASE ASechButt.Handle
      MathText = "asech()"
    CASE ACschButt.Handle
      MathText = "acsch()"
    CASE LogButt.Handle
      MathText = "log()"
    CASE LnButt.Handle
      MathText = "ln()"
    CASE IntButt.Handle
      MathText = "int()"
    CASE FracButt.Handle
      MathText = "frac()"
    CASE FloorButt.Handle
      MathText = "floor()"
    CASE CeilButt.Handle
      MathText = "ceil()"
    CASE ExpButt.Handle
      MathText = "exp()"
    CASE PiButt.Handle
      MathText = "pi"
    CASE SqrtButt.Handle
      MathText = "sqrt()"
    CASE CbrtButt.Handle
      MathText = "cbrt()"
    CASE sqrButt.Handle
      MathText = "sqr()"
    CASE AbsButt.Handle
      MathText = "abs()"
    CASE InvButt.Handle
      MathText = "inv()"
    CASE FactButt.Handle
      MathText = "fact()"
    CASE RandButt.Handle
      MathText = "rand()"
    CASE ModButt.Handle
      MathText = "mod()"
    CASE DotButt.Handle
      MathText = "."
    CASE AddButt.Handle
      MathText = " + "
    CASE SubButt.Handle
      MathText = " - "
    CASE MulButt.Handle
      MathText = " * "
    CASE DivButt.Handle
      MathText = " / "
    CASE PowButt.Handle
      MathText = " ^ "
    CASE ZeroButt.Handle
      MathText = "0"
    CASE OneButt.Handle
      MathText = "1"
    CASE TwoButt.Handle
      MathText = "2"
    CASE ThreeButt.Handle
      MathText = "3"
    CASE FourButt.Handle
      MathText = "4"
    CASE FiveButt.Handle
      MathText = "5"
    CASE SixButt.Handle
      MathText = "6"
    CASE SevenButt.Handle
      MathText = "7"
    CASE EightButt.Handle
      MathText = "8"
    CASE NineButt.Handle
      MathText = "9"
    CASE BegParButt.Handle
      MathText = "("
    CASE EndParButt.Handle
      MathText = ")"
  END SELECT
  SELECT CASE MathText
    CASE "0" TO "9","."
      IF soundoff = 0 THEN PLAYWAV (typing,1)
    CASE "+","-","*","/","^"
      IF soundoff = 0 THEN PLAYWAV (laser,1)
    CASE ELSE
      IF soundoff = 0 THEN PLAYWAV (whoosh,1)
  END SELECT
  ExpEdit.Text = INSERT$(MathText,ExpEdit.Text,ExpEdit.SelStart+1)
  index = LEN(ExpEdit.Text)
  IF MathText <> ")" THEN
    DO
      find$ = MID$(ExpEdit.Text,index,1)
      IF find$ = ")" THEN INC countEndPar 
      DEC index
    LOOP UNTIL find$ <> ")"
  END IF
  ExpEdit.SelStart = LEN(ExpEdit.Text) - countEndPar
  SetFocus(ExpEdit.Handle)
END SUB        

SUB ChangeMode
  IF soundoff = 0 THEN PLAYWAV (wipe,1)
  IF DegRad.Caption = "D" THEN
    CMode = 1
    CModeN = 1
    DegRad.Caption = "R"
    DegRad.Hint = "Now in Radians. Click for Degrees."
  ELSE
    CMode = 57.2957795130824
    CModeN = 0.0174532925199433
    DegRad.Caption = "D"
    DegRad.Hint = "Now in Degrees. Click for Radians."
  END IF  
END SUB

SUB Click
  IF soundoff = 0 THEN PLAYWAV (gong,1)
  Animate(HistoryForm.Handle)
  Animate(FunctionsForm.Handle)
  Animate(VariablesForm.Handle)
  HistoryForm.Visible = 1
  FunctionsForm.Visible = 1
  VariablesForm.Visible = 1
  SetFocus(ExpEdit.Handle)
END SUB

SUB FunctionsShow
  IF soundoff = 0 THEN PLAYWAV (gong,1)
  Animate(FunctionsForm.Handle)
  FunctionsForm.Visible = 1
  SetFocus(ExpEdit.Handle)
END SUB

SUB HistoryShow
  IF soundoff = 0 THEN PLAYWAV (gong,1)
  Animate(HistoryForm.Handle)
  HistoryForm.Visible = 1
  SetFocus(ExpEdit.Handle)
END SUB

SUB OutFinancial
  outform$ = "fin"
  OutFormatType
  OutFin.Caption = "> &Financial"
END SUB

SUB OutScientific
  outform$ = "sci"
  OutFormatType
  OutSci.Caption = "> &Scientific"
END SUB

SUB OutComma
  outform$ = "com"
  OutFormatType
  OutCom.Caption = "> &Comma separated"
END SUB

SUB OutNone
  outform$ = "non"
  OutFormatType
  OutNon.Caption = "> &No format"
END SUB

SUB OutFormatType
  OutFin.Caption = "&Financial"
  OutSci.Caption = "&Scientific"
  OutCom.Caption = "&Comma separated"
  OutNon.Caption = "&No format"
  OutNoForm.Caption = "&User-set precision"
  IF outform$ = "use" THEN
    OutNoForm.Caption = "> &User-set precision"
  ELSE
    OutFormat
  END IF
END SUB

SUB OutFormat
  OutPrecise15.Caption = "15"
  OutPrecise14.Caption = "14"
  OutPrecise13.Caption = "13"
  OutPrecise12.Caption = "12"
  OutPrecise11.Caption = "11"
  OutPrecise10.Caption = "10"
  OutPrecise9.Caption = "9"
  OutPrecise8.Caption = "8"
  OutPrecise7.Caption = "7"
  OutPrecise6.Caption = "6"
  OutPrecise5.Caption = "5"
  OutPrecise4.Caption = "4"
  OutPrecise3.Caption = "3"
  OutPrecise2.Caption = "2"
  OutPrecise1.Caption = "1"
END SUB

SUB OutUser(Sender AS QMENUITEM)
  OutFormat
  SELECT CASE Sender.Handle
    CASE OutPrecise1.Handle
      precision$ = "%.1g"
      OutPrecise1.Caption = "> 1"
    CASE OutPrecise2.Handle
      precision$ = "%.2g"
      OutPrecise2.Caption = "> 2"
    CASE OutPrecise3.Handle
      precision$ = "%.3g"
      OutPrecise3.Caption = "> 3"
    CASE OutPrecise4.Handle
      precision$ = "%.4g"
      OutPrecise4.Caption = "> 4"
    CASE OutPrecise5.Handle
      precision$ = "%.5g"
      OutPrecise5.Caption = "> 5"
    CASE OutPrecise6.Handle
      precision$ = "%.6g"
      OutPrecise6.Caption = "> 6"
    CASE OutPrecise7.Handle
      precision$ = "%.7g"
      OutPrecise7.Caption = "> 7"
    CASE OutPrecise8.Handle
      precision$ = "%.8g"
      OutPrecise8.Caption = "> 8"
    CASE OutPrecise9.Handle
      precision$ = "%.9g"
      OutPrecise9.Caption = "> 9"
    CASE OutPrecise10.Handle
      precision$ = "%.10g"
      OutPrecise10.Caption = "> 10"
    CASE OutPrecise11.Handle
      precision$ = "%.11g"
      OutPrecise11.Caption = "> 11"
    CASE OutPrecise12.Handle
      precision$ = "%.12g"
      OutPrecise12.Caption = "> 12"
    CASE OutPrecise13.Handle
      precision$ = "%.13g"
      OutPrecise13.Caption = "> 13"
    CASE OutPrecise14.Handle
      precision$ = "%.14g"
      OutPrecise14.Caption = "> 14"
    CASE OutPrecise15.Handle
      precision$ = "%.15g"
      OutPrecise15.Caption = "> 15"
  END SELECT
  outform$ = "use"
  OutFormatType
END SUB

SUB OutPrecision
  OutFormat
  SELECT CASE precision$
    CASE "%.1g"
      OutPrecise1.Caption = "> 1"
    CASE "%.2g"
      OutPrecise2.Caption = "> 2"
    CASE "%.3g" 
      OutPrecise3.Caption = "> 3"
    CASE "%.4g"
      OutPrecise4.Caption = "> 4"
    CASE "%.5g" 
      OutPrecise5.Caption = "> 5"
    CASE "%.6g" 
      OutPrecise6.Caption = "> 6"
    CASE "%.7g" 
      OutPrecise7.Caption = "> 7"
    CASE "%.8g" 
      OutPrecise8.Caption = "> 8"
    CASE "%.9g" 
      OutPrecise9.Caption = "> 9"
    CASE "%.10g" 
      OutPrecise10.Caption = "> 10"
    CASE "%.11g" 
      OutPrecise11.Caption = "> 11"
    CASE "%.12g" 
      OutPrecise12.Caption = "> 12"
    CASE "%.13g" 
      OutPrecise13.Caption = "> 13"
    CASE "%.14g" 
      OutPrecise14.Caption = "> 14"
    CASE "%.15g" 
      OutPrecise15.Caption = "> 15"
  END SELECT
  OutFormatType
END SUB

SUB ShowNotes
  IF soundoff = 0 THEN PLAYWAV (cuckoo,1)
  Timer2.Enabled = 1
  Animate(NoteProductForm.Handle)
  NoteProductForm.Visible = 1
END SUB

SUB NotesShow
  DEFSHORT y
  DXNotes.FillRect(0,0,84,63,0) 
  INC y
  IF y > 84 THEN y = 1
  IF y < 11 THEN b$ = RIGHT$("wasaywasay",y)
  IF y < 8 THEN a$ = RIGHT$(".com.ph",y)    
  DXNotes.TextOut(y,y+2,a$,clGreen,clBlack)
  DXNotes.TextOut(y+2,2,b$,clWhite,clBlack)
  DXNotes.TextOut(1,y+16,"@i-manila",&HDDCE,clBlack)  
END SUB

SUB SendMe
  IF soundoff = 0 THEN PLAYWAV(camera,1)
  dummy = SHELL ("start http://pages.zdnet.com/wasaywasay/wasaywasay", SW_HIDE)
  IF dummy = 0 THEN
    dummy = SHELL ("start http://pages.zdnet.com/wasaywasay/wasaywasay", SW_HIDE)
    IF dummy = 0 THEN
      SHOWMESSAGE "Can't find your Start program. \nPlease go to http://pages.zdnet.com/wasaywasay/wasaywasay manually." 
    END IF
  END IF
END SUB

SUB EMailMe
  IF soundoff = 0 THEN PLAYWAV (camera,1)
  dummy = SHELL("c:\windows\command\Start mailto:wasaywasay@i-manila.com.ph?subject=QEDTukak",0)
  IF dummy = 0 THEN
    dummy = SHELL("Start mailto:wasaywasay@i-manila.com.ph?subject=QEDTukak",0)
    IF dummy = 0 THEN
      SHOWMESSAGE "Can't find your Start program. Please do manual email instead." 
    END IF
  END IF
END SUB

SUB SoundOnOff
  IF Sounds.Caption = "Switch sounds o&ff" THEN
    soundoff = 1
    Sounds.Caption = "Switch sounds o&n"
  ELSE
    soundoff = 0
    Sounds.Caption = "Switch sounds o&ff"
  END IF
END SUB

SUB ClipboardCopy
  IF soundoff = 0 THEN PLAYWAV (camera,1)
  ClipBoard.Open
  ClipBoard.SetAsText(DELETE$(ExpSolverForm.Caption,1,20))
  ClipBoard.Close
END SUB

SUB ClipboardPaste
  IF soundoff = 0 THEN PLAYWAV (whoosh,1)
  ClipBoard.Open   
  ExpSolverForm.Caption = "QEDTukak:  ANSWER = " + ClipBoard.Text
  ClipBoard.Close
END SUB

SUB SaveFile
  DIM lastitem AS WORD
  DIM FileH AS QSAVEDIALOG
  DIM SaveFileH AS QSTRINGLIST
  lastitem = HistoryView.ItemCount - 1
  FOR x = 0 TO lastitem
    SaveFileH.AddItems HistoryView.Item(x)
  NEXT
  IF FileH.Execute THEN 
    ShowMessage "Saving to: " + FileH.FileName
  END IF 
  SaveFileH.SaveToFile(FileH.FileName)
END SUB

SUB PrintFile
 LPRINT HistoryView.Text
 LFLUSH
END SUB

SUB MilSTDTime
  IF Times.Caption = "Switch to &Military Time" THEN
    military = 1
    Times.Caption = "Switch to &Standard Time"
  ELSE
    military = 0
    Times.Caption = "Switch to &Military Time"
  END IF
END SUB

SUB Time
  DEFINT milhour, hour, min
  hour =  VAL(LEFT$(TIME$,2))
  min = VAL(MID$(TIME$,4,2))     
  milhour = hour
  IF hour >= 12 AND hour < 24 THEN
    hour = hour - 12
    IF hour = 0 THEN hour = 12
    ampm$ = " PM"
  ELSEIF hour = 0 THEN 
    hour = 12
    ampm$ = " AM"
  ELSE
    ampm$ = " AM"
  END IF
  IF min < 10 THEN
    IF military = 1 THEN
      TimePanel.Caption = STR$(milhour) + ":0" + STR$(min) + RIGHT$(TIME$,3)
    ELSE
      TimePanel.Caption = STR$(hour) + ":0" + STR$(min) + RIGHT$(TIME$,3) + ampm$
    END IF
  ELSE
    IF military = 1 THEN
      TimePanel.Caption = TIME$
    ELSE
      TimePanel.Caption = STR$(hour) + ":" + STR$(min) + RIGHT$(TIME$,3) + ampm$
    END IF
  END IF
END SUB

SUB OnTop
  IF always = 0 THEN
    always = 1
    AlwaysTop.Caption = "> &Always on top"
  ELSE
    always = 0
    AlwaysTop.Caption = "&Always on top"
  END IF
END SUB

SUB ConstantsShow
  Constants.PopUp(Screen.MouseX,ScreenMouseY)
END SUB  

SUB ConstantsAll(Sender AS QMENUITEM)
  DIM AddCaption AS STRING
  SELECT CASE Sender.Handle
    CASE AccelerationG.Handle
      AddCaption = "9.80665"
    CASE ADensity.Handle
      AddCaption = "1.293"
    CASE LSpeed.Handle
      AddCaption = "299792458"
    CASE SolarC.Handle
      AddCaption = "1340"
    CASE SSpeed.Handle
      AddCaption = "331.4"
    CASE SAtmosphere.Handle
      AddCaption = "101300"
    CASE EERadius.Handle
      AddCaption = "6378000"
    CASE EEscapeV.Handle
      AddCaption = "11186"
    CASE MEarthDipole.Handle
      AddCaption = "6.400E21"
    CASE MEarth.Handle
      AddCaption = "5.983E24"
    CASE MAngularS.Handle
      AddCaption = ".0000729"    
    CASE DEarth.Handle
      AddCaption = "5522"
    CASE MOrbitalS.Handle
      AddCaption = "29770"  
    CASE PERadius.Handle
      AddCaption = "6357000"
    CASE VEarth.Handle
      AddCaption = "1.087E21"
    CASE AlphaPMass.Handle
      AddCaption = "6.64465598E-27"
    CASE ElectronCMassR.Handle
      AddCaption = "175881961000"
    CASE ElectronMass.Handle
      AddCaption = "9.10938188E-31"
    CASE MuonMass.Handle
      AddCaption = "1.88353109E-28"
    CASE NeutronMass.Handle
      AddCaption = "1.67492716E-27"
    CASE ProtonMass.Handle
      AddCaption = "1.67262158E-27"
    CASE ATomicMC.Handle
      AddCaption = "1.66053873E-27"
    CASE AvogadroC.Handle
      AddCaption = "6.02214199E23"
    CASE BoltzmannC.Handle
      AddCaption = "1.3806503E-23"
    CASE ECharge.Handle
      AddCaption = "1.602176462E-19"
    CASE FaradayC.Handle
      AddCaption = "96485.3415"
    CASE GravityC.Handle
      AddCaption = ".000000000066726"
    CASE PermeabilityC.Handle
      AddCaption = "1.25663706143E-6"
    CASE PermittivityC.Handle
      AddCaption = "8.85418781762E-12"
    CASE PlankC.Handle
      AddCaption = "6.62606876E-34"
    CASE RydbergC.Handle
      AddCaption = "10973731.568549"
    CASE SBoltzmannC.Handle
      AddCaption = ".000000056704"
    CASE UnivGasC.Handle
      AddCaption = "8.314472"
    CASE WienC.Handle
      AddCaption = ".00290"                
  END SELECT
  ExpEdit.Text = ExpEdit.Text + " " + AddCaption
  ExpEdit.SelStart = LEN(ExpEdit.Text)
END SUB

SUB ConversionsShow
  Conversions.PopUp(Screen.MouseX,ScreenMouseY)
END SUB  

SUB ConversionsAll(Sender AS QMENUITEM)
  DIM AddCaption AS STRING
  SELECT CASE Sender.Handle
    CASE ftm.Handle
      AddCaption = "/ 3.28084"
    CASE mft.Handle
      AddCaption = "* 3.28084"
    CASE incm.Handle
      AddCaption = "* 2.54"
    CASE cmin.Handle
      AddCaption = "/ 2.54"
    CASE kmmi.Handle
      AddCaption = "/ 1.609344"
    CASE mikm.Handle
      AddCaption = "* 1.609344"
    CASE inft.Handle
      AddCaption = "/ 12"
    CASE ftin.Handle
      AddCaption = "* 12"
    CASE ydm.Handle
      AddCaption = "/ 1.093613"
    CASE myd.Handle
      AddCaption = "* 1.093613"
    CASE fam.Handle
      AddCaption = "* 1.8288"
    CASE mfa.Handle
      AddCaption = "/ 1.8288"
    CASE mily.Handle
      AddCaption = "/ 5880000000000"
    CASE lymi.Handle
      AddCaption = "* 5880000000000"
    CASE PartoLy.Handle
      AddCaption = "* 3.261643"
    CASE LytoPar.Handle
      AddCaption = "/ 3.261643"
    CASE ft3m3.Handle
      AddCaption = "/ 35.314667"
    CASE m3ft3.Handle
      AddCaption = "* 35.314667"
    CASE ft2m2.Handle
      AddCaption = "/ 10.76391"
    CASE m2ft2.Handle
      AddCaption = "* 10.76391"
    CASE in2cm2.Handle
      AddCaption = "* 6.4516"
    CASE cm2in2.Handle
      AddCaption = "/ 6.4516"
    CASE haac.Handle
      AddCaption = "* 2.471054"
    CASE acha.Handle
      AddCaption = "/ 2.471054"
    CASE lbkg.Handle
      AddCaption = "/ 2.204623"
    CASE kglb.Handle
      AddCaption = "* 2.204623"
    CASE TontoKilo.Handle
      AddCaption = "* 1000"
    CASE KilotoTon.Handle
      AddCaption = "/ 1000"      
    CASE TontoKiloUS.Handle
      AddCaption = "* 907.18474"
    CASE KilotoTonUS.Handle
      AddCaption = "/ 907.18474"
    CASE TontoKiloUK.Handle
      AddCaption = "* 1016.046909"
    CASE KilotoTonUK.Handle
      AddCaption = "/ 1016.046909"      
    CASE OztoGram.Handle
      AddCaption = "* 28.349551"
    CASE GramtoOz.Handle
      AddCaption = "/ 28.349551"
    CASE OztoGramT.Handle
      AddCaption = "* 31.103508"
    CASE GramtoOzT.Handle
      AddCaption = "/ 31.103508"      
    CASE FC.Handle
      AddCaption = "- 32 / 1.8"
    CASE CF.Handle
      AddCaption = "* 1.8 + 32"
    CASE CK.Handle
      AddCaption = "+ 273.16"
    CASE KC.Handle
      AddCaption = "- 273.16"
    CASE GaltoLit.Handle
      AddCaption = "* 4.404884"
    CASE LittoGal.Handle
      AddCaption = "/ 4.404884"
    CASE GaltoLitL.Handle
      AddCaption = "* 3.785412"
    CASE LittoGalL.Handle
      AddCaption = "/ 3.785412"      
    CASE QrtoGal.Handle
      AddCaption = "/ 4"
    CASE GaltoQrt.Handle
      AddCaption = "* 4"
    CASE PinttoLtr.Handle
      AddCaption = "* 0.55061"
    CASE LtrtoPint.Handle
      AddCaption = "/ 0.55061"      
    CASE PinttoLtrL.Handle
      AddCaption = "* 0.473176"
    CASE LtrtoPintL.Handle
      AddCaption = "/ 0.473176"
    CASE HptoWatt.Handle
      AddCaption = "* 745.7"
    CASE WatttoHp.Handle
      AddCaption = "/ 745.7"
    CASE HptoWattM.Handle
      AddCaption = "* 735.499"
    CASE WatttoHpM.Handle
      AddCaption = "/ 735.499"      
    CASE BTUtoWatt.Handle
      AddCaption = "* 0.293071"
    CASE WatttoBTU.Handle
      AddCaption = "/ 0.293071"
    CASE KwtoWatt.Handle
      AddCaption = "* 1000"
    CASE WatttoKw.Handle
      AddCaption = "/ 1000"
    CASE KphtoMph.Handle
      AddCaption = "/ 1.609344"
    CASE MphtoKph.Handle
      AddCaption = "* 1.609344"
    CASE KnottoMph.Handle
      AddCaption = "* 1.150778"
    CASE MphtoKnot.Handle
      AddCaption = "/ 1.150778"
    CASE MpstoFps.Handle
      AddCaption = "* 3.28084"
    CASE FpstoMps.Handle
      AddCaption = "/ 3.28084"
    CASE SectoMin.Handle
      AddCaption = "/ 60"
    CASE MintoSec.Handle
      AddCaption = "* 60"
    CASE MintoHr.Handle
      AddCaption = "/ 60"
    CASE HrtoMin.Handle
      AddCaption = "* 60"
    CASE MintoDay.Handle
      AddCaption = "/ 1440"
    CASE DaytoMin.Handle
      AddCaption = "* 1440"
    CASE DaytoHr.Handle
      AddCaption = "* 24"
    CASE HrtoDay.Handle
      AddCaption = "/ 24"
    CASE PsitoPas.Handle
      AddCaption = "* 6894.757"
    CASE PastoPsi.Handle
      AddCaption = "/ 6894.757"
    CASE PsitoAtm.Handle
      AddCaption = "* 0.068046"
    CASE Atmtopsi.Handle
      AddCaption = "/ 0.068046"
    CASE PsitoKgscm.Handle
      AddCaption = "* 0.070307"
    CASE KgscmtoPsi.Handle
      AddCaption = "/ 0.070307"
  END SELECT
  ExpEdit.Text = ExpEdit.Text + " " + AddCaption
  ExpEdit.SelStart = LEN(ExpEdit.Text)
END SUB

SUB VariablesShow
  IF soundoff = 0 THEN PLAYWAV (gong,1)
  Animate(VariablesForm.Handle)
  VariablesForm.Visible = 1
END SUB

SUB SendAnswer
  IF soundoff = 0 THEN PLAYWAV (laser,1)
  ExpEdit.Text = ExpEdit.Text + " " + memvalue
  ExpEdit.SelStart = LEN(ExpEdit.Text)
END SUB

SUB DummyMin(Hwnd&, uMsg&, wParam&, lParam&)
  PaintForm
END SUB 

SUB PaintForm
  PaintDesktop GetDC(ExpSolverForm.Handle)  
END SUB

SUB CloseNotes
  IF soundoff = 0 THEN PLAYWAV (cuckoo,1)
  Timer2.Enabled = 0
  Deanimate(NoteProductForm.Handle)
END SUB

SUB CloseFunctions 
  IF soundoff = 0 THEN PLAYWAV (gong,1)
  Deanimate(FunctionsForm.Handle)
END SUB

SUB CloseHistory 
  IF soundoff = 0 THEN PLAYWAV (gong,1)
  Deanimate(HistoryForm.Handle)
END SUB

SUB CloseVariables 
  IF soundoff = 0 THEN PLAYWAV (gong,1)
  Deanimate(VariablesForm.Handle)
END SUB

SUB Initialize
  RANDOMIZE TIMER
  'Application.IcoHandle = QEDTukak
  Application.HintShortPause = 25
  Application.HintPause = 25
  Application.HintHidePause = 6500    
  IF FILEEXISTS("QEDTukak.ini") <> 0 THEN
    DIM File as QFileStream
    File.Open("QEDTukak.ini",fmOpenReadWrite)
    inifile$ = File.ReadStr(File.Size)
    where = INSTR(inifile$,CHR$(13))  
    outform$ = MID$(inifile$,1,3)
    soundoff = VAL(MID$(inifile$,4,1))
    military = VAL(MID$(inifile$,5,1))
    always = VAL(MID$(inifile$,6,1))
    DegRad.Caption = MID$(inifile$,7,1)
    precision$ = RTRIM$(MID$(inifile$,8,where-8))
    ExpEdit.Text = RTRIM$(RIGHT$(inifile$,LEN(inifile$)-where))
    ExpEdit.SelStart = LEN(ExpEdit.Text)    
    File.Close
  ELSE 
    outform$ = "non"
    soundoff = 0
    military = 0
    always = 0
    DegRad.Caption = "D"
    precision$ = ""
    ExpEdit.Text = ""
  END IF
  IF military = 1 THEN
    Times.Caption = "Switch to &Standard Time"
  ELSE
    Times.Caption = "Switch to &Military Time"
  END IF
  IF DegRad.Caption = "D" THEN
    CMode = 57.2957795130824
    CModeN = 0.0174532925199433
    DegRad.Caption = "D"
    DegRad.Hint = "Now in Degrees. Click for Radians."
  ELSE
    CMode = 1
    CModeN = 1
    DegRad.Caption = "R"
    DegRad.Hint = "Now in Radians. Click for Degrees."
  END IF
  IF always = 1 THEN
    AlwaysTop.Caption = "> &Always on top"
  ELSE
    AlwaysTop.Caption = "&Always on top"
  END IF
  IF soundoff = 1 THEN    
    Sounds.Caption = "Switch sounds o&n"
  ELSE
    Sounds.Caption = "Switch sounds o&ff"
  END IF
  SELECT CASE outform$
    CASE "sci"
      OutScientific
    CASE "fin"
      OutFinancial
    CASE "com"
      OutComma
    CASE "non"
      OutNone
    CASE "use"
      OutPrecision
  END SELECT
  Time
END SUB

SUB CloseSolver
  DIM File AS QFileStream
  File.Open("QEDTukak.ini",fmCreate)
  inifile$ = outform$ + STR$(soundoff) + STR$(military) + STR$(always) + _
             DegRad.Caption + precision$ + CHR$(13) + ExpEdit.Text
  File.WriteStr(inifile$,LEN(inifile$))
  File.Close
  IF soundoff = 0 THEN PLAYWAV (wipe,0)
  ExpSolverForm.Visible = 0
  HistoryForm.Visible = 0
  FunctionsForm.Visible = 0
  VariablesForm.Visible = 0
  NoteProductForm.Visible = 0
  Application.Terminate
END SUB

SUB Animate(Handle AS INTEGER)
  AnimateWindow Handle, 300, AW_CENTER
  SELECT CASE Handle
    CASE NoteProductForm.Handle
      NoteProductForm.Repaint
    CASE FunctionsForm.Handle
      FunctionsForm.Repaint
    CASE HistoryForm.Handle
      HistoryForm.Repaint
    CASE VariablesForm.Handle
      VariablesForm.Repaint
  END SELECT
END SUB

SUB Deanimate(Handle AS INTEGER)
  AnimateWindow Handle, 300, AW_CENTER OR AW_HIDE
END SUB

SUB ResizeView
  HistoryView.Height = HistoryForm.ClientHeight - 10
  HistoryView.Width = HistoryForm.ClientWidth - 10
END SUB

Initialize
ExpSolver
DO
  DOEVENTS
  IF always = 1 THEN
    ExpSolverForm.Color = &HDBC777
    HistoryForm.Color = &HDBC777
    FunctionsForm.Color = &HDBC777
    NoteProductForm.Color = &HDBC777
    VariablesForm.Color = &HDBC777   
    SELECT CASE GetFocus()
      CASE ExpEdit.Handle 
        SetForegroundWindow(ExpSolverForm.Handle)
      CASE HistoryForm.Handle 
        SetForegroundWindow(HistoryForm.Handle)
      CASE VariablesForm.Handle 
        SetForegroundWindow(VariablesForm.Handle)
      CASE SinButt.Handle,CosButt.Handle,TanButt.Handle,CotButt.Handle,_
           SecButt.Handle,CscButt.Handle,ASinButt.Handle,ACosButt.Handle,_
           ATanButt.Handle,ACotButt.Handle,ASecButt.Handle,ACscButt.Handle,_
           SinhButt.Handle,CoshButt.Handle,TanhButt.Handle,CothButt.Handle,_
           SechButt.Handle,CschButt.Handle,ASinhButt.Handle,ACoshButt.Handle,_
           ATanhButt.Handle,ACothButt.Handle,ASechButt.Handle,ACschButt.Handle,_
           LogButt.Handle,LnButt.Handle,IntButt.Handle,FracButt.Handle,_
           FloorButt.Handle,CeilButt.Handle,ExpButt.Handle,PiButt.Handle,_
           SqrtButt.Handle,CbrtButt.Handle,sqrButt.Handle,AbsButt.Handle,_
           InvButt.Handle,BegParButt.Handle,EndParButt.Handle,DotButt.Handle,_
           AddButt.Handle,SubButt.Handle,MulButt.Handle,DivButt.Handle,PowButt.Handle,_
           ZeroButt.Handle,OneButt.Handle,TwoButt.Handle,ThreeButt.Handle,_
           FourButt.Handle,FiveButt.Handle,SixButt.Handle,SevenButt.Handle,_
           EightButt.Handle,NineButt.Handle,DegRadButt.Handle,SendButt.Handle,_
           FactButt.Handle,ModButt.Handle,RandButt.Handle
             SetForegroundWindow(FunctionsForm.Handle)
      CASE ELSE
        SetWindowPos(ExpSolverForm.Handle, -1, 0, 0, 0, 0,SWP_NOMOVE OR SWP_NOSIZE)
    END SELECT
  ELSE
    ExpSolverForm.Color = &HABC777
    HistoryForm.Color = &HABC777
    FunctionsForm.Color = &HABC777
    NoteProductForm.Color = &HABC777
    VariablesForm.Color = &HABC777 
  END IF   
LOOP UNTIL ExpSolverForm.Visible = 0

Application.Terminate
