In class we did a program on moving a round object up and down on a form,we finally figured it out but what i want to know is there are another way of shortening the coding instead of tesing using boolean :(

Recommended Answers

My crystal ball is in the repair shop, unfortunately, so I don't know whether any solution I might come up with is shorter or longer than yours.

Jump to Post

Why dont you post your program or at least a part of it here so that others could get to know how long (or short) you program is at the moment :D

-----------------
Programming ( Assignment / Project ) Help

Jump to Post

All 5 Replies

My crystal ball is in the repair shop, unfortunately, so I don't know whether any solution I might come up with is shorter or longer than yours.

Here you go.

if(upkeypressed)
{
    yPos--;
}
if(downkeypressed)
{
    yPos++;
}

Assuming that upkeypressed and downkeypressed are booleans or integers that only have values 0 or 1,

yPos += downkeypressed - upkeypressed;

you can do it that way, but yo loose alot of readability!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.