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

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, networking, learning, and sharing knowledge.