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

Hi dashby! Welcome here :)
Put all (or most?) of the var declarations outside you button2_Click method.
Lines 57 and 58 should be something like
String tall = textBox1.Text; // gets entry made into textbox
if ((tall == String.Empty)// if no entry made
Also, have a look at this snippet: http://www.daniweb.com/software-development/csharp/code/217189

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

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.