vb6 - 无法读取结果十进制结果 (Visual Basic 6.0)
问题描述
我有一个问题,如果我将 mid(z) = 0.6875 的值放入这个公式,我的程序无法读取 0.0## 结果
公式 = 2.718281828 ^ mid(z) - 2 为什么结果是 -1.12625 ?它应该是-0.0112625
不仅对于 0.6875,而且对于结果为 0.0#### 的其他数字,这意味着我的程序无法读取 0.0
请帮助我,抱歉英语不好
我使用编程语言 vb6 btw
源代码 :
Dim tengah(11) As Variant
Dim f(11) As Variant
Dim rumus As Variant
Dim x As Variant
Dim a As Variant
Dim b As Variant
Dim fc(11) As Variant
Private Sub cmdHitung_Click()
a = txtKiri.Text
b = txtKanan.Text
f(a) = 2.718281828 ^ Val(txtKiri.Text) - 2
f(b) = 2.718281828 ^ Val(txtKanan.Text) - 2
For z = 1 To cboJumlah.Text
tengah(z) = (a + b) / 2
f(tengah(z)) = 2.718281828 ^ tengah(z) - 2
fc(z) = f(tengah(z))
If f(tengah(z)) * f(a) <= 0 Then
b = a
a = tengah(z)
Else
a = b
b = tengah(z)
End If
Next z
For x = 1 To cboJumlah
txtc(x) = tengah(x)
txtfc(x) = fc(x)
txtc(x).Visible = True
txtfc(x).Visible = True
Text(x).Visible = True
Next x
Private Sub Form_Load()
For a = 1 To 10
cboJumlah.AddItem (a)
Next a
End Sub
End Sub
解决方案
有关如何格式化数字、日期等的详细说明,请参阅VBA 格式化函数。
以标准方式格式化您使用的数字的示例是:
For x = 1 To cboJumlah
txtc(x) = Format(tengah(x), "0.########")
txtfc(x) = Format(fc(x), "0.########")
txtc(x).Visible = True
txtfc(x).Visible = True
Text(x).Visible = True
Next x
如果您浏览链接页面,您会发现您甚至可以为多种情况提供自定义掩码,即一个掩码用于正面,一个用于空,一个用于负数等。
推荐阅读
- spring-boot - spring boot 不会自动装配包含事务方法的 inhert 抽象类
- arrays - 使用外部函数“交换”来执行冒泡排序的交换步骤,但在 c 中使用结构数组?
- reactjs - 如何使用 Axios 以表单的形式发布到数据库?
- selenium - Selenium IDE - 导致此错误消息的原因(“无法读取未定义的属性'trim'”)
- google-chrome-devtools - Chrome 开发者工具 - 删除网络标签中不必要的标题
- powerbi - 如何根据过滤器选择获得上一年的值?
- python - 重定向标准输入和标准输出
- android - 以编程方式圆角图像视图
- javascript - 识别和编码网址的问题
- blazor-server-side - 发现具有意外名称“EditForm”的标记元素