Array help needed for unit conversion application

Posted by Manolis on Stack Overflow See other posts from Stack Overflow or by Manolis
Published on 2010-06-07T11:59:22Z Indexed on 2010/06/07 12:42 UTC
Read the original article Hit count: 404

Filed under:

I have a project to do in Visual Basic. My problem is that the outcome is always wrong (ex. instead of 2011 it gives 2000). And i cannot set as Desired unit the Inch(1) or feet(3), it gives the Infinity error. And if i put as Original and Desired unit the inch(1), the outcome is "Not a Number".

Here's the code i made so far. The project is about arrays. Any help appreciated.

Public Class 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

End Class

© Stack Overflow or respective owner

Related posts about vb