5 Replies - 328 Views - Last Post: 02 December 2013 - 07:53 PM Rate Topic: -----

#1 jeremyjones123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 11-October 13

Need to convert input into words

Posted 02 December 2013 - 11:21 AM

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Employee name = new Employee();
            Employee number = new Employee();
            Employee shift = new Employee();
            Employee pay = new Employee();

            name.name = textBox1.Text;
            number.name = textBox2.Text;
            shift.name = textBox3.Text;
            pay.name = textBox4.Text;

            MessageBox.Show("Your name is " + name.name + ". \nYour Employee number is " 
            + number.name + ". \nThe shift you work is " + shift.name + " \nYour hourly pay rate is " 
            + pay.name + ".");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            textBox2.Clear();

        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        class Employee
        {
            public string name, number;

            public Employee()
            {
                name = "";
            }

            public string Name
            {
                get
                {
                    return name;
                }
            }

            public string Number
            {
                get
                {
                    return name;
                }
            }

            class ProductionWorker
            {
                public string shift_number, pay_rate;
                public int one, two;

                public ProductionWorker()
                {
                    shift_number = "";
                    pay_rate = "";
                }

                public string Shift_number
                {
                    set
                    {
                        
                    }

                    get
                    {
                        return shift_number;
                    }

                }

                public string Pay_rate
                {
                    get
                    {
                        return pay_rate;
                    }
                }
                
            }

        }

        
    }
}


Hey fellas, what i'm trying to do is under public sting Shift_number im trying to set it to where the user inputs either one or two within the textbox and have it converted so that it displays within the textbox as either day or night. Day = 1 and Night = 2

Any help is greatly appreciated !!

Is This A Good Question/Topic? 0
  • +

Replies To: Need to convert input into words

#2 astonecipher  Icon User is offline

  • D.I.C.
  • member icon

Reputation: 795
  • View blog
  • Posts: 3,477
  • Joined: 03-December 12

Re: Need to convert input into words

Posted 02 December 2013 - 11:30 AM

Would it not be better to use a combo box with 1 and 2 as the values to limit what is acceptable?

You can still do the checking in an

If ==1
 'day shift
If else == 2
 'night shift
Else
 'throw invalid

This post has been edited by astonecipher: 02 December 2013 - 11:30 AM

Was This Post Helpful? 1
  • +
  • -

#3 jeremyjones123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 11-October 13

Re: Need to convert input into words

Posted 02 December 2013 - 11:36 AM

Actually yeah that would be much easier hahaha thanks for the quick response!

+rep
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,466
  • Joined: 05-May 12

Re: Need to convert input into words

Posted 02 December 2013 - 01:11 PM

And better yet, instead of shift numbers, use enums:
enum Shift
{
    Day = 1,
    Night = 2,
}


Was This Post Helpful? 1
  • +
  • -

#5 Robin19  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 272
  • View blog
  • Posts: 552
  • Joined: 07-July 10

Re: Need to convert input into words

Posted 02 December 2013 - 03:19 PM

You can expand upon Skydriver's idea and use casting with your combo box to create a property.
public enum Shift
{
   Day = 0,
   Night = 2
}

public partial class MainForm : Form
{
   public SelectedShift
   {
      get
      {
         if (shiftComboBox.SelectedIndex == -1)
            return Shift.Day
         return (Shift)shiftComboBox.SelectedIndex;
      }
      set { shiftComboBox.SelectedIndex = (int)value; }
   }

   public MainForm()
   {
      Initialize();
      SelectedShift = Shift.Day;
   }
}

Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5675
  • View blog
  • Posts: 12,192
  • Joined: 02-June 10

Re: Need to convert input into words

Posted 02 December 2013 - 07:53 PM

Lines 10-13... Whiskey Tango Foxtrot?!?!?!

It looks like you have no idea about the objects you're making.
You made four completely independent instances of the Employee() class. You made 4 employees and refer to the 4 employes as 'Name' 'Number' 'Shift' and 'Pay. Don't you really want one employee and to fill in these 4 properties on the same employee?

Please go work this tutorial on classed before you go any further.
http://www.dreaminco...lasses-objects/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1