well, the problem is that strval is probably less than 31. A quick fix would be to do this:
string logoutstring = tempval.Substring(0, Math.Max(0, strval - 31));
That way, the ssecond parameter will always be at least 0.
I don't get it. I actually provided code to fix the problem, and my response is voted lower?