8 Replies - 3947 Views - Last Post: 07 March 2012 - 02:52 PM Rate Topic: -----

#1 RafasLad   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 10
  • Joined: 06-March 12

C# case statement and linking to other classes

Posted 07 March 2012 - 08:36 AM

Hi all, first of all thank you to everyone who helped me out last night with my problems, now I need some help again.

I have a menu and submenu system, this submenu contains information about locating a driver's location, I want to be able to do a search within the if statement to find out where said Driver is located. I've attached a link to a screenshot if that helps.

http://imageshack.us/f/14/helpub.png/

I want to be able to press the number 1 (or any other number) and for the application to say the following instead of defaulting back to the depot menu:

Please enter name of driver (in this case Steven)
Then for the application to say:

"Steven is located at Depot A"

Any ideas, tips or suggestions greatly appreciated.
I don't want the coding done for me as this is cheating, I just want a pointing in the right direction :bananaman:

Rafa

Is This A Good Question/Topic? 0
  • +

Replies To: C# case statement and linking to other classes

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: C# case statement and linking to other classes

Posted 07 March 2012 - 08:45 AM

In your Driver class, add a property for Location.

When you dispatch the driver there, set his new location.

When you want to know where he is, check it.

Driver bob = new Driver("Bob");
bob.Location = "South Wales";

Was This Post Helpful? 2
  • +
  • -

#3 RafasLad   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 10
  • Joined: 06-March 12

Re: C# case statement and linking to other classes

Posted 07 March 2012 - 11:27 AM

Hi there, thanks for your reply, tried as you suggested but no luck, put the following code in:

 public driverLocation()
        {
            Driver Kenny = new Driver ("Kenny");
            Kenny.driverLocation = "Liverpool Depot";
        }
      


Got these errors:

Method must have a return type
Driver does not contain a constructor that takes 1 arguments
Cannot assign to driverLocation because it is a method group.

Please bare in mind I'm a complete C# beginner and am slightly bedazzled by this, any help appreciated :bananaman:
Was This Post Helpful? 0
  • +
  • -

#4 superkb10   User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 298
  • Joined: 27-November 11

Re: C# case statement and linking to other classes

Posted 07 March 2012 - 11:47 AM

Okay, first off, why is the Location property a function? You could just make it a string. Also, please look up what a constructor is. The constructor is a method, it doesn't have parameteres by default, you must add parameters. As for the other error messages, a method cannot be assigned a value, something can have a something assigned the value of the function, but not the function. The way to change the value of a function is to pass parameters through it. You can find that too online.

So, to recap, make the location a string, not a method. Methods are generally only used when you must convert something, like ToString() with converts an object type to a string. Whereas, in this, unless you are planning to do something with the location, just make it a string.

If you need any help, here's a great site to find info
Was This Post Helpful? 0
  • +
  • -

#5 RafasLad   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 10
  • Joined: 06-March 12

Re: C# case statement and linking to other classes

Posted 07 March 2012 - 12:17 PM

Thanks for all your help guys but still not getting anywhere :(

Getting these errors:

Posted Image
Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: C# case statement and linking to other classes

Posted 07 March 2012 - 01:30 PM

View PostRafasLad, on 07 March 2012 - 12:27 PM, said:

Hi there, thanks for your reply, tried as you suggested but no luck, put the following code in:

 public driverLocation()
        {
            Driver Kenny = new Driver ("Kenny");
            Kenny.driverLocation = "Liverpool Depot";
        }
      


Got these errors:

Method must have a return type
Driver does not contain a constructor that takes 1 arguments
Cannot assign to driverLocation because it is a method group.

Please bare in mind I'm a complete C# beginner and am slightly bedazzled by this, any help appreciated :bananaman:


YOu make the new Driver instance called "Kenny". You assign the location. Then what?
Kenny was made inside a method. Therefore that is its scope of life. It evaporates as soon as the method completes.

At the risk of demoralizing you, I'm going to suggest you stop trying to make program from scratch and just work on learning the language and underlying concepts. You can't design and build a car if you don't know what an engine is, or a an airbag sensor, or how a transmission works. Same here. You can't design how a program should function if you don't understand scope, class creation, instances and so on.

This type of thing is covered very early on in any self-teaching book.

For now, just work on the lessons. Do a self-teaching book from cover to cover. Then consider writing a program.

I don't say this to be mean. We've seen lots of new coders take this approach and we know it doesn't work. Trying to design your own programs before you understand the basics of the code language you've chosen just leads to problems, frustrations, and 'swiss-cheese' education (lots of holes).


Resources, references and suggestions for new programmers. - Updated Jan 2012
Spoiler

Was This Post Helpful? 1
  • +
  • -

#7 RafasLad   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 10
  • Joined: 06-March 12

Re: C# case statement and linking to other classes

Posted 07 March 2012 - 02:13 PM

I understand what you are trying to say buddy and I appreciate it but our teacher has told us to go off and build this program, this is for an assignment, I'm trying my best and people on this forum just reply by being smug and 'oh well you should know this' or whatever, you all sound just like my teacher.

I never asked for assistance in the coding, I just asked if someone could point me in the right direction regarding my query (showing me how to add a search method/function to my menu option) but a lot of people just go off on a rant and tell me I'm crap.

I need :helpsmilie: or pointing in the right direction, showing me an example of how to do the search, not the coding done for me.
Was This Post Helpful? 0
  • +
  • -

#8 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: C# case statement and linking to other classes

Posted 07 March 2012 - 02:47 PM

Did we know this was homework and you had certain rules to follow? No.

Did we know when we suggested you add a .Location property to your driver class that you didn't know how to add a property? No.

Can we read the text on your reduced ImageHack image? No

So you might be a little less pissy with people that are trying to help you.

Method must have a return type
I know damn well that your teacher and your textbook have examples of how to construct a method.

accessability returntype name(parameterType parameterName)
{
}

public string FirstName(CustomerObject incomingCustomer)
{
    Return incomingCustomer.CustomerFirstName;
}




Does your method match that pattern?
1 public driverLocation()

No.

Fixing bugs like this one isn't tough, but you do have to try and you do have to pay attention to the details, and you have to accept that you need to open your text book and lecture notes and look back at the examples that you are given. Bugs like this one aren't much more than just proofreading: Look at the example method and compare it to yours. What is missing from yours that is in the example? The error even TOLD YOU: The return type. Visual Studio is telling you what is missing. It couldn't get any easier than if it filled it in for you.

Maybe you are just too burned out from staring at it. Go for a walk. Play with the dog. Take a shower. Watch 30 minutes of TV. Do something then come back to it refreshed.
Was This Post Helpful? 1
  • +
  • -

#9 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: C# case statement and linking to other classes

Posted 07 March 2012 - 02:52 PM

Please visit these links, they might help:
Homework help thread
Building an app
C# learning series


See FAQ 2 & 25 & 26. (Click the SHOW button below)


TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Form1 talk to Form2


FAQ (Frequently Asked Questions - Updated Feb 2012
Spoiler



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1