请VB高手来,为什么百分比计算老出错

我是VB新手 制了一个百分比计算器 可是输入数据相差大一点就计算出错,请高手帮我看一下,最好帮我改改语句,我设计的是上面3个框输入数字计算结果在下面三个框中显示。
Private Sub Command1_Click()
Dim a As Double
Dim b As Double
Dim c As Double
Let a=Val (Text1.Text)
Let b=Val (Text2.Text)
Let c=Val (Text3.Text)
Text4.Text=a/(a+b+c)
Text5.Text=b/(a+b+c)
Text6.Text=c/(a+b+c)

有可能是你将数据定义为double求解容易产生溢出错误导致结果错误。改为float即可。即
Private Sub Command1_Click()
Dim a As float
Dim b As float
Dim c As float
Let a=Val (Text1.Text)
Let b=Val (Text2.Text)
Let c=Val (Text3.Text)
Text4.Text=a/(a+b+c)
Text5.Text=b/(a+b+c)
Text6.Text=c/(a+b+c)
温馨提示:内容为网友见解,仅供参考
第1个回答  2010-07-24
改为如下代码:
Private Sub Command1_Click()
Dim a As Double
Dim b As Double
Dim c As Double
Let a = Val(Text1.Text)
Let b = Val(Text2.Text)
Let c = Val(Text3.Text)
Text4.Text = (Int(10000 * a / (a + b + c)) / 100) & "%"
Text5.Text = (Int(10000 * b / (a + b + c)) / 100) & "%"
Text6.Text = (Int(10000 * c / (a + b + c)) / 100) & "%"
If Len(Text4.Text) < 5 Then Text4.Text = "0" & Text4.Text
If Len(Text5.Text) < 5 Then Text5.Text = "0" & Text5.Text
If Len(Text6.Text) < 5 Then Text6.Text = "0" & Text6.Text
End Sub本回答被提问者采纳
第2个回答  2010-07-24
Private Sub Command1_Click()
Dim a As Double
Dim b As Double
Dim c As Double
Let a = Val(Text1.Text)
Let b = Val(Text2.Text)
Let c = Val(Text3.Text)
If a + b + c <> 0 Then
Text4.Text = a / (a + b + c)
Text5.Text = b / (a + b + c)
Text6.Text = c / (a + b + c)
End If
End Sub
第3个回答  2010-07-24
一楼瞎扯个鸟蛋!
VS里才float呢!double都没事,float就out了?
2楼正解

请VB高手来,为什么百分比计算老出错
有可能是你将数据定义为double求解容易产生溢出错误导致结果错误。改为float即可。即 Private Sub Command1_Click()Dim a As float Dim b As float Dim c As float Let a=Val (Text1.Text)Let b=Val (Text2.Text)Let c=Val (Text3.Text)Text4.Text=a\/(a+b+c)Text5.Text=b\/(a+b+c...

VB 百分比自动计算判读问题
abs()是计算绝对值,这样的话计算结果就肯定是正数,不可能出现-60%、-30%这样的值,所以 Private Sub Command3_Click()If Trim(Text7) = "" Or Trim(Text8) = "" Then MsgBox "数字不能为空!"Else ssrz = Val(Text8) lsrz = Val(Text7) If lsrz = 0 Then MsgBo...

VB百分比问题
Private Sub ChuanSong()Dim a, b As String a = Text3.Text b = "10"If Check8.Value = 1 Then Text3.Text = str(Val(a) \/ Val(b) + Val(a))Else Text3.Text = a End If FMain1.Text4(0).Text = str(i)FMain1.Text4(1).Text = Me.Text3.Text Call FMain1.HuiChe...

VB.net 计算比率
你既然固定了新加入的占2%,那么原来的10个人又是均等的,当然剩下的98%每个人有9.8%。

VB 计算百分比
--举个例子 表code 字段bproperty declare @a float declare @b float set @a = (select count(*) from code where bproperty = 0)set @b = (select count(*) from code)select cast((@a \/ @b * 100) as varchar) + '%'

excel一个单元格中实现百分比自动计算
只能VBA了 你点录制宏,设置一个快捷键,比如ctrl+K,然后点结束 alt+F11,左边在模块中,在快捷键后插入 Dim i As Integer i = ActiveCell.FormulaR1C1 ActiveCell.FormulaR1C1 = i * 0.2 以后你鼠标选中需要变化的单元格,按ctrl+K,就可以对这个单元格*0.2了 ...

求一个vb代码,我说明下: 随机输入0到9 这10个数字 计算出现的概率
)Dim i%, a, b%, c%(9) a = Split(Text2, vbCrLf) b = UBound(a) For i = 0 To b - 1 c(a(i)) = c(a(i)) + 1 Next For i = 0 To 9 Print i; "占百分比:"; Format(c(i) \/ b, "00%") NextEnd Sub ...

vb net 计算百分比代码怎么写
代码:a=Convert.toDouble(textbox1.Text)*6\/100,先转换字符串格式为双精度型,再和数字相乘获得结果,但结果是双精度型,你若要显示出来必须转换成字符串,比如textbox2.Text=a.toString(),希望对你有帮助

用vb编写个小程序 计算百分比 输入总数 输出三个值 a b c a=10% b...
Private Sub Command1_Click()Dim s As Double s = Val(Trim(InputBox("请输入总数", "提示!")))MsgBox "a=" & CStr(s * 0.1) & " b=" & CStr(s * 0.3) & " c=" & CStr(s * 0.6)End Sub

VB下载百分比和进度条问题
Label1.Caption = (Loc(1) * 100 \/ lDatalen) & "%" '计算已下载百分比,这里没有保留小数 Pictrue1.width= 2000 * (Loc(1) \/ lDatalen) '设置图片宽度,用总长度乘以完成百分比 If Loc(1) >= lDatalen Then bDone = True Loop Close #1 MsgBox "下载完成", vbInformation, "通...

相似回答
大家正在搜