x = Val(Text1.Text)
If x >0 And x <= 3 Then y=12
If x >3 And x<=10 Then y = 12 + (x - 3) * 2
If x >10 Then y = 26+(x-10) * 3
If x <= 0 Then y = 0
Label1.Caption = x &"公里"
Label2.Caption = y &"元"
End Sub
界面如上图所示, 其中公式用OLE 控件绘制,将该控件绘制到窗体中,点击右键,插入对象,选择microsoft 公式3 ,即可编辑。代码如下:
Private Sub Command1_Click()
Dim x, n As Integer
Dim p, q As Single
If (Val(Text1.Text) >= 0) And (Val(Text1.Text) >= 0) Then
n = Val(Text1.Text)
x = Val(Text2.Text)
p = x / n
q = f(n) / (f(x) * f((n - x))) * p ^ x * (1 - p) ^ (n - x)
Text3.Text = q
End If
End Sub
Function f(n)
Dim i As Long
f = 1
For i = 1 To n
f = f * i
Next
End Function
如有其它需要,请继续追问~~~
在窗体上放4个textbox控件,text1输入成绩a,text2输入成绩b,text3输入成绩c,text4输出总成绩,再放一个按钮.拷贝下面的代码就可以了:
Private Sub Form_Load()
Text1 = "" '清空数据
Text2 = ""
Text3 = ""
Text4 = ""
End Sub
Private Sub Command1_Click()
dim 学时a as Integer ,学时b as Integer ,学时c as Integer ,
学时a = 30 '按实际写
学时b = 25
学时c = 20
学分 = (学时a * Val(Text1) + 学时b * Val(Text2) + 学时c * Val(Text3)) / (学时a + 学时b + 学时c)
Text4 = 学分
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)