- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This example has so much wrong with it I hardly know where to start. The misuse of logical operations on integers, which we support as an extension, is the least of it. There are numerous syntax errors as well. I will have it replaced.
Basically, the .OR. should be replaced with references to the IOR intrinsic and the .AND. replaced with IAND.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is what it should be:
USE IFQWIN INTEGER(4) mouseevent, keystate, x, y, result !... mouseevent = IOR(MOUSE$RBUTTONDOWN,MOUSE$LBUTTONDOWN) result = WAITONMOUSEEVENT (mouseevent, keystate, x , y) ! ! Wait until right or left mouse button clicked, then check the keystate ! with the following: ! if (IAND(MOUSE$KS_SHIFT,keystate) == MOUSE$KS_SHIFT) & & write (*,*) 'Shift key was down' if (IAND(MOUSE$KS_CONTROL,keystate) == MOUSE$KS_CONTROL) & & write (*,*) 'Ctrl key was down' end
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When Fortran was the only language I knew, I remember that reading about logical and shift operations (in the machine language sense, not the high level language sense) was a revelation to me. Instead of thinking about an INTEGER variable as a number having a value, you can think of it as an array of BIT_SIZE(I) logical values, or flags. Same variables, just different way to think about them.
ORing two integer variables results in a variable whose set flags are the union of the set flags of the inputs. For two inputs IOR(A,B) achieves this. For any number of inputs, f2008 provides IANY([A,B,C,D]) (as an example with 4 inputs).
ANDing two integer variables results in a variable whose set flags are the intersection of the set flags of the inputs. For two inputs use IAND(A,B); for any number of inputs, IALL([A,B,C,D]).
There is also IEOR(A,B) to toggle bits, IPARITY for any number of inputs.
Thus in the above, MOUSE$RBUTTONDOWN and MOUSE$LBUTTONDOWN each have, I assume, 1 bit (flag) set in them so the WAITONMOUSEEVENT invocation ends up checking for both events because those are the two flags that are set in mouseevent. IAND(MOUSE$KS_SHIFT,keystate) will equal MOUSE$KS_SHIFT exactly when all the bits (flags) that are set in MOUSE$KS_SHIFT are also set in keystate.
So this way of thinking about integer variables is sort of a set of logical operations on a fixed size array. A Possible reference is http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&ved=0CCwQFjAC&url=http%3A%2F%2Fwww.cs.uwm.edu%2Fclasses%2Fcs215%2Fslides%2F14%2520-%2520Arithmetic%2520%26%2520Logic%25201.ppt&ei=81TKVPS4MJe2yASYuIGgDA&usg=AFQjCNGOT8mICel1yne6WHk8aWDQRh-stQ&bvm=bv.84607526,d.aWw
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve and Repeat Offender:
Thank you for the replies. They are very helpful and fully explain everything.
By the way is there a document that gives tips on how to format posts to the forum? I would like to know how Steve inserted his code snip into his post, and how to start a new line without inserting a blank line (like the blank line between the lines Regards and Bob below).
Regards,
Bob.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When you enter a post, there is a row of buttons for various formatting options. The second from the right is the Code button. Click that, select Fortran from the dropdown, and paste your code into that.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page