"Expression too complex" error when compiling

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
User avatar
Codemss
Veteran
Posts: 124
Joined: Sun Jun 24, 2007 6:49 am
Location: Utrecht, The Netherlands
Contact:

"Expression too complex" error when compiling

Post by Codemss »

I want to compile a program that consists this piece of code:

Code: Select all

CLS
DEFINT A-Z
DIM SHARED btn(1, 1, 1, 1, 1, 1, 1, 1)
DIM SHARED ntb(255, 7)
FOR n = 0 TO 255
  IF (n AND 1) THEN ntb(n, 0) = 1: b0 = 1 ELSE b0 = 0
  IF (n AND 2) THEN ntb(n, 1) = 1: b1 = 1 ELSE b1 = 0
  IF (n AND 4) THEN ntb(n, 2) = 1: b2 = 1 ELSE b2 = 0
  IF (n AND 8) THEN ntb(n, 3) = 1: b3 = 1 ELSE b3 = 0
  IF (n AND 16) THEN ntb(n, 4) = 1: b4 = 1 ELSE b4 = 0
  IF (n AND 32) THEN ntb(n, 5) = 1: b5 = 1 ELSE b5 = 0
  IF (n AND 64) THEN ntb(n, 6) = 1: b6 = 1 ELSE b6 = 0
  IF (n AND 128) THEN ntb(n, 7) = 1: b7 = 1 ELSE b7 = 0
  btn(b0, b1, b2, b3, b4, b5, b6, b7) = n
NEXT
END
And it gets me an "Expression too complex" error when compiling. Can't this be solved?
Check out my site: <a href="http://members.lycos.nl/rubynl">Click here</a>
Hope you like it. Send some feedback if you want: <a href="mailto:basicallybest@live.nl">Mail me</a>
Codemss, before known as RubyNL
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

Use block IFs instead of trying to cram it all onto one line. You might also want to come up with a more intuitive method of representing your code too, as that looks rather inefficient. Decimal-to-binary converter, eh? :)

I can make two suggestions right off the bat:

1. b0 b1 b2 etc. could be redone as an array.
2. Building off of #1, you could simply use a loop to set them all to 0 at the beginning of your loop. That would eliminate the need for the ELSE clause, since they would already all be 0 unless explicitly set otherwise. Or, if you don't want to change your variables as per #1, you could just have b0 = 0: b1 = 0: etc. at the beginning of your loop.
User avatar
Codemss
Veteran
Posts: 124
Joined: Sun Jun 24, 2007 6:49 am
Location: Utrecht, The Netherlands
Contact:

Post by Codemss »

Nodtveidt wrote:Use block IFs instead of trying to cram it all onto one line. You might also want to come up with a more intuitive method of representing your code too, as that looks rather inefficient. Decimal-to-binary converter, eh? :)
Yes :). I've found that the problem is the binary-to-number converter, because it has so many dimensions (8!). So I've found that I can solve this by using 8 arrays: a Mul1, a Mul2, a Mul4, 8, 16, 32, 64 and 128. Then I can add the results together.

So thanks for your help, but I've found a solution.

BTW: It really doesn't matter if this code is inefficient (but it is indeed :P), because it are all precalculations.
Check out my site: <a href="http://members.lycos.nl/rubynl">Click here</a>
Hope you like it. Send some feedback if you want: <a href="mailto:basicallybest@live.nl">Mail me</a>
Codemss, before known as RubyNL
Mac
Veteran
Posts: 151
Joined: Mon Aug 06, 2007 2:00 pm

Curious

Post by Mac »

Codemss wrote:It really doesn't matter if this code is inefficient because it are all precalculations.
Well, I sure would like to see your final application that required the BtN-array. I agree that pre-computing the NtB-array is useful because it is easy to use, but I would guess the other is as hard to use as just computing. Below is how I would handle NtB and BtN.

Mac

Code: Select all

DECLARE FUNCTION BtN% (Binary$)
DIM NtB(255) AS STRING: GOSUB InitNtB
FOR i = 0 TO 255
  Test$ = NtB(i)
  Test% = BtN(Test$)
  IF Test% <> i THEN STOP: 'bug in program
NEXT i
PRINT "Works"
SYSTEM

InitNtB:
FOR n = 0 TO 255
  IF (n AND 128) THEN w$ = "1" ELSE w$ = "0"
  IF (n AND 64) THEN w$ = w$ + "1" ELSE w$ = w$ + "0"
  IF (n AND 32) THEN w$ = w$ + "1" ELSE w$ = w$ + "0"
  IF (n AND 16) THEN w$ = w$ + "1" ELSE w$ = w$ + "0"
  IF (n AND 8) THEN w$ = w$ + "1" ELSE w$ = w$ + "0"
  IF (n AND 4) THEN w$ = w$ + "1" ELSE w$ = w$ + "0"
  IF (n AND 2) THEN w$ = w$ + "1" ELSE w$ = w$ + "0"
  IF (n AND 1) THEN w$ = w$ + "1" ELSE w$ = w$ + "0"
  NtB(n) = w$
NEXT n
RETURN

FUNCTION BtN% (Binary$)
IF LEN(Binary$) <> 8 THEN STOP: 'Misuse of this function
IF MID$(Binary$, 8, 1) = "1" THEN w = 1 ELSE w = 0
IF MID$(Binary$, 7, 1) = "1" THEN w = w + 2
IF MID$(Binary$, 6, 1) = "1" THEN w = w + 4
IF MID$(Binary$, 5, 1) = "1" THEN w = w + 8
IF MID$(Binary$, 4, 1) = "1" THEN w = w + 16
IF MID$(Binary$, 3, 1) = "1" THEN w = w + 32
IF MID$(Binary$, 2, 1) = "1" THEN w = w + 64
IF MID$(Binary$, 1, 1) = "1" THEN w = w + 128
BtN% = w
END FUNCTION
Post Reply