I have a bmi application that was written in Java via netbeans but now I am trying to convert the Java to C#, I have pasted a sample of my Java and under that what I have so far for my C#.

I would be grateful for some help with correcting the errors, I am a newbie to C#.

Thanks

Java

private void cmdConvertActionPerformed(java.awt.event.ActionEvent evt) {                                           
// convert button for height and weight

   // Metric Cm & Kg
   //Imperial Inches & lb's        
        double inch = 0;
        double outputInches;
        String outinch; // Variable used in - txtConvHeight.setText(outinch=bodymass.format(outputInches));
        double cm = 0;
        double outputCms = 0;
        String outcms; // Variable used in - txtConvHeight.setText(outcms=bodymass.format(outputCms));
        boolean ok;  // boolean used in - ok = false; //boolean to trigger Optpane on alpha entry
        ok = true;
        double kgs = 0;
        double lbs = 0;
        String outkgs; // variable used in - txtConvWeight.setText(outkgs=bodymass.format(outputkgs));
        String outlbs; // Variable used in -  txtConvWeight.setText (outlbs=bodymass.format(outputlbs));
        double outputkgs = 0;
        double outputlbs = 0;
        

        // if Height is blank field                          START

        String tall= txtHeight.getText(); // converts double to string
                        if  ((tall.isEmpty())) // if no entry made
                            optPane1.showMessageDialog(this,"Please enter your height ",
                                 "You did not enter your height",optPane1.ERROR_MESSAGE);

       // if height blank field                                   end




C#

private void button2_Click(object sender, EventArgs e)
        {
            // convert button for height and weight - metric and imperial

            double inch = 0;
            double outputInches;
            String outinch; // Variable used in - txtConvHeight.setText(outinch=bodymass.format(outputInches));
            double cm = 0;
            double outputCms = 0;
            String outcms; // Variable used in - txtConvHeight.setText(outcms=bodymass.format(outputCms));
            bool ok;  // boolean used in - ok = false; //boolean to trigger Optpane on alpha entry
            ok = true;
            double kgs = 0;
            double lbs = 0;
            String outkgs; // variable used in - txtConvWeight.setText(outkgs=bodymass.format(outputkgs));
            String outlbs; // Variable used in -  txtConvWeight.setText (outlbs=bodymass.format(outputlbs));
            double outputkgs = 0;
            double outputlbs = 0;

            // if Height is blank field                          START

            String tall = textBox1.GetText(); // gets entry made into textbox
            if ((tall.DefaultIfEmpty())) // if no entry made
                MessageBox.Show(this, "Please enter your height ",
                     "You did not enter your height", MessageBoxButtons.OK, MessageBoxIcon.Error);

I have the whole application to convert but getting this section working would give me some idea as to how to attack the rest of the java conversion.

Thanks again

Edited 5 Years Ago by ~s.o.s~: Added code tags, please learn to use them.

Thanks for the quick reply, I will try this and get back to let you know how I got on.

This article has been dead for over six months. Start a new discussion instead.