I wrote this code
\documentclass{article}
% make a command called \insertfoo{..} for the user to insert foo
\newcommand{\insertfoo}[1]{%
\savebox{\boxthatcontainsfoo}{#1}%
}
% make a command called \showfoo that shows the value for foo
\newcommand{\showfoo}{%
\usebox{\boxthatcontainsfoo}%
}
\insertfoo{somefoo}
\begin{document}
The foo you choose was \showfoo .
end{document}
\end{document}
Why do I get a compiling error?
\newcommand{\}{%
at the start of it all. That's causing all sorts of problems. I don't know if that's the real reason for your compilation error because you've only posted a snippet and not a compilable document.\savebox
and\usebox
expect a box, not a braced-group, as the next token (that's my understanding).