This code doesn't do anything:
Code: Select all
if(locationofplant = a1)
{
croplocations.a1
}
if(locationofplant = a2)
{
croplocations.a2
}
(ignore this paragraph now)You can't call methods dynamically without using reflection, which is something you definitely should not use here. Outside of reflection, all method calls are static, or the proper term is "early-binding". You cannot take input and make it dynamically call a method at runtime ("late-binding"), because method calls are resolved at compile-time (again, outside of reflection).
You need one method that can take any of the cell numbers and any of the values that need to be stored in those cell values. That is the way this problem needs to be solved
EDIT: Oops! I see what you were trying to do, which was take the value input and call a method based on that value. I am tired and for some reason I thought you meant dynamically calling methods at runtime.
Still though, this problem needs to be solved with 1 method. If you do it like this, with all of the IF statements and separate methods, you are creating massive amounts of duplicate code which will be extremely difficult to maintain. Not duplicating code is a prime tenant of programming, called DRY ("Don't Repeat Yourself").
Your cells need to be stored in an array or other collection, not as separate properties or class fields, so that you can programmatically access them. Change the cells to an array stored within the CropLocations class. Then you will be able to make 1 method that can set anything you need for all of the cells!