Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi folks, still learning here so please bear with me!

I am trying to pass a parameter to my method, but keep getting an complier error

Error1 - The name 'vehicleMake' does not exist in the current context

Code below, any help much appreciated, please simplify your answers as I’m still new to this, thanks.

C#
public void RegReturn()
{

    string regNo;
    regNo = txtReg.Text;

    GetVehicleData RegSearch = new GetVehicleData();

    {
        RegSearch.GetTyreSize(regNo);
        TextBox1.Text = vehicleMake;

    }
}


public string GetTyreSize(string regNo)
{
    var service = new TyrescannerWebApp.com.carwebuk.www1.CarweBVRRWebService();
    var vehicleData = service.strB2BGetVehicleByVRM("regNo, "0.31.test");
    var vehicleMake = vehicleData.SelectSingleNode("//Vehicle/Combined_Make").InnerText;

    return vehicleMake;

}
Posted

read Scope [^] of variable to undestand why you can't access varible inside your method from calling method. since you have return value, you can use that as below.
C#
string vehicleMake = RegSearch.GetTyreSize(regNo);
//use the return value from your method 
TextBox1.Text = vehicleMake;
 
Share this answer
 
v2
Its obvious to get this error as you are using it going beyond its scope. You can use it inside GetTyreSize Method only.

Simply make it Global(not always a good approach) or return it (good approach) like:

C#
TextBox1.Text = RegSearch.GetTyreSize(regNo);


Hope it helps :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900