Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted
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....

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted

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#.

Posted

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.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...