Qbasicnews.com

Full Version: i need a way to shorten this piece of code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i need to know the correct method to shorten this piece of code:
Code:
if room = 1 then 10
if room = 2 then 20
if room = 3 then 30
...etc

im sure i can do this with an equation such a if room = x then goto (10 * x)

i just need a method to show that (10 * x) is a line number to be refered to
The line numbers referred to by GOTO have to be fixed numbers, not variables or expressions. (Some people like to use SELECT CASE in situations like yours, but that won't shorten your code any. But why are you worried about that?)
i wasnt worried im just lazy hehe i didnt want to have to type a new line for a room everytime i created a new one...hehe no worries thanks :-)
Hey there, ummm.
Quote:Code:

if room = 1 then 10
if room = 2 then 20
if room = 3 then 30
...etc
so does that mean that you want to go to a certain label if the room is a certain number, right? Okay, I think there might be an easier way to do it, but I think that if you're a beginning programmer you really should just use what methods you got, then advance your methods generally and gradually. I think that maybe someone will help you out but if you want my opinion I think that you should just stick with what you are doing for now, and maybe you'll come up with your own system soon. I might sound lame but hey, it is my experience in this matter....
yep you're right im starting to develop my skills now. I find its easier to write a programme how you can most easilly understand it and then change it afterwards once u can assess it as a whole and shorcuts become more apparent.

im sure there is a way to accomplish this somehow though, just gotta solve it :-D
You can always do:

Code:
on room goto 10, 20, 30

Thats pretty short.

Dex
Not a good style of programming, however. But it works.

It is better to have the rooms in a data structure (arrays and such) and use the same code for everyone of them.
I know . . . I was just answering literally. :wink:

Dex