I am having some trouble figuring out how to Validate data on my robot project so that the robot stays in the range of say 100-150. Also my Go 10 button is only going 1 space even though I have it labled as

private void Go10_Click(object sender, EventArgs e)
            {

                Robby.Move(10);
                positionLbl.Text = Robby.location.ToString();
                Robby.Draw(pnlRobot); 


            }

and my Go 1 button is labled as Robby.Move(1);

My main form code:

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;

    namespace RobotCS
    {
        public partial class Form1 : Form
        {
            private Robot Robby = new Robot();
            public Form1()
            {

                InitializeComponent();

            }

            private void Form1_Load(object sender, EventArgs e)
            {
                robotLbl.Text = Robby.ToString();
                Robby.Draw(pnlRobot);
                positionLbl.Text = Robby.location.ToString();

            }

            private void Exit_Click(object sender, EventArgs e)
            {
                Application.Exit();
            }


            private void North_Click(object sender, EventArgs e)
            {
                // set direction of the robot to north
                Robby.direction = Direction.North;
                robotLbl.Text = Robby.ToString();   
            }

            private void East_Click(object sender, EventArgs e)
            {
                Robby.direction = Direction.East;
                robotLbl.Text = Robby.ToString();   
            }

            private void South_Click(object sender, EventArgs e)
            {
                Robby.direction = Direction.South;
                robotLbl.Text = Robby.ToString();   
            }

            private void West_Click(object sender, EventArgs e)
            {
                Robby.direction = Direction.West;
                robotLbl.Text = Robby.ToString();  
            }

            private void Go1_Click(object sender, EventArgs e)
            {

                Robby.Move(1);
                positionLbl.Text = Robby.location.ToString();
                Robby.Draw(pnlRobot); 


            }


            private void Go10_Click(object sender, EventArgs e)
            {

                Robby.Move(10);
                positionLbl.Text = Robby.location.ToString();
                Robby.Draw(pnlRobot); 


            }
        }
    }




Class code: 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace RobotCS
{
    public enum Direction
    {

        North = 233,
        West = 231,
        South = 234,
        East = 232
    }
    class Robot
    {
        public Direction direction;

        public Robot() // Default constructor
        {
            location = new Point(); // Sets location.X=0 and location.Y=0          
            direction = Direction.North;
        }
    //   public Direction direction { get; set; }

        public Point location { get; set; }


        public void Move(int unitToMove)        
        {
            Point P = new Point();

            switch (direction)
            {
                case Direction.North:
                    P.X = location.X;
                    P.Y = location.Y - unitToMove;
                    break;
                case Direction.West:
                    P.X = location.X - unitToMove;
                    P.Y = location.Y;
                    break;
                case Direction.South:
                    P.X = location.X;
                    P.Y = location.Y + unitToMove;
                    break;
                case Direction.East:
                    P.X = location.X + unitToMove;
                    P.Y = location.Y;
                    break;
                default:
                    break;
            }
            location = P;
        }
        public void Draw(Panel P)
        {
            Point L = new Point(location.X + P.Width / 2, location.Y + P.Height / 2);
            P.Controls[0].Location = L;
        }

             public override string ToString()
        {

            return ((char)direction).ToString();
        }
    }
}

Any and all help would be great! =)

-Crima

Between lines 144 and 145 you should test if the robot is still in the range, if not, then don't change the location property.

And I don't see anything obviously wrong with the move code. Put a breakpoint in the Go10_Click event and see if it is making it into that code (and make sure you have the right event tied to the button).

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.