首页 > 解决方案 > 无法读取结果十进制结果 (Visual Basic 6.0)

问题描述

我有一个问题,如果我将 mid(z) = 0.6875 的值放入这个公式,我的程序无法读取 0.0## 结果

公式 = 2.718281828 ^ mid(z) - 2 为什么结果是 -1.12625 ?它应该是-0.0112625

第 3 列第 4 和第 5 列的问题

源代码 1 源代码 2

不仅对于 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

问题

标签: vb6

解决方案


有关如何格式化数字、日期等的详细说明,请参阅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

如果您浏览链接页面,您会发现您甚至可以为多种情况提供自定义掩码,即一个掩码用于正面,一个用于空,一个用于负数等。


推荐阅读