When his eight-year relationship broke down, Darren Johnstone reverted to illegal drugs.
Johnstone, 28, of Havelock Place, was fined £270 when he admitted possession of heroin at Galashiels Police Station on February 4.
He was fined a further £100, when he also admitted possession of cannabis at Princes Street, on February 14.
Depute fiscal Tessa Bradley told how Johnstone was detained by police and searched, when a package of brown powder, confirmed as diamorphine, was found hidden in his clothing.
“He said it was heroin and that he had paid £80 for it,” said Ms Bradley.
“It weighed 3.5gms and the value was put at £350,” she added.
On the second occasion, Johnstone had cannabis worth £2.50 “in his sock”.
Solicitor Iain Burke, defending, said his client had a long record for drug offences, but had been drug-free for the last two years.
“His eight-year relationship broke down, so he lapsed back into drug use again,” explained Mr Burke.
“The relationship ended about six months ago and it was the end of that relationship which led him to dabbling in drugs again.
“He was struggling to cope, emotionally, and resorted to old habits,” added Mr Burke.
He said Johnstone was “desperately keen to avoid going back to his previous behaviour” and had sought medical help.
Mr Burke said Johnstone was currently a student, receiving a bursary.
Fining Johnstone £370, Sheriff Kevin Drummond told him: “You are able to pay £80 out of limited income from public funds, so you are able to pay a fine.”
“If you are returning to your previous habits which resulted in a long list of convictions, than the consequences are well known to you,” he warned.