Jump to content

Project help

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
unleashed-my-freedom

unleashed-my-freedom

    Newbie

  • Members
  • Pip
  • 8 posts
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 
            MsgBox(m)

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

        End If
        cmtextbox.Text = Convert.ToString(m)

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

        Else
            MessageBox.Show("Please enter a number.")
        End If
        gtextbox.Text = Convert.ToString(kg)

        '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

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

    End Sub
End Class

Can someone help me with it? I need to help in before 26/1/2010.

I need to convert from cm to m and g to kg.

I need to use If...Else...Then statements, Select case statements, For...Next statements, Do & While loop, error handling, function without passing argument, function with passing argument.

Thanks in advance.

Edited by WingedPanther, 23 January 2010 - 05:34 PM.
add code tags (the # button)


#2
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,248 posts
Well first can you use code tags?

Do you have the conversion working? What problems are you having?

I don't see a need to use do & while loops for this.

Well as for the error checking to check if the user has entered a number or not... does VB have try catch exceptions?

If yes you can do something like this:

try {
    // enter number
} catch (Exception ex) {
    // user has entered something other than an integer
}

If not, I don't know how to do error checking then.

#3
unleashed-my-freedom

unleashed-my-freedom

    Newbie

  • Members
  • Pip
  • 8 posts
The conversion working, I came up with myself. My programme cannot run with those coding. I think there are mistakes with those coding.

#4
so1i

so1i

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 312 posts

unleashed-my-freedom said:

The conversion working, I came up with myself. My programme cannot run with those coding. I think there are mistakes with those coding.

He's written in in C#, rather than VB. As they are both similar languages, it's very similar in VB, you just take away the curly brackets :P

#5
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,248 posts
Look at this: Exception Handling in VB.NET

#6
Ray Tawil

Ray Tawil

    Programmer

  • Members
  • PipPipPipPip
  • 108 posts
Here check the solution i did it for you.

Attached Files


Share your Knowledge, It's one way to achieve immortality.
Video Tutorial Channel