Page 1 of 1

Want to port my celc to fahr conv from c# to visual basic

Posted: Wed Feb 18, 2009 2:26 am
by Levio91
How do I do this? I mainly want to do this so I can figure out visual basic. (dont worry I already have the guis)

visual basic code so far

Code: Select all

Public Class Form1

    Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    End Sub

    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

    End Sub

    Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged

    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub
End Class
entire c# code

Code: Select all

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    //*********************************************************
    // Convert:: A simple conversion example
    // Levi Harman A.K.A.  (mth)
    // ********************************************************
    // Date        Comments                                pgr
    // =====       =========                               ====
    // 2/10/09     First working version with input tests  mth
    //*********************************************************
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {

                float temp_c;
                float temp_f;

                InitializeComponent();
            }

            public bool IsNumeric(string s)
            {
                try
                {
                    Double.Parse(s);
                }
                catch
                {
                    return (false);
                }

                return (true);
            }




            // f2c
            private void button1_Click(object sender, EventArgs e)
            {
                float temp_f = 0;
                float temp_c = 0;


                if (IsNumeric(textBox1.Text) == true)
                {
                    // temp convert code goes here
                    temp_f = float.Parse(textBox1.Text);

                    temp_c = (float) ((temp_f - 32) * 5 / 9.0);

                    textBox2.Text = temp_c.ToString();
               
                }
                else
                {
                    // message window code goes here
                    textBox1.Text = "need number";
                }
            }




            // c2f
            private void button2_Click(object sender, EventArgs e)
            {

                float temp_f = 0;
                float temp_c = 0;


                if (IsNumeric(textBox2.Text) == true)// validity test
                {
                    temp_c = float.Parse(textBox2.Text);
                    temp_f = (float)((temp_c / (5.0 / 9.0)) + 32);
                    textBox1.Text = Convert.ToString(temp_f);
                }
                else
                {
                    textBox2.Text = "need a number";
                }
            }

            private void textBox1_TextChanged(object sender, EventArgs e)
            {

            }

            private void Form1_Load(object sender, EventArgs e)
            {

            }
        }
    }

Re: Want to port my celc to fahr conv from c# to visual basic

Posted: Wed Feb 18, 2009 2:37 am
by MarauderIIC
You do it by rewriting everything yourself, I'm not going to do it for you (and neither will most people here). More than happy to help you with a particular problem. However, "entire code" with "how do i port this" yields "rewrite it yourself."

Re: Want to port my celc to fahr conv from c# to visual basic

Posted: Wed Feb 18, 2009 7:55 am
by programmerinprogress
Using properties on a form, and binding the properties and variables together(or rather assigning variables to certain properties of a window's controls) is pretty standard stuff you know.

Why don't you try figuring it out yourself before constantly posting "how do I do it" threads?

I would start with using a controls(prefferably a button) click event which:
- takes the values from text boxes (or another type of control)
- sticks them in variables
- does some arithmetic to work out the conversion
-dumps the answer back to a text box

That would be the way to think about how to do it, but i'm not writing any code out, it's your project...