Vba 我有一个vb程序,但它给了我错误的结果?
正如我在上面展示的代码,我试图让我的程序确定在哪一年人口从2008年的60亿减少到或少于600万(假设人口每40年翻一番)。然而,当我运行程序时,它不会显示1608年的结果。Vba 我有一个vb程序,但它给了我错误的结果?,vba,vb6,Vba,Vb6,正如我在上面展示的代码,我试图让我的程序确定在哪一年人口从2008年的60亿减少到或少于600万(假设人口每40年翻一番)。然而,当我运行程序时,它不会显示1608年的结果。 如果有人能帮我修改代码,那将非常有帮助!非常感谢。在VBA中,以下代码将按预期工作: Dim n As Integer = 1, year As Integer Do Until 6000000000 / (2 * n) = 6000000 year = 2008 - 40 * n
如果有人能帮我修改代码,那将非常有帮助!非常感谢。在VBA中,以下代码将按预期工作:
Dim n As Integer = 1, year As Integer
Do Until 6000000000 / (2 * n) = 6000000
year = 2008 - 40 * n
n = n + 1
Loop
txtResult.Text = "The world population would have been less than 6 million in the year " & year
Sub-qtest()
Dim n为整数,年份为整数
暗淡的人口是双重的
n=1
年份=2008年
人口=600000000#
你认为这是一个家庭作业问题吗?请重新阅读你的课本中有关浮点运算的部分。非常感谢你,兄弟,这对你很有帮助:祝你度过愉快的一天!
Sub qtest()
Dim n As Integer, year As Integer
Dim Population As Double
n = 1
year = 2008
Population = 6000000000#
Do Until Population <= 6000000
Population = Population / 2
year = year - 40
n = n + 1 'you don't need it but I left it here
Loop
MsgBox "The world population would have been less than 6 million in the year " & year
End Sub