BOSTON (AP) - The state’s highest court says a medical marijuana permit did not get a man off the hook for violating terms of his probation.

The Supreme Judicial Court ruled Wednesday in the case of Danny Vargas, who was given three years of probation for a 2012 Haverhill armed robbery. He admitted using some of the stolen money to buy pot.

Vargas was prohibited from using marijuana during his probationary period. But he later tested positive for it and was sentenced to two years in jail.

He appealed, saying a doctor had given him permission to use medical marijuana.

In a unanimous decision, the court upheld the sentence, writing that Vargas agreed to the probationary terms before enrolling in the state program.