Hey i am very new to vb.net and am creating a simple unit converter, i want my unit converter to display results in a listbox and want the user to be able to specify the start, step and end value in a For Next loop. Here is the code i have so far:

Public Class Form3


    Private Sub lst1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstdata.SelectedIndexChanged
        Dim Conversion As String
        Conversion = lstdata.Items(lstdata.SelectedIndex)

        Dim Math As Double
        Dim number As Double
        Dim start As Double
        Dim increment As Double
        Dim finish As Double


        Select Case Conversion
            Case "Grams to Ounces"
                number = txt1.Text
                Math = number * 0.0352739619
            Case "Kilograms to Stones"
                number = txt1.Text
                Math = number * 0.157473044
            Case "°Celsius to °Fahrenheit"
                number = txt1.Text
                Math = (number * 9 / 5) + 32
            Case "Litres to Gallons"
                number = txt1.Text
                Math = number * 0.264172052
            Case "Ounces to Grams"
                number = txt1.Text
                Math = number / 0.0352739619
            Case "Stones to Kilograms"
                number = txt1.Text
                Math = number / 0.157473044
            Case "°Fahrenheit to °Celsius"
                number = txt1.Text
                Math = (number - 32) * 5 / 9
            Case "Gallons to Litres"
                number = txt1.Text
                Math = number / 0.264172052
        End Select

        start = txt2.Text
        increment = txt3.Text
        finish = txt4.Text
        For Math = start To finish Step increment
            lstoutput.Items.Add(Math)
        Next

    End Sub

I can't seem to get the list results to reflect the value math, please what am i doing wrong?? Any help would be very much appreciated. Cheers

First of all you can't just do

number = txt1.Text

Because txt1.Text is a string. You have to convert it to a floating point value as follows

number = CDbl(txt1.Text)

Same thing applies to txt2.Text, txt3.Text and txt4.Text except you use CInt and make start, increment and finish Integers

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.