Quick One

vb6 Ireland
  • 12 years ago

    Hello,

    I know it's prob very easy to those in the know, but i'm learning on my own!

    What is the quickest way to convert miles into kilometers and visa versa.

    I have 2labels and 2 txt boxes with a convert cmdbtn.

    thanks

    Ploneill

  • 12 years ago

    Hi,

    Check this:

    'CHECK IF TEXT ENTERED AS KILOMETERS IS NUMERIC AND EMPTY THE MILES TEXT BOX

    Private Sub txtKm_LostFocus()

    If Me.txtKm <> "" Then
        If IsNumeric(Me.txtKm) Then
            Me.txtMile = ""
        Else
            Me.txtKm.SetFocus
            MsgBox "Please enter a valid numeric value"
        End If
    End If








    End Sub

    'CHECK IF TEXT ENTERED AS MILES IS NUMERIC AND EMPTY THE KILOMETERS TEXT BOX
    Private Sub txtMile_LostFocus()


    If Me.txtMile <> "" Then
        If IsNumeric(Me.txtMile) Then
            Me.txtKm = ""
        Else
            Me.txtMile.SetFocus
            MsgBox "Please enter a valid numeric value"
        End If
    End If








    End Sub

    'CONVERT THE NON EMPTY TEXT BOX

    Private Sub cmdConv_Click()

    If Me.txtKm <> "" Then
        Me.txtMile = Me.txtKm / 1.60934
        Exit Sub
    End If




    If Me.txtMile <> "" Then
        Me.txtKm = Me.txtMile * 1.60934
        Exit Sub
    End If
    End Sub





    Hope this works for you.

  • 12 years ago

    Tanks Kassem! Worked like charm.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter” - Eric Raymond