我有一個在Visual Basic中執行的項目。 我的問題是,結果總是錯誤的(例如,而不是2011年它給出2000)。而且我不能將Inch(1)或feet(3)設置爲期望單位,它會給出Infinity錯誤。如果我把原始單位和期望單位放在英寸(1)中,結果是「不是數字」。單位轉換應用程序需要的數組幫助
這是我迄今爲止所做的代碼。該項目是關於數組。任何幫助讚賞。
公共類Form1中
Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click Dim original(9) As Long Dim desired(9) As Long Dim a As Integer Dim o As Integer Dim d As Integer Dim inch As Long, fathom As Long, furlong As Long, kilometer As Long Dim meter As Long, miles As Long, rod As Long, yard As Long, feet As Long a = Val(Input3.Text) o = Val(Input1.Text) d = Val(Input2.Text) inch& = 0.0833 rod& = 16.5 yard& = 3 furlong& = 660 meter& = 3.28155 kilometer& = 3281.5 fathom& = 6 miles& = 5280 original(1) = inch original(2) = fathom original(3) = feet original(4) = furlong original(5) = kilometer original(6) = meter original(7) = miles original(8) = rod original(9) = yard desired(1) = inch desired(2) = fathom desired(3) = feet desired(4) = furlong desired(5) = kilometer desired(6) = meter desired(7) = miles desired(8) = rod desired(9) = yard If o < 1 Or o > 9 Or d < 1 Or d > 9 Then MessageBox.Show("Units must range from 1-9.", "Error", _ MessageBoxButtons.OK, _ MessageBoxIcon.Information) Return End If Output.Text = (a * original(o))/desired(d) End Sub
末級
你也可以只使用原始數組。所需的數組不需要。 例如: Output.Text = CStr((a * original(o))/ original(d)) – 2010-06-07 12:44:59