Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem w/ IF-THEN 1

Status
Not open for further replies.

qbasicking

Programmer
Aug 19, 2001
628
US
Heres the deal: When I click my mouse I make my program run a click diagnosis to see what was clicked.
It runs through all the buttons of all of the windows.

Here's the code that is giving me problems:

FOR buttons = 1 to 30
x = butx(buttons)
y = buty(buttons)
x2 = butx2(buttons)
y2 = buty2(buttons)
IF butwin(buttons) = awin OR butwin(buttons) = 0 THEN
IF x<x%>x2 AND y<y%>y2 THEN IF buttons = 1 then task:IF
buttons = 2 then dos
END IF
NEXT

I can't get it to goto the SUB dos, I know that the rest of the code is right becasue is goes to SUB task flawlessly, and when I make the line:
IF x<x%>x2 AND y<y%>y2 THEN IF buttons = 2 then dos: IF
buttons = 1 then task
it goes to dos, but not to task

What should I do to get it to do both?

PS: x% and y% are the cursor positions
Of course I didn't use x<x%>x2; I used AND but i
shortened it to save space
yes, all of the strings were called long before
 

I haven't tried it but I think you've got too many IFs on one line. You could try changing the bit 'if buttons%=2 ......dos' to

If buttons%=2 then task ELSEIF buttons%=1 then dos

on a separate line.
 
This works. It's is a fair simulation of your params:-

DECLARE SUB one
DECLARE SUB two
a%=1:b%=1:c%=0
x=1:x%=2:x2=3
y=2:y%=3:y2=4
buttons=2

IF a%=b% OR c%=0 THEN
IF x<x% AND x2>x% AND y<y% AND y2>y% THEN
IF buttons=1 THEN one
IF buttons=2 THEN two
END IF
END IF
 
pebe is right. Your logic isn't structured well...

FOR buttons = 1 to 30
x = butx(buttons)
y = buty(buttons)
x2 = butx2(buttons)
y2 = buty2(buttons)
IF butwin(buttons) = awin OR butwin(buttons) = 0 THEN
[red] IF x<x%>x2 AND y<y%>y2 THEN [/red]
IF buttons = 1 then task
IF buttons = 2 then dos
END IF
NEXT

....the red &quot;end if&quot; is missing--which is properly incorporated in pebe's second response. Try out pebe's code above, it should work now that the computer recognizes that &quot;one&quot; and &quot;two&quot; are SUBs. If you are still having probs, try using CALL Task instead or even SELECT.

--MiggyD It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
I have fixed the problem by simply moving the code to the beginning of the sub

Miggyd-I don't think your code will work, I have tried similar codes, you can only have one THEN-END IF command at a time, when I do something like that I get an error and it says &quot;Must be first line of statement&quot;
 
Did you read the paragraph AFTER the code? If not, it indicates that the original code was not properly done. So I made a note for later readers inregards to that.

--MiggyD It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top