Author Topic: ELSEIF question  (Read 2208 times)

0 Members and 1 Guest are viewing this topic.

Offline thelowerrhythm

  • Newbie
  • Posts: 10
    • View Profile
ELSEIF question
« on: August 24, 2018, 08:55:38 pm »
Hello, first post. Dusted off a really old machine the other day and was digging through some BAS programs I had been working on. Now I've got the wild hair to finish some of them. I'm still working in Qbasic, but QB64 is on its way down the pipe as I type this.

Fair warning: I'm no programmer. I had barely learned anything when I moved on.

Anyway, this program I've got is supposed to let the user input four strings of text, choose foreground / background colors (or randomize them), and then barf out these strings at random X number of times.

This is the section that always falters:

IF B = 666 AND F = 666 THEN
COLOR FR, BR
ELSEIF B < 666 AND F < 666 THEN
COLOR F, B
ELSEIF B = 666 AND F < 666 THEN
COLOR FR, B
ELSEIF B < 666 AND F = 666 THEN
COLOR F, BR
END IF

B is the background color input by user and F is foreground color input by user, while BR and FR are the randomly generated versions respectively.

If you set both to random by entering 666 for B and F, it works. It also works if both are NOT 666. However, if one is set to random and the other isn't, it always fails, citing the appropriate COLOR line as an Illegal Function Call.

This is a mystery that's about 18 years old, so my future appreciation for any help solving it.


FellippeHeitor

  • Guest
Re: ELSEIF question
« Reply #1 on: August 24, 2018, 09:06:10 pm »
Hello there and welcome to the forum.

Is this any sort of demoniac conjuring? A lot of 666 there!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: ELSEIF question
« Reply #2 on: August 24, 2018, 09:16:46 pm »
It's been a long time since I have used qbasic, but back then, the "general" colors numbered from 0 to 15. (of course this may be different depending on the "screen" number.

As long as B and F are less then 16 pretty much all of it should work. (Do not just take 'my' word for it. I may be wrong as well... lol)

J

ps: More importantly... Welcome to the Forum!!
Logic is the beginning of wisdom.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: ELSEIF question
« Reply #3 on: August 24, 2018, 09:19:13 pm »
Fillippe,

You snuck in whilst I was typing.... lol

J
Logic is the beginning of wisdom.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: ELSEIF question
« Reply #4 on: August 24, 2018, 09:45:21 pm »
IF B = 666 AND F = 666 THEN
COLOR FR, BR
ELSEIF B < 666 AND F < 666 THEN
COLOR F, B
ELSEIF B = 666 AND F < 666 THEN
COLOR FR, B
ELSEIF B < 666 AND F = 666 THEN
COLOR F, BR
END IF


It seems to me that 666 is the code to use a random color,  and if so, the COLOR statements are reversed.

ELSEIF B < 666 AND F = 666 THEN
COLOR F, BR

For example, in the above, B would be a valid color (less than 666), and F would be the code for FOREGROUND_RANDOMIZED, which should end up being:

ELSEIF B < 666 AND F = 666 THEN
COLOR FR, B


https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline thelowerrhythm

  • Newbie
  • Posts: 10
    • View Profile
Re: ELSEIF question
« Reply #5 on: August 24, 2018, 10:01:03 pm »
Noooo. /facepalm

That was totally it, lol. It was reversed and trying to call the wrong variable in the wrong spot.

I love the fact that my first dip back into this after all this time was just to embarrass myself over a 20 year old problem.

Damn this forum is quick! Thanks everyone!