大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
创新互联专业为企业提供城区网站建设、城区做网站、城区网站设计、城区网站制作等企业网站建设、网页设计与制作、城区企业网站模板建站服务,十载城区做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
Dim s As Double
Dim n As Integer
s = 2
For n = 1 To 10000
s = s * (2 * n) ^ 2 / (2 * n - 1) / (2 * n + 1)
Next n
MsgBox("圆周率π的值是" s)
End Sub
仅仅是普通表达式的话,定义数据类型,比如从单精度改为双精度,如果想保留小数点位数,用formatnumber来处理。如果是某个算法的精度,就要复杂一些,要定义一个误差,在算法迭代过程中,用while语句判断计算结果的残差是否小于定义的误差值,至于残差如何计算,与你的算法有关
Dim s1!, s2!, a$ '为小数点的叠加,s1,s2必须定义为单精度型
Dim flag As Boolean 'flag它是过程及的变量,在通用里必须声明
'在数字按钮控件单击数组单击事件中获取操作数(没有区分是哪一个操作数)
Private Sub Command1_Click(Index As Integer)
x = Text1.Text
If flag = True Or x = "0" Then '查看数字是否输入完毕或者是否清零了
Text1.Text = CStr(Index) 'CStr将数值转换字符
Else
Text1.Text = Text1.Text + CStr(Index) '"+"在这里这个是对字符串的操作的叠加,CStr(Index)是接的数据
End If
flag = False '时刻准备数字的输入
End Sub
'2.单击运算符,确定s1,并且要选定运算
Private Sub Command2_Click(Index As Integer)
flag = True
s1 = Val(Text1.Text)
Select Case Index
Case 0
a = "+"
Case 1
a = "-"
Case 2
a = "*"
Case 3
a = "/"
End Select
End Sub
'3."="的单击事件
Private Sub Command3_Click()
flag = True
s2 = Val(Text1.Text)
Select Case a
Case "+"
Text1.Text = s1 + s2
Case "-"
Text1.Text = s1 - s2
Case "*"
Text1.Text = s1 * s2
Case "/"
Text1.Text = s1 / s2 '分母不能为0
End Select
s1 = 0: s2 = 0: a = ""
End Sub
'4.清屏
Private Sub Command4_Click()
Text1.Text = "0"
s1 = 0
s2 = 0
a = ""
flag = False
End Sub
'5.删除最后输入的一个字符,换句话说,将本文框中的字符串取字符(从左往右取left(string,length)),将最后一个字符不取就先行
Private Sub Command5_Click()
If Text1.Text = "" Then
Else
Command5.Enabled = True
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
'len求字符串的长度,left(text1.len(text1)-1减1是取字符串从左往右减去一个字符串
End If
End Sub
'小数点 1)显示出"."(注意前面输入过的整数必须显示) 2)小数后能继续接受数字的输入
Private Sub Command6_Click()
Text1 = Text1 "."
End Sub
'7加入正负号--单击“+、-”,产生一个"-",而且处于一种等待数字输入的一种状态
Private Sub Command7_Click()
Dim temp As Double
temp = -Val(Text1.Text)
Text1.Text = temp
If d = " " Then s1 = temp Else s2 = temp
End Sub
Private Sub Command8_Click() '退出
End
End Sub
Private Sub Form_Load() '窗体初始化
Text1.Text = 0
Text1.Locked = True
End Sub