数理统计程序集
源代码在线查看: 泊松分布f1.frm
VERSION 5.00
Begin VB.Form frmOutput
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "泊松分布"
ClientHeight = 8820
ClientLeft = 60
ClientTop = 345
ClientWidth = 7350
LinkTopic = "Form1"
ScaleHeight = 8820
ScaleWidth = 7350
StartUpPosition = 3 '窗口缺省
Begin VB.VScrollBar VScroll1
Height = 8895
LargeChange = 5
Left = 6960
TabIndex = 10
Top = 0
Width = 375
End
Begin VB.OptionButton OptUF
Appearance = 0 'Flat
BackColor = &H80000005&
ForeColor = &H80000008&
Height = 255
Index = 0
Left = 6360
TabIndex = 9
Top = 480
Width = 375
End
Begin VB.OptionButton OptDF
Appearance = 0 'Flat
BackColor = &H80000005&
ForeColor = &H80000008&
Height = 255
Index = 0
Left = 4440
TabIndex = 8
Top = 480
Width = 375
End
Begin VB.CheckBox cheP
Appearance = 0 'Flat
BackColor = &H80000005&
ForeColor = &H80000008&
Height = 255
Index = 0
Left = 2640
TabIndex = 7
Top = 480
Width = 375
End
Begin VB.CommandButton cmdExit
Caption = "退 出"
Height = 375
Left = 5520
TabIndex = 6
Top = 0
Width = 1215
End
Begin VB.CommandButton cmdPrint
Caption = "打 印"
Height = 375
Left = 120
TabIndex = 5
Top = 0
Width = 1095
End
Begin VB.Line Line1
Index = 0
X1 = 0
X2 = 6960
Y1 = 720
Y2 = 720
End
Begin VB.Label lblUF
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "上侧概率"
ForeColor = &H80000008&
Height = 255
Index = 0
Left = 4800
TabIndex = 4
Top = 480
Width = 1575
End
Begin VB.Label lblDF
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "下侧概率"
ForeColor = &H80000008&
Height = 255
Index = 0
Left = 3120
TabIndex = 3
Top = 480
Width = 1215
End
Begin VB.Label lblP
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "事件概率"
ForeColor = &H80000008&
Height = 255
Index = 0
Left = 1320
TabIndex = 2
Top = 480
Width = 1215
End
Begin VB.Label lblNo
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "次数"
ForeColor = &H80000008&
Height = 255
Index = 0
Left = 240
TabIndex = 1
Top = 480
Width = 855
End
Begin VB.Label lblTitle
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "计算结果"
BeginProperty Font
Name = "隶书"
Size = 21.75
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 495
Left = 2400
TabIndex = 0
Top = 0
Width = 1935
End
End
Attribute VB_Name = "frmOutput"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'泊松分布
Option Explicit
Dim Hig As Single, s1 As Single, s2 As Single, s3 As Single
Dim I As Integer, Pa As Single
Private Sub Form_Load()
On Error Resume Next
Me.Top = 300
With VScroll1
.Min = 0
.Max = 1000
.SmallChange = 1
.LargeChange = 1
End With
Hig = lblNo(0).Height
cheP(0).Visible = False: OptDF(0).Visible = False
OptUF(0).Visible = False
'形成显示计算结果的标签数组
For I = 1 To x + 2
's1:概率,s2:下侧概率,s3:上侧概率
s1 = A(1, I - 1): s2 = A(2, I - 1): s3 = A(3, I - 1)
'加载控件数组
Load lblNo(I): Load lblP(I)
Load lblDF(I): Load lblUF(I)
Load cheP(I): Load OptDF(I): Load OptUF(I)
'控件数组移位
lblNo(I).Move lblNo(0).Left, lblNo(0).Top + I * Hig
lblP(I).Move lblP(0).Left, lblP(0).Top + I * Hig
lblDF(I).Move lblDF(0).Left, lblDF(0).Top + I * Hig
lblUF(I).Move lblUF(0).Left, lblUF(0).Top + I * Hig
cheP(I).Move cheP(0).Left, cheP(0).Top + I * Hig
OptDF(I).Move OptDF(0).Left, OptDF(0).Top + I * Hig
OptUF(I).Move OptUF(0).Left, OptUF(0).Top + I * Hig
'使控件数组可视
lblNo(I).Visible = True: lblP(I).Visible = True
lblDF(I).Visible = True: lblUF(I).Visible = True
If I cheP(I).Visible = True: OptDF(I).Visible = True
OptUF(I).Visible = True
End If
'为控件数组填充显示内容
If I < x + 2 Then lblNo(I).Caption = I - 1 Else lblNo(I).Caption = "答案"
If I < x + 2 Then lblP(I).Caption = s1 Else lblP(I).Caption = ""
If I < x + 2 Then lblDF(I).Caption = s2 Else lblDF(I).Caption = ""
If I < x + 2 Then lblUF(I).Caption = s3 Else lblUF(I).Caption = ""
Next I
End Sub
'单击单选按钮取得相应的下侧概率值
Private Sub OptDF_Click(Index As Integer)
If OptDF(Index).Value = True Then
lblDF(x + 2).Caption = lblDF(Index).Caption
Else
lblDF(x + 2).Caption = ""
End If
End Sub
'单击单选按钮取得相应的上侧概率值
Private Sub OptUF_Click(Index As Integer)
If OptUF(Index).Value = True Then
lblUF(x + 2).Caption = lblUF(Index).Caption
Else
lblUF(x + 2).Caption = ""
End If
End Sub
'由滚动条事件改变显示区域
Private Sub VScroll1_Change()
Dim v As Integer
On Error Resume Next
v = VScroll1.Value
For I = 1 To x + 2 - v
lblNo(I + v).Move lblNo(0).Left, lblNo(0).Top + I * Hig
lblP(I + v).Move lblP(0).Left, lblP(0).Top + I * Hig
lblDF(I + v).Move lblDF(0).Left, lblDF(0).Top + I * Hig
lblUF(I + v).Move lblUF(0).Left, lblUF(0).Top + I * Hig
cheP(I + v).Move cheP(0).Left, cheP(0).Top + I * Hig
OptDF(I + v).Move OptDF(0).Left, OptDF(0).Top + I * Hig
OptUF(I + v).Move OptUF(0).Left, OptUF(0).Top + I * Hig
Next I
End Sub
'单击复选框事件,计算概率和
Private Sub cheP_Click(Index As Integer)
If cheP(Index).Value = 1 Then Pa = Pa + Val(lblP(Index)) Else _
Pa = Pa - Val(lblP(Index))
lblP(x + 2).Caption = Str(Pa) '在“答案”标签显示计算结果
End Sub
'打印
Private Sub cmdPrint_Click()
Dim I As Integer
Printer.CurrentX = lblTitle.Left: Printer.CurrentY = lblTitle.Top
Printer.FontName = lblTitle.FontName: Printer.FontSize = lblTitle.FontSize
Printer.Print lblTitle.Caption '打印标题
Printer.FontName = lblNo(0).FontName: Printer.FontSize = lblNo(0).FontSize
For I = 0 To x + 2
Printer.CurrentX = lblNo(I).Left: Printer.CurrentY = lblNo(I).Top
Printer.Print lblNo(I).Caption '打印事件数
Printer.CurrentX = lblP(I).Left: Printer.CurrentY = lblP(I).Top
Printer.Print lblP(I).Caption '打印事件概率
Printer.CurrentX = lblDF(I).Left: Printer.CurrentY = lblDF(I).Top
Printer.Print lblDF(I).Caption '打印下侧概率
Printer.CurrentX = lblUF(I).Left: Printer.CurrentY = lblUF(I).Top
Printer.Print lblUF(I).Caption '打印上侧概率
Next I
End Sub
'退出
Private Sub cmdExit_Click()
Unload Me
End
End Sub