Guidance
指路人
g.yi.org
software / rapidq / Examples / Algorithm & Maths / Probability Distributions / ProbCalc.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
'----- Compiler Directives
     $TYPECHECK ON
     $IFNDEF True
      $DEFINE True 1
     $ENDIF
     $IFNDEF False
      $DEFINE False 0
     $ENDIF

     $INCLUDE "C:\rapidq\qstat\ProbDists.inc"

'----- API Constants and Functions
     CONST GWL_HWNDPARENT = (-8)                         'Minimize to task bar
     CONST HWND_DESKTOP = 0
     DECLARE FUNCTION SetWindowLong LIB "user32" ALIAS "SetWindowLongA"_
      (hwnd AS LONG, nIndex AS LONG, dwNewLong AS LONG) AS LONG

'----- Declarations
     DECLARE SUB btnClick (SENDER AS QBUTTON)
     DECLARE SUB rdoClick (SENDER AS QRADIOBUTTON)
     DECLARE SUB frmClose (SENDER AS QFORM)

     DIM TestType AS INTEGER

'----- Define Form
     CREATE frmMain AS QFORM
      CAPTION = "Probability Distribution Calculator"
      Width = 405
      Height = 310
      BorderStyle = 1
      Center
      DelBorderIcons (2)
      OnClose = frmClose
      CREATE lbl1 AS QLABEL
       CAPTION = ""
       Left = 210
       Top = 45
       Width = 56
       Transparent = 1
      END CREATE
      CREATE lbl2 AS QLABEL
       CAPTION = ""
       Left = 210
       Top = 85
       Transparent = 1
      END CREATE
      CREATE lbl3 AS QLABEL
       CAPTION = "df 2"
       Left = 210
       Top = 125
       Transparent = 1
      END CREATE
      CREATE lbl4 AS QLABEL
       CAPTION = "Result"
       Left = 210
       Top = 165
      END CREATE
      CREATE grpTest AS QGROUPBOX
       Left = 30
       Top = 30
       Width = 129
       Height = 177
       CREATE rdoZ AS QRADIOBUTTON
        CAPTION = "&z Probability"
        Left = 13
        Top = 15
        Width = 110
        TabOrder = 0
        Tag = 1
        OnClick = rdoClick
       END CREATE
       CREATE rdoInvZ AS QRADIOBUTTON
        CAPTION = "&Inverse z Probabilty"
        Left = 13
        Top = 35
        Width = 110
        TabOrder = 1
        Tag = 2
        OnClick = rdoClick
       END CREATE
       CREATE rdoT AS QRADIOBUTTON
        CAPTION = "&t Probability"
        Left = 13
        Top = 55
        Width = 110
        TabOrder = 2
        Tag = 3
        OnClick = rdoClick
       END CREATE
       CREATE rdoInvT AS QRADIOBUTTON
        CAPTION = "I&nverse t Probability"
        Left = 13
        Top = 75
        Width = 110
        TabOrder = 3
        Tag = 4
        OnClick = rdoClick
       END CREATE
       CREATE rdoF AS QRADIOBUTTON
        CAPTION = "&f Probability"
        Left = 13
        Top = 95
        Width = 110
        Height = 19
        TabOrder = 4
        Tag = 5
        OnClick = rdoClick
       END CREATE
       CREATE rdoInvF AS QRADIOBUTTON
        CAPTION = "In&verse f Probability"
        Left = 13
        Top = 115
        Width = 110
        TabOrder = 5
        Tag = 6
        OnClick = rdoClick
       END CREATE
       CREATE rdoChi AS QRADIOBUTTON
        CAPTION = "C&hi Probability"
        Left = 13
        Top = 135
        Width = 110
        TabOrder = 6
        Tag = 7
        OnClick = rdoClick
       END CREATE
       CREATE rdoInvChi AS QRADIOBUTTON
        CAPTION = "Inv Chi &Probability"
        Left = 13
        Top = 155
        Width = 110
        TabOrder = 7
        Tag = 8
        OnClick = rdoClick
       END CREATE
      END CREATE
      CREATE txtArg1 AS QEDIT
       Text = ""
       Left = 300
       Top = 40
       Width = 60
       TabOrder = 2
      END CREATE
      CREATE txtArg2 AS QEDIT
       Text = ""
       Left = 300
       Top = 80
       Width = 60
       TabOrder = 3
      END CREATE
      CREATE txtArg3 AS QEDIT
       Text = ""
       Left = 300
       Top = 120
       Width = 60
       TabOrder = 4
      END CREATE
      CREATE txtResult AS QEDIT
       Text = ""
       Left = 300
       Top = 160
       Width = 60
       Enabled = False
      END CREATE
      CREATE btnCalc AS QBUTTON
       CAPTION = "&Calculate"
       Left = 200
       Top = 230
       TabOrder = 5
       Tag = 1
       Default = True
       OnClick = btnClick
      END CREATE
      CREATE btnQuit AS QBUTTON
       CAPTION = "&Quit"
       Left = 295
       Top = 230
       TabOrder = 6
       Tag = 2
       OnClick = btnClick
      END CREATE
      CREATE grpTail AS QGROUPBOX
       Left = 30
       Top = 220
       Width = 130
       Height = 35
       TabOrder = 1
       CREATE rdo1Tail AS QRADIOBUTTON
        CAPTION = "&1 Tail"
        Left = 5
        Top = 12
        Width = 60
        Tag = 6
       END CREATE
       CREATE rdo2Tail AS QRADIOBUTTON
        CAPTION = "&2 Tail"
        Left = 67
        Top = 12
        Width = 60
        Tag = 10
       END CREATE
      END CREATE
     END CREATE

'----- API Call that lets RapidQ programs minimize to the task bar
     setwindowlong(frmMain.handle, GWL_HWNDPARENT, HWND_DESKTOP)
     setwindowlong(application.handle, GWL_HWNDPARENT, frmMain.handle)

'----- Initialization Code
     rdoZ.Checked = True
     lbl2.Visible = False
     lbl3.Visible = False
     txtArg2.Visible = False
     txtArg3.Visible = False
     grpTail.Visible = False
     TestType = 1


'----- Application Entry
     frmMain.SHOWMODAL


'----- SUBs

     SUB frmClose (SENDER AS QFORM)

      Application.Terminate

     END SUB
'--------------------------------------------------------------------------------------

     SUB btnClick (SENDER AS QBUTTON)

      DIM i AS INTEGER
      DIM x AS DOUBLE

      SELECT CASE Sender.Tag

      CASE 1
       SELECT CASE TestType

       CASE 1  'Z
        x = zDist(VAL(txtArg1.Text))
        txtResult.Text = STRF$(x, 2, 6, 4)
       CASE 2  'InvZ
        x = zDistInv(VAL(txtArg1.Text))
        txtResult.Text = STRF$(x, 2, 6, 4)
       CASE 3  'T
        IF rdo1Tail.Checked = True THEN i = 1 ELSE i = 2
        x = tDist(VAL(txtArg1.Text), VAL(txtArg2.Text), i)
        txtResult.Text = STRF$(x, 2, 6, 4)
       CASE 4  'InvT
        IF rdo1Tail.Checked = True THEN i = 1 ELSE i = 2
        x = tDistInv(VAL(txtArg1.Text), VAL(txtArg2.Text), i)
        txtResult.Text = STRF$(x, 2, 6, 4)
       CASE 5  'F
        x = fDist(VAL(txtArg1.Text), VAL(txtArg2.Text), VAL(txtArg3.Text))
        txtResult.Text = STRF$(x, 2, 6, 4)
       CASE 6  'InvF
        x = fDistInv(VAL(txtArg1.Text), VAL(txtArg2.Text), VAL(txtArg3.Text))
        txtResult.Text = STRF$(x, 2, 6, 4)
       CASE 7  'Chi
        x = Chi(VAL(txtArg1.Text), VAL(txtArg2.Text))
        txtResult.Text = STRF$(x, 2, 6, 4)
       CASE 8  'InvChi
        x = ChiInv(VAL(txtArg1.Text), VAL(txtArg2.Text))
        txtResult.Text = STRF$(x, 2, 6, 4)
       END SELECT

      CASE 2
       frmClose(frmMain)

      END SELECT

     END SUB
'--------------------------------------------------------------------------------------

     SUB rdoClick (SENDER AS QRADIOBUTTON)

      txtArg1.Text = ""
      txtArg2.Text = ""
      txtArg3.Text = ""
      txtResult.Text = ""

      SELECT CASE Sender.Tag

      CASE 1  'Z
       lbl1.CAPTION = "Z Value"
       lbl2.Visible = False
       lbl3.Visible = False
       lbl4.CAPTION = "Probability"
       txtArg2.Visible = False
       txtArg3.Visible = False
       grpTail.Visible = False
       TestType = 1

      CASE 2  'InvZ
       lbl1.CAPTION = "Probability"
       lbl2.Visible = False
       lbl3.Visible = False
       lbl4.CAPTION = "Z Value"
       txtArg2.Visible = False
       txtArg3.Visible = False
       grpTail.Visible = False
       TestType = 2

      CASE 3  'T
       lbl1.CAPTION = "T Value"
       lbl2.Visible = True
       lbl2.CAPTION = "df"
       lbl3.Visible = False
       lbl4.CAPTION = "Probability"
       txtArg2.Visible = True
       txtArg3.Visible = False
       grpTail.Visible = True
       rdo1Tail.Checked = True
       TestType = 3

      CASE 4  'InvT
       lbl1.CAPTION = "Probability"
       lbl2.Visible = True
       lbl2.CAPTION = "df"
       lbl3.Visible = False
       lbl4.CAPTION = "T Value"
       txtArg2.Visible = True
       txtArg3.Visible = False
       grpTail.Visible = True
       rdo1Tail.Checked = True
       TestType = 4

      CASE 5  'F
       lbl1.CAPTION = "F Value"
       lbl2.Visible = True
       lbl2.CAPTION = "df 1"
       lbl3.Visible = True
       lbl4.CAPTION = "Probability"
       txtArg2.Visible = True
       txtArg3.Visible = True
       grpTail.Visible = False
       TestType = 5

      CASE 6  'InvF
       lbl1.CAPTION = "Probability"
       lbl2.Visible = True
       lbl2.CAPTION = "df 1"
       lbl3.Visible = True
       lbl4.CAPTION = "F Value"
       txtArg2.Visible = True
       txtArg3.Visible = True
       grpTail.Visible = False
       TestType = 6

      CASE 7  'Chi
       lbl1.CAPTION = "Chi Value"
       lbl2.Visible = True
       lbl2.CAPTION = "df"
       lbl3.Visible = False
       lbl4.CAPTION = "Probability"
       txtArg2.Visible = True
       txtArg3.Visible = False
       grpTail.Visible = False
       TestType = 7

      CASE 8  'InvChi
       lbl1.CAPTION = "Probability"
       lbl2.Visible = True
       lbl2.CAPTION = "df"
       lbl3.Visible = False
       lbl4.CAPTION = "Chi Value"
       txtArg2.Visible = True
       txtArg3.Visible = False
       grpTail.Visible = False
       TestType = 8

      END SELECT

     END SUB
'--------------------------------------------------------------------------------------
掌柜推荐
 
 
¥289.00 ·
 
 
¥1,080.00 ·
 
 
¥1,380.00 ·
 
 
¥638.00 ·
 
 
¥1,290.00 ·
 
 
¥1,420.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2003-12-29 03:37:52