8 Replies - 4046 Views - Last Post: 14 August 2007 - 05:55 PM Rate Topic: -----

#1 pete.self  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 14-August 07

ToUpper problem

Post icon  Posted 14 August 2007 - 04:36 AM

ok I am trying to store the postcode and other things all in upper case using the ToUpper method, I think I need to reword it something along the lines of postcode =oldpostcode.ToUpper(); please could someone give me some direction here.
sio you know CapatalizeFirstLettersOfAllWordsInSentence is a method I call from another file.

Pete
if i have not done enough myself first I am sorry now.

public class Address
{
	public Address(string fax, string telephone, string postcode, int countyRef, string town, string area, string street, string houseNameNumber)
	{
		Fax = fax;
		Telephone = telephone;
		Postcode = postcode;
		CountyRef = countyRef;
		Town = town;
		Area = area;
		Street = street;
		HouseNameNumber = houseNameNumber;
	}

	public string Fax
	{
		get { return fax; }
		set { fax = value; }
	}
	
	public string Telephone
	{
		get { return telephone; }
		set { telephone = value; }
	}
	
	public string Postcode
	{
		get { return postcode; }
		set
		{
			if (value != null)
			{
				postcode = postcode.ToUpper();
			}
			else
			{
				postcode = "";
			}
		}
	}
	
	public int CountyRef
	{
		get { return countyRef; }
		set { countyRef = value; }
	}

	public string Town
	{
		get { return town; }
		set 
		{
			if (value != null)
			{
				town = TextHelper.CapatalizeFirstLettersOfAllWordsInSentence(value);
			}
			else
			{
				town = "";
			}
		}
	}

	public string Area
	{
		get { return area; }
		set
		{
			if (value != null)
			{
				area = TextHelper.CapatalizeFirstLettersOfAllWordsInSentence(value);
			}
			else
			{
				area = "";
			}
		}
	}

	public string Street
	{
		get { return street; }
		set
		{
			if (value != null)
			{
				street = TextHelper.CapatalizeFirstLettersOfAllWordsInSentence(value);
			}
			else
			{
				street = "";
			}
		}
	}
	
	public string HouseNameNumber
	{
		get { return houseNameNumber; }
		set 
		{
			if (value != null)
			{
				houseNameNumber = TextHelper.CapatalizeFirstLettersOfAllWordsInSentence(value);
			}
			else
			{
				houseNameNumber = "";
			}
		}
	}

	private string houseNameNumber;
	private string street;
	private string area;
	private string town;
	private int countyRef;
	private string postcode;
	private string telephone;
	private string fax;
}

public class County
{
	public County(string name, int countyRef)
	{
		this.name = name;
		this.countyRef = countyRef;
	}

	public string Name
	{
		get { return this.name; }
	}

	public int CountyRef
	{
		get { return this.countyRef; }
	}

	private int countyRef;
	private string name;
}



Is This A Good Question/Topic? 0
  • +

Replies To: ToUpper problem

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: ToUpper problem

Posted 14 August 2007 - 04:45 AM

So the .ToUpper isnt working, is that what you're saying? If its not working what kind of output are you getting, is it throwing any errors?

This post has been edited by PsychoCoder: 14 August 2007 - 04:46 AM

Was This Post Helpful? 0
  • +
  • -

#3 pete.self  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 14-August 07

Re: ToUpper problem

Posted 14 August 2007 - 04:55 AM

View PostPsychoCoder, on 14 Aug, 2007 - 04:45 AM, said:

So the .ToUpper isnt working, is that what you're saying? If its not working what kind of output are you getting, is it throwing any errors?

I am getting a NullReferenceExceptiong : Object reference not set to an instance of an object.
I take this to mean I am either using a recursive call which wont work in C# or something hasnbt been initialised, sorry it stops at the postcode at the moment.
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: ToUpper problem

Posted 14 August 2007 - 04:59 AM

You're getting that because your Property (and its corresponding variable) havent been initialized yet. Move the .ToUpper from the Property and use it when you set that property i.e; postcode = my_value.ToUpper.

Theres always the chance that something else is causing the NullReferenceException also.
Was This Post Helpful? 0
  • +
  • -

#5 pete.self  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 14-August 07

Re: ToUpper problem

Posted 14 August 2007 - 05:05 AM

View PostPsychoCoder, on 14 Aug, 2007 - 04:59 AM, said:

You're getting that because your Property (and its corresponding variable) havent been initialized yet. Move the .ToUpper from the Property and use it when you set that property i.e; postcode = my_value.ToUpper.

Theres always the chance that something else is causing the NullReferenceException also.

it is withint he SET, but I take it you would feel to much like you were doing my work for me if you were to show me for that one and then I was able to understand and apply it to other sections of my work.
Was This Post Helpful? 0
  • +
  • -

#6 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: ToUpper problem

Posted 14 August 2007 - 05:09 AM

I already showed you. When you, in your code, go to set the value for that property do the ToUpper there, like postalcode = my_value.ToUpper Don't do it in the property declaration (until its been set by a value its not initialized, in the Set you're just telling it how to set the value, you're not actually setting the value or initializing it.
Was This Post Helpful? 0
  • +
  • -

#7 pete.self  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 14-August 07

Re: ToUpper problem

Posted 14 August 2007 - 05:20 AM

View PostPsychoCoder, on 14 Aug, 2007 - 05:09 AM, said:

I already showed you. When you, in your code, go to set the value for that property do the ToUpper there, like postalcode = my_value.ToUpper Don't do it in the property declaration (until its been set by a value its not initialized, in the Set you're just telling it how to set the value, you're not actually setting the value or initializing it.

thanks my apologies I dont normally do a lot of coding. your time and help is appreciated.
Was This Post Helpful? 0
  • +
  • -

#8 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: ToUpper problem

Posted 14 August 2007 - 05:22 AM

No apologies needed, as long as you're willing to put time and effort into your code I am more than willing to help :)
Was This Post Helpful? 0
  • +
  • -

#9 serializer  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 110
  • Joined: 25-June 07

Re: ToUpper problem

Posted 14 August 2007 - 05:55 PM

View Postpete.self, on 14 Aug, 2007 - 04:36 AM, said:

sio you know CapatalizeFirstLettersOfAllWordsInSentence is a method I call from another file.


Just to save you some typing ... this is generally known as "Title Case". See the c2.com wiki: CapitalizationRules.

You could name your method "TextHelper.ToTitleCase()". It might save you some headaches! ;)

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

Page 1 of 1