Qbasicnews.com
November 14, 2019, 11:16:29 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Problem with IF...THEN...ELSEIF + DO ... LOOP + WHILE ... WEND  (Read 6343 times)
Karelius
Member
*
Posts: 88



« on: June 15, 2009, 08:58:35 AM »

Hi! I've a problem with this code:

Code:
Sessione = TRUE
WHILE Sessione

'Barra di stato
Future.FillBox 2, Lx - 19, Rx - 2, Lx - 2, RGB2Color&(0, 0, 32)
Future.Box 1, Lx - 20, Rx - 1, Lx - 1, RGB2Color&(0, 128, 192)

'Barra del menu
Future.FillBox 2, Lx - 49, Rx - 2, Lx - 21, RGB2Color&(0, 24, 64)
Future.Box 1, Lx - 50, Rx - 1, Lx - 20, RGB2Color&(0, 128, 192)

Future.LoadBMP "\hawk\skin\" + skin$ + "\user.bmp", 5, Lx - 47

TIMER ON
ON TIMER(1) GOSUB Stato

Future.MouseOn

DO
        Future.UpdateMouse
        IF Future.MouseX% > 5 AND Future.MouseX% < 29 AND Future.MouseY% > Lx - 47 AND Future.MouseY% < Lx - 23 AND Future.MouseB% = 0 THEN
                Future.Print 5, Lx - 18, "Amministra il sistema", RGB2Color&(255, 255, 255), -1
        ELSEIF Future.MouseX% > 5 AND Future.MouseX% < 29 AND Future.MouseY% > Lx - 47 AND Future.MouseY% < Lx - 23 AND Future.MouseB% = 1 THEN
                Future.MouseOff
                Future.FillBox 33, Lx - 49, Rx - 2, Lx - 21, RGB2Color&(0, 52, 92)
                Future.Box 32, Lx - 50, Rx - 1, Lx - 20, RGB2Color&(0, 128, 192)
                Future.LoadBMP "\hawk\skin\" + skin$ + "\update.bmp", 37, Lx - 47
                Future.LoadBMP "\hawk\skin\" + skin$ + "\esci.bmp", 65, Lx - 47
                Future.MouseOn
                DO
                        Future.UpdateMouse
                        IF Future.MouseX% > 37 AND Future.MouseX% < 61 AND Future.MouseL% > Lx - 47 AND Future.MouseY% < Lx - 23 AND Future.MouseB% = 0 THEN
                                Future.Print 5, Lx - 18, "Visualizza info aggiornamenti", RGB2Color&(255, 255, 255), -1
                        ELSEIF Future.MouseX% > 37 AND Future.MouseX% < 61 AND Future.MouseL% > Lx - 47 AND Future.MouseY% < Lx - 23 AND Future.MouseB% = 1 THEN
                                END
                        ELSEIF Future.MouseX% > 65 AND Future.MouseX% < 89 AND Future.MouseL% > Lx - 47 AND Future.MouseY% < Lx - 23 AND Future.MouseB% = 0 THEN
                                Future.Print 5, Lx - 18, "Esci da Hawk", RGB2Color&(255, 255, 255), -1
                        ELSEIF Future.MouseX% > 65 AND Future.MouseX% < 89 AND Future.MouseL% > Lx - 47 AND Future.MouseY% < Lx - 23 AND Future.MouseB% = 1 THEN
                                END
                        END IF
                LOOP WHILE INKEY$=""
        END IF
       
LOOP WHILE INKEY$ = ""
Sessione = FALSE
Future.MouseOff
WEND

in the second DO...LOOP, the "if...then...elseif" don't work!!! Why?
Logged
Moneo
Na_th_an
*****
Posts: 1971


« Reply #1 on: June 15, 2009, 07:39:03 PM »

Just a quick look a your code shows that you have many undeclared functions, as well as undefined variables.

Maybe you didn't show us the entire code, without which it's hard to determine your problem.

Regards..... Moneo
Logged
Clippy
Member
*
Posts: 84



« Reply #2 on: June 15, 2009, 08:35:58 PM »

I'm suprised that you don't get an "expression too complex!" error!

WHY do you need the second DO LOOP? Nothing changes........and what happens if none of the IF and ELSEIF statements are True? You get stuck there until a key is pressed.

I think that you have too many ELSEIF comparisons. Some portions are repeated with additional comparisons.

My suggestion: Start from the left and make that one IF statement. Then use the next comparison if that is true to make further comparisons.

Code:
IF Future.MouseX% > 37 AND Future.MouseX% < 61 THEN

ELSEIF will find the first comparison that is True, no matter how much is added to later comparisons!

« Last Edit: June 15, 2009, 08:48:05 PM by Clippy » Logged

Karelius
Member
*
Posts: 88



« Reply #3 on: June 16, 2009, 07:05:13 AM »

This is my entire code:

Code:
'$INCLUDE: 'FUTURE.BI'
DEFINT A-Z
DIM Rx AS INTEGER, Lx AS INTEGER, Bit AS INTEGER
CONST FALSE = 0, TRUE = -1
Sessione = TRUE

ON ERROR GOTO Errore

'Apertura registri di configurazione
OPEN "\hawk\system\svga.cfg" FOR INPUT AS #1
        INPUT #1, Rx
        INPUT #1, Lx
        INPUT #1, Bit
OPEN "\hawk\system\sfondo.cfg" FOR INPUT AS #2
        INPUT #2, sfondo$
OPEN "\hawk\system\skin.cfg" FOR INPUT AS #3
        INPUT #3, skin$

'Impostazione Video
SetScreenMode Rx, Lx, Bit

Future.CLS 0

'Avvio sfondo
IF sfondo$ <> "nessuno" THEN
        IF Rx < 800 THEN
                Future.LoadBMP "\hawk\sfondi\640\" + sfondo$, 0, 0
        ELSEIF Rx = 800 THEN
                Future.LoadBMP "\hawk\sfondi\800\" + sfondo$, 0, 0
        ELSEIF Rx > 800 THEN
                Future.LoadBMP "\hawk\sfondi\1024\" + sfondo$, 0, 0
        END IF
END IF

WHILE Sessione

'Barra di stato
Future.FillBox 2, Lx - 19, Rx - 2, Lx - 2, RGB2Color&(0, 0, 32)
Future.Box 1, Lx - 20, Rx - 1, Lx - 1, RGB2Color&(0, 128, 192)

'Barra del menu
Future.FillBox 2, Lx - 49, Rx - 2, Lx - 21, RGB2Color&(0, 24, 64)
Future.Box 1, Lx - 50, Rx - 1, Lx - 20, RGB2Color&(0, 128, 192)

Future.LoadBMP "\hawk\skin\" + skin$ + "\user.bmp", 5, Lx - 47

TIMER ON
ON TIMER(1) GOSUB Stato

Future.MouseOn

DO
        Future.UpdateMouse
        IF Future.MouseX% > 5 AND Future.MouseX% < 29 AND Future.MouseY% > Lx - 47 AND Future.MouseY% < Lx - 23 AND Future.MouseB% = 0 THEN
                Future.Print 5, Lx - 18, "Amministra il sistema", RGB2Color&(255, 255, 255), -1
        ELSEIF Future.MouseX% > 5 AND Future.MouseX% < 29 AND Future.MouseY% > Lx - 47 AND Future.MouseY% < Lx - 23 AND Future.MouseB% = 1 THEN
                Future.MouseOff
                Future.FillBox 33, Lx - 49, Rx - 2, Lx - 21, RGB2Color&(0, 52, 92)
                Future.Box 32, Lx - 50, Rx - 1, Lx - 20, RGB2Color&(0, 128, 192)
                Future.LoadBMP "\hawk\skin\" + skin$ + "\update.bmp", 37, Lx - 47
                Future.LoadBMP "\hawk\skin\" + skin$ + "\esci.bmp", 65, Lx - 47
                Future.MouseOn
                DO
                        Future.UpdateMouse
                        IF Future.MouseX% > 37 AND Future.MouseX% < 61 AND Future.MouseL% > Lx - 47 AND Future.MouseY% < Lx - 23 AND Future.MouseB% = 0 THEN
                                Future.Print 5, Lx - 18, "Visualizza info aggiornamenti", RGB2Color&(255, 255, 255), -1
                        ELSEIF Future.MouseX% > 37 AND Future.MouseX% < 61 AND Future.MouseL% > Lx - 47 AND Future.MouseY% < Lx - 23 AND Future.MouseB% = 1 THEN
                                END
                        ELSEIF Future.MouseX% > 65 AND Future.MouseX% < 89 AND Future.MouseL% > Lx - 47 AND Future.MouseY% < Lx - 23 AND Future.MouseB% = 0 THEN
                                Future.Print 5, Lx - 18, "Esci da Hawk", RGB2Color&(255, 255, 255), -1
                        ELSEIF Future.MouseX% > 65 AND Future.MouseX% < 89 AND Future.MouseL% > Lx - 47 AND Future.MouseY% < Lx - 23 AND Future.MouseB% = 1 THEN
                                END
                        END IF
                 LOOP WHILE INKEY$ = ""
        END IF
       
LOOP WHILE INKEY$ = ""
Sessione = FALSE
Future.MouseOff
WEND

CLOSE #1, #2, #3

END

Errore: CHAIN "\hawk\system\error.lib"

Stato: Future.MouseOff
Future.FillBox 2, Lx - 19, Rx - 2, Lx - 2, RGB2Color&(0, 0, 32)
Future.MouseOn
RETURN

For Lx, i can not remove because the position where I click is incorrect.
Logged
Karelius
Member
*
Posts: 88



« Reply #4 on: June 16, 2009, 12:51:43 PM »

i find the error  Tongue... The problem is Futue.MouseL%  Tongue Tongue Tongue ... Thanks for all  Smiley
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!