Trying to get a subroutine working

There is a piece of the skekch that has to be done several times.
So i thought put it in a subroutine en use the calculated value afterwards.

It looks like this:

int MyStation = 1;
//-----------------------------------------------------------------------
void CalcStation(uint8_t Station) {
  if(Station > 48) {
    Station = Station - 48; 
    }
  if(Station <= 0) {
    Station = Station + 48; 
    } 
}
//-----------------------------------------------------------------------

and it wil be called like this:

        MyStation = CalcStation(MyStation);

It wont compile and i get this error: NmraDccV01:406: error: void value not ignored as it ought to be

Am i doing something wrong and if so what?

error: void value not ignored as it ought to be

A function declared void doesn't return anything, so you can't assign its non-existent return value to anything.

You're declaring the function void (e.g. return nothing) but when you use it you're trying to get a value back. That won't work.

I think you want it declared as an int instead of void.

Additionally, you're declaring its parameter as unsigned (uint8_t) but then your code tests to see if it's below zero. That won't ever happen.

Then how should i tackle this problem?

  uint8_t CalcStation(uint8_t Station) {
  if(Station > 48) {
    Station = Station - 48; 
    }
  if(Station <= 0) {
    Station = Station + 48; 
    } 
return Station;
}

Two changes:

  1. declare your function so it returns something other than void (in my example, uint8_t)
  2. actually return something.

Now i get the stranged error messages:

C:\arduino\hardware\arduino\cores\arduino\IPAddress.cpp: In member function 'virtual size_t IPAddress::printTo(Print&) const':
C:\arduino\hardware\arduino\cores\arduino\IPAddress.cpp:50: error: void value not ignored as it ought to be
C:\arduino\hardware\arduino\cores\arduino\IPAddress.cpp:50: error: in evaluation of 'operator+=(size_t, void)'
C:\arduino\hardware\arduino\cores\arduino\IPAddress.cpp:51: error: void value not ignored as it ought to be
C:\arduino\hardware\arduino\cores\arduino\IPAddress.cpp:51: error: in evaluation of 'operator+=(size_t, void)'
C:\arduino\hardware\arduino\cores\arduino\IPAddress.cpp:53: error: void value not ignored as it ought to be
C:\arduino\hardware\arduino\cores\arduino\IPAddress.cpp:53: error: in evaluation of 'operator+=(size_t, void)'

Now i get the stranged error messages:

I don’t, but then I’m not compiling your code (hint)

I may be an idiod trying to get this running but what do YOU mean by this remark.
I am just trying to get some help to understand this.

Everybody thinks that all people are perfect programmers and understand somthing with just one word.
But sorry i am not. But if this is the kind of help here........

gharryh:
I am just trying to get some help to understand this.

You might help us, help you, and actually post the code you are trying to compile.

Snippets are not of much use. People tend to try to shortcut the help/troubleshooting process and only post what they think this issue is. As you can see in this example the code you posted has nothing to do with the error message.

The best approach is to post your entire code, error messages, and what is happening/what you expect to happen (assuming your question isn't "why won't this complie?")

No, I don't think you're an idiot because you're not a perfect programmer, because if that is the criterion for idiocy, then I'd be an idiot too. ( some might say...)
Imagine, however, walking into a garage and saying "my car doesn't work".
You'd be surprised if a mechanic didn't ask to see the car.