Visual Basic计算难度

时间:2017-05-18 20:09:27

标签: vb.net

只是有一个visual basic的问题。我试图制作一个简单的转换程序,但程序一直给我错误的答案。我也用Java编写了这个代码,它给了我我期待的答案。我不知道这里发生了什么。这是代码示例。我输入的数字是10个外星人转换,440个是alienYearLength,25.5是alienDayLength。它应该出现在大约12个东西但我一直得到218.something 谢谢

Dim alienYears As Decimal = CDec(txtYearsToConvert.Text)
        Dim alienYearLength As Decimal = CDec(txtDaysOnAlienPlanet.Text)
        Dim alienDayLength As Decimal = CDec(txtDaysOnAlienPlanet.Text)
        Dim alienHoursYears As Decimal = ((alienYears * alienYearLength) * alienDayLength)
        Dim earthHourYears As Decimal = (8851.25)
        Dim earthConversion As Decimal = (alienHoursYears / earthHourYears)
        txtAgeOnEarth.Text = CStr(earthConversion)

1 个答案:

答案 0 :(得分:1)

这里看起来像拼写错误(vvvv),你的意思是txtYears(某事)?使用同一文本框中的输入无法实现这一点。

    Dim alienYears As Decimal = CDec(txtYearsToConvert.Text)
'                                            VVVV
    Dim alienYearLength As Decimal = CDec(txtDaysOnAlienPlanet.Text)
    Dim alienDayLength As Decimal = CDec(txtDaysOnAlienPlanet.Text)
    Dim alienHoursYears As Decimal = ((alienYears * alienYearLength) * alienDayLength)
    Dim earthHourYears As Decimal = (8851.25)
    Dim earthConversion As Decimal = (alienHoursYears / earthHourYears)
    txtAgeOnEarth.Text = CStr(earthConversion)