Switching a relay on & off using a momentary push button

All, many thanks for the help so far; with it, I now have an (almost) working system. The code is now as follows:

// Constants:
const int SwitchPin = 32; // the pin that the switch is attached to
const int RelayPin = 42; // the pin that the relay is attached to

// Variables:
int SwitchState = 0; // current state of the switch
int PreviousSwitchState = 0; // previous state of the switch
int RelayState = 0; // current state of relay pin

void setup() {
// initialise switch pin (32) as an input:
pinMode(SwitchPin, INPUT);

// enable internal pullup resistor - open switch will now go high
//digitalWrite (SwitchPin, HIGH);

// initialise relay pin (42) as an output:
pinMode(RelayPin, OUTPUT);

// initialize serial communication:
Serial.begin(9600);
}

//Look for switch Off to On event
void loop() {

// read the switch pin (32):
SwitchState = digitalRead(SwitchPin);

// read the relay pin (42):
RelayState = digitalRead(RelayPin);

// compare the SwitchState to its previous state
if (SwitchState != PreviousSwitchState) {

// if the state has changed, check change direction
if (SwitchState == HIGH){

// if the current state is HIGH then the switch went from off to on
// instigate a relay state change:

if (RelayState == LOW)
digitalWrite(RelayPin, HIGH);
else
digitalWrite(RelayPin, LOW);}

}
}

I put the line in to enable the pull up resistor, the code didn't work - it only worked when I removed it.

As can be seen, I'm now using digital pins 32 & 42. I changed the physical switch to a normally open push button. On loading the sketch, the LED is off, as I'd expect. I press the button, and the LED comes on. I press the switch again, and - sometimes it goes off, sometimes not - it seems intermittent. I tried just shorting the wires (suspecting a bad switch), same problem. It occasionally works on the first "off" press, sometimes the tenth or so - no apparent pattern.

Worse, it sometimes switches all by itself...

This has me baffled! Common sense tells me to suspect the switch not making contact, yet - after re-uploading the code, the first press to switch the LED on always works.

Could it be a floating pin, still to do with the internal pull up resistor?

Thanks,

Ian