Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' declare constants and variables
        Dim cm As Integer
        Dim m As Double
        Dim g As Integer
        Dim kg As Double
        mtextbox.Text = ""
        kgtextbox.Text = ""

        ' converting from cm to m
        Integer.TryParse(cmTextBox.Text, cm)
        m = cm / 100

        ' converting from g to kg
        Integer.TryParse(gtextbox.Text, g)
        kg = g / 1000


        ' display the converted result (cm to m)
        If user enter integer then 
            display = "m"

        Else
            MessageBox.Show("Please enter a number.")

        End If

        ' display the converted result (g to kg)
        If user enter integer then
            display = "kg"

        Else
            MessageBox.Show("Please enter a number.")

            'set focus
            mtextbox.Focus()
            kgtextbox.Focus()

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        cmtextbox.Text = ""
        gtextbox.Text = ""
    End Sub
End Class

My project topic is on data conversion for length and weight. There is something wrong with the code. Can anybody help me. Thanks in advance. I need to hand in on 22/1/10. Please reply asap.

If user enter integer then
display = "m"


.

Your first problem is here. Don't put your variable in quotes, or you'll just display the "m". Try this to get started:

Dim cm As Integer
        Dim m As Double

        Integer.TryParse(TextBox1.Text, cm)
        m = cm / 100
        MsgBox(m)'This will display the value in your variable, not the "m."

Also, Integer.TryParse is only going to return a zero if the user does not enter an integer. Look at using integer.parse in a Try / Catch block to trap an invalid entry.

Dim cm As Integer       
 Dim m As Double         
Integer.TryParse(TextBox1.Text, cm)        
m = cm / 100        
MsgBox(m)'This will display the value in your variable, not the "m."

You mean I have to follow this?

Dim cm As Integer
Dim m As Double
Integer.TryParse(TextBox1.Text, cm)
m = cm / 100
MsgBox(m)'This will display the value in your variable, not the "m."

You mean I have to follow this?

I'm not sure what the question is now.

If you are brand new at this, my recommendation is to start very simple. Create a form with just a textbox and a button. Put the code above into the click event of the button. Run the program, enter a value, and see what happens.

In your original code, it looks like you are not even sure how to start, so you need to start simple. This code:

If user enter integer then display = "m"

Is not real code, it is more like "here is what I want to do", so please start simple, and people here will help you build on that.

Good Luck!

im not 100% on what you are trying. here is what you should do if you want an application to convert cm to m and g to kg.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
      
        '

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
dim number, convertednumber as integer
try
number=textbox1.text
catch
msgbox("please enter a valid number")
end try
      
convertednumber=number/100
textbox1.text=convertednumber.tostring
    End Sub
End Class

To:wiss.dev
You mean I have to follow your code?

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.