Nate Bross Posted February 15, 2006 Posted February 15, 2006 I have an object (sprite) and I have a method called inkCF, or incriment current frame. public void inkCF() { if ((iCurrentFrame + 1)< (iNumFrames)) { iCurrentFrame += 1; } else { iCurrentFrame = 1; } } My issue is that when I try to call the method, either of these two ways MyClass x; x.inkCF; //Or, This, inside of another sub in the class code... inkCF; code.... I get the following error Only assignment, call, increment, decrement, and new object expressions can be used as a statement. When I used the MSDN help it didn't really help me. I'm new to C#, and the same method worked in Visual Basic without error. Using.....C# 2005 Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Nate Bross Posted February 15, 2006 Author Posted February 15, 2006 If I paste the code in the inkCF method inline with the rest of the code it works fine, but I don't want to do that because I need to call that method from several places.... Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
mskeel Posted February 15, 2006 Posted February 15, 2006 I believe the problem is that you are missing the parens when you call the method: MyClass x; x.inkCF(); code... inkCF(); code.... If I recall, parenthesis are optional for methods without arguments in Visual Basic. That could easily be causing the confusion, esspecially if the code was originally written in VB. Parenthisis are always required in C#. Quote
Nate Bross Posted February 15, 2006 Author Posted February 15, 2006 Thanks a million, that was it. I could have sworn that I tried that, but in hindsight I tried so many combonations that I may have had seporate error. Regardless I added the () and it works now. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
mskeel Posted February 15, 2006 Posted February 15, 2006 Yeah, I always get a little frazzled when switching between languages (do I need the semi-colon? and so on). I'm glad it turned out to be something simple. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.