Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Stuart

Pages: [1]
1
QB64 Discussion / Re: IF THEN issue using AND, I think I'm losing my mind!
« on: December 14, 2021, 11:49:29 am »
Quote
IF A <> 0 AND B <> 0 THEN....    <--- Never any issues with this, and it's actually quite readable and easy to understand.

IF A * B THEN....   <--- This might run faster and be shorter code, but there's always the chance that SOMETIME, it's going to overflow.  And, I know myself -- when it does, something like this would drive me absolutely insane trying to find it and debug it.  Because, after all, it works perfectly well all the rest of the time!

I totally agree, since unsigned variables are possible in QB64.
QB4.5 didn't allow unsigned variables, so it was never an issue back in those days...  (I'm just an old style SCREEN 0 type of programmer.)

Quote
Now, with that caveat said, I'd also like to say, "I don't have a clue what variable TYPE an IF statement actually uses for internal calculations."  When we do A * B, is the intermittent result that we compare against 0 an _UNSIGNED _BYTE like the two initial variable types?  Is it a LONG?  A _FLOAT??

That is a very good question...
It seems like it could cause occasional "unexpected results" depending on what the answer really is.
Back in QB4.5, I'm pretty sure that all internal functions like VAL(num$) would ALWAYS be interpreted as a SIGNED FLOAT.

2
QB64 Discussion / Re: IF THEN issue using AND, I think I'm losing my mind!
« on: December 14, 2021, 05:13:33 am »
If the main purpose is to make sure that neither value is zero, instead of this : 
IF P.MOR <> 0  AND P.MOB <> 0 THEN...

wouldn't this work just as well and be more simple, shorter, and faster if it was in a loop?
IF P.MOR * P.MOB THEN...

Just wondering...

3
QB64 Discussion / Re: Help needed with one or more _MEM commands
« on: February 07, 2019, 07:29:40 am »
And since it sounds like you just want to grab a segment of a screen, why don't you give these little routines a quick try:

Code: QB64: [Select]
  1. REDIM Array(0) AS STRING
  2.  
  3. FOR i = 1 TO 25 'draw an original screen
  4.     COLOR 4
  5.     LOCATE i, 1: PRINT i;
  6.     COLOR 15
  7.     LOCATE i, i: PRINT i;
  8.  
  9. ScreenSave 0, 10, 10, 20, 20, Array() 'save a portion of it
  10. CLS 'clear it
  11. ScreenRestore 0, 10, 10, Array() 'restore it exactly where it was
  12. CLS 'clear it
  13. SCREEN _NEWIMAGE(120, 50, 0) 'and make a larger screen
  14. ScreenRestore 0, 10, 10, Array() 'restore it to that larger screen
  15. ScreenRestore 0, 45, 7, Array() 'And to showcase that we can move this text elsewhere...
  16.  
  17.  
  18. SUB ScreenSave (Image, X1, Y1, X2, Y2, Array() AS STRING) 'coordinates of the screen to copy
  19.     IF X1 > X2 THEN SWAP X1, X2 'go from left to right, not right to left
  20.     IF Y1 > Y2 THEN SWAP Y1, Y2 'and from top yo bottom, not bottom to top
  21.  
  22.     DIM M AS _MEM
  23.     M = _MEMIMAGE(Image) '
  24.     E = ConvertOffset(M.ELEMENTSIZE) 'How many bytes per pixel are in memory?  Screen 0 uses 2 bytes, 256 color screens use 1, 32-bit screens use 4
  25.  
  26.     Length = (X2 - X1 + 1) * E 'Width of stored area * bytes per pixel
  27.     Rows = (Y2 - Y1 + 1) 'Number of rows to store
  28.  
  29.     REDIM Array(1 TO Rows) AS STRING 'Array to store the data
  30.     FOR i = 1 TO Rows
  31.         Array(i) = SPACE$(Length) 'Set the array to the proper length to store each row of data
  32.     NEXT
  33.  
  34.     count = 0
  35.     IF E = 2 THEN
  36.         FOR y = Y1 - 1 TO Y2 - 1 'for text screens, we need to change the coordinates from using text locations
  37.             '                     (starting at 1,1), and convert them to memory locations starting at 0,0.
  38.             count = count + 1
  39.             _MEMGET M, M.OFFSET + (y * _WIDTH + X1) * E, Array(count) 'get the rows into memory starting from the proper offset
  40.         NEXT
  41.     ELSE
  42.         FOR y = Y1 TO Y2
  43.             count = count + 1
  44.             _MEMGET M, M.OFFSET + (y * _WIDTH + X1) * E, Array(count) 'get the rows into memory starting from the proper offset
  45.         NEXT
  46.     END IF
  47.     _MEMFREE M 'Free the temp mem block
  48.  
  49. SUB ScreenRestore (Image, X1, Y1, Array() AS STRING) 'coordinates of the screen to copy
  50.     y2 = Y1 + UBOUND(Array) - 1
  51.  
  52.     DIM M AS _MEM
  53.     M = _MEMIMAGE(Image) '
  54.     E = ConvertOffset(M.ELEMENTSIZE) 'How many bytes per pixel are in memory?  Screen 0 uses 2 bytes, 256 color screens use 1, 32-bit screens use 4
  55.  
  56.     length = LEN(Array(1))
  57.     Rows = (y2 - Y1 + 1) 'Number of rows to store
  58.  
  59.     count = 0
  60.     IF E = 2 THEN
  61.         FOR y = Y1 - 1 TO y2 - 1
  62.             count = count + 1
  63.             _MEMPUT M, M.OFFSET + (y * _WIDTH + X1) * E, Array(count) 'get the rows into memory starting from the proper offset
  64.         NEXT
  65.     ELSE
  66.         FOR y = Y1 TO y2
  67.             count = count + 1
  68.             _MEMPUT M, M.OFFSET + (y * _WIDTH + X1) * E, Array(count) 'get the rows into memory starting from the proper offset
  69.         NEXT
  70.  
  71.     END IF
  72.     _MEMFREE M 'Free the temp mem block
  73.  
  74.  
  75.  
  76. FUNCTION ConvertOffset&& (value AS _OFFSET)
  77.     DIM m AS _MEM 'Define a memblock
  78.     m = _MEM(value) 'Point it to use value
  79.     $IF 64BIT THEN
  80.         'On 64 bit OSes, an OFFSET is 8 bytes in size.  We can put it directly into an Integer64
  81.         _MEMGET m, m.OFFSET, ConvertOffset&& 'Get the contents of the memblock and put the values there directly into ConvertOffset&&
  82.     $ELSE
  83.         'However, on 32 bit OSes, an OFFSET is only 4 bytes.  We need to put it into a LONG variable first
  84.         _MEMGET m, m.OFFSET, temp& 'Like this
  85.         ConvertOffset&& = temp& 'And then assign that long value to ConvertOffset&&
  86.     $END IF
  87.     _MEMFREE m 'Free the memblock
  88.  

The Screen Information is stored in a REDIM array, which you use to pass the information back and forth between the two subs, which in this case is found near the top of the code with: REDIM Array(0) AS STRING.

Note, this should work in graphic modes just the same as it does for SCREEN 0, though I haven't tested it extensively.

I'm sorry it took so long for me get back to you.

Thanks for the code and REMarks you provided.  It's a little more than I need at the moment because my program always uses a SCREEN 0, 80 character width display, but I'm sure I can learn a lot from it for future projects.  I like the way that you and Luke both comment each line to explain exactly what it does and why it's needed.

There were a lot of articles you had posted back on [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there], one in particular that explained in great detail how the SCREEN 0 memory works -- (that 2 bytes are used for each character position, first byte = ascii value of character, and the second byte = the foreground and background colors).  I think that MOD could then be used to get those 2 values from that second, single byte.
That article was a lot of help when I had to manually calculate the 'offset' and 'length' variables needed when I was using the older BSAVE, BLOAD method to transfer screen data.  As a matter of fact, I'm still using the older 'offset' and 'length' variables _as_part_of_ the newer _MEM command(s) method.

It would be nice if those old acticles could be found and restored here at qb64.org if/when they are made available from [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there] because I'm sure that lots of other people would find them interesting and useful.

Oh, and thanks again for getting the problems with VAL fixed a few years ago.  That was one of the first bugs I ever reported way back in the SDL days, and it just so happens that this program I'm working on right now is the same one I was using when I noticed the problems with VAL.

Stuart

4
QB64 Discussion / Re: Help needed with one or more _MEM commands
« on: February 07, 2019, 05:57:54 am »
If you're only changing the vertical height this isn't too hard:
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(80, 25, 0)
  2. FOR i = 1 TO 10
  3.     PRINT STRING$(i, "*")
  4.     COLOR i
  5.  
  6. character_count = _WIDTH * 10 'save 10 lines worth of characters
  7.  
  8. DIM saved AS _MEM
  9. m = _MEMIMAGE(0) '_mem reference to the display
  10. saved = _MEMNEW(m.ELEMENTSIZE * _WIDTH * 10) 'buffer to save data in
  11. _MEMCOPY m, m.OFFSET, m.ELEMENTSIZE * character_count TO saved, saved.OFFSET 'copy screen -> buffer
  12.  
  13. SCREEN _NEWIMAGE(80, 30, 0)
  14. m = _MEMIMAGE(0) 'we are now displaying a new screen, do get a new reference to it
  15. _MEMCOPY saved, saved.OFFSET, m.ELEMENTSIZE * character_count TO m, m.OFFSET 'copy buffer -> screen
  16.  
  17. _MEMFREE saved
But if you're changing the width (characters per line) or you only want to save part of a line it'll be a little more complicated because you're no longer dealing with a contiguous block of memory. At this point (or even before) consider if it isn't just easier to save the data to an array.


Thanks for your reply.  I'm sorry it took so long for me get back to you.

I did think about using an array at one time to hold the screen data which would have eliminated the unwanted disk activity when using BSAVE, BLOAD and KILL, but I was also thinking about all of the (up to 7680) PEEKs and POKEs, etc... and it seemed like it would be such a long and drawn out process that it might end up looking too flashy, so I never even bothered to try it that way.

I was able to use the code you provided to do exactly what I wanted, with a few small changes to make allowances for the _original_ 'offset' and 'length' variables that I was using for the SCREEN 0 memory segment at &HB800 (which was originally used by BSAVE and BLOAD).

Here's what I came up with :

           LN = CSRLIN
          _DELAY .001: offset = (LN - 48) * 160 '(originally used with BSAVE -- based on DEF SEG = &HB800)
           _DELAY .001: IF offset < 0 THEN offset = 0 ELSE LN = 48
           _DELAY .001: length = LN * 160
''''''''(originally used with BSAVE -- same as m.ELEMENTSIZE * _WIDTH * LN)

_DELAY .001 'Thanks Luke, for all the help with the _MEM commands below...

          _DELAY .001: DIM m AS _MEM, saved AS _MEM
           _DELAY .001: m = _MEMIMAGE(0)
''''''''This is the _MEM reference to the display.
          _DELAY .001: saved = _MEMNEW(length) 'This is the buffer to save data in.
           _MEMCOPY m, m.OFFSET + offset, length TO saved, saved.OFFSET 'Copy (up to) the first 48 of the _last 50_ lines of screen data to the buffer.
          _MEMFREE m

           GOSUB 1400
           _DELAY .001: m = _MEMIMAGE(0) '''''''''''''''''''''''We are now displaying a new screen, so get a new reference to it.
           _MEMCOPY saved, saved.OFFSET, length TO m, m.OFFSET 'Copy from the buffer to the new screen.

           _MEMFREE saved
           _MEMFREE m



Red   -- original code -- (used with the older BSAVE and BLOAD method)
Green -- new QB64 code -- (replaces the older code and doesn't cause unwanted disk activity)
Black -- always used
Blue  -- all REMarks

Note :  The "_DELAY .001" at the beginning of a few lines is used only because the program that this code is for was written in such a way that it could be loaded using either QB64 _or_ QuickBASIC 4.5. Any line that begins with an underscore will be ignored completely by QB4.5 instead of being partially loaded, causing errors, and requiring a lot of manual editing to get it working again.  Also, some of the lines are only needed for features that are available in QB64, so those lines don't get loaded by QB4.5 in order to conserve memory.

Thanks again for providing this code and the remarks; it's certainly made it a lot easier for me to understand how the _MEM commands are implemented and used together.

Stuart

5
QB64 Discussion / Help needed with one or more _MEM commands
« on: January 31, 2019, 03:19:56 am »
Basically, the program I've been working on uses a SCREEN 0 text screen that is always a minimum of 80 characters x 50 lines, and could conceiveably be as large as 80 chars x 200 lines when using QB64.  The usual size is between 66 and 130 lines depending on the screen resolution, available desktop space and _FONT used.


Here's the problem : 

I'm currently using the code below to BSAVE a copy of a certain segment of the video memory for SCREEN 0 which has already been calculated using the 'offset' and 'length' variables.

Next, the subroutine at line 1400 resets the screen size to either a 50 line screen (using a different _FONT), or...  a more than 50 line screen.  The actual number of lines will vary as described above.

After the new SCREEN 0 text screen has been established at 1400 (using the WIDTH command), the new screen will be blank, so the BLOAD statement is used to write the previously saved screen data to the beginning segment of the new SCREEN 0 video memory at &HB800 and then the KILL command deletes the temporary file that was used.

Code: QB64: [Select]
  1.            LN = CSRLIN
  2.            offset = (LN - 48) * 160: length = LN * 160
  3.            IF offset < 0 THEN offset = 0 ELSE LN = 48
  4.            '
  5.            DEF SEG = &HB800
  6.            BSAVE "tmpscrn.tmp", offset, length
  7.            GOSUB 1400
  8.            BLOAD "tmpscrn.tmp", 0
  9.            DEF SEG
  10.            KILL "tmpscrn.tmp"
  11.  

Everything works just like I want it to, but...  I don't really like having to save and then delete a file from disk each time the routine is used.

I'm pretty sure that one or more of the _MEM commands can be used to do all of this in QB64, but even after reading the info here :  https://www.qb64.org/articles/articlemem.txt I just can't figure out exactly how to go about doing it.  I'm thinking that the BSAVE and BLOAD lines just need to be replaced with the proper variant of _MEM such as _MEMIMAGE and/or _MEMCOPY or _MEMGET and _MEMPUT, but who knows?

Thanks in advance for any help that can be provided.

6
QB64 Discussion / Re: Q
« on: December 24, 2018, 06:45:46 am »
I had an odd occurance though, I ran the following code in QB45,
Code: QB64: [Select]
  1. hello: if inkey$<>chr$(27) then hello
  2.  
  3. sub Hello
  4. print hellob
  5.  

the first time I ran this, It hung. it treated the "THEN HELLO" as a "goto hello" and waited until i pressed ESC
but the second time and then on it treated the THEN HELLO as a sub call and printed 0 and quit on its own. I had to restart DOSBOX to cause it to repeat this and then only randomly. might be an error with my copy of dosbox.

This runs without any problems when I use QB4.5 -- "THEN HELLO" is always treated as a SUB call.
NOTE :  When using QB4.5, "GOTO" is optional with a line number but is _required_ with a line label.


now I havent used GOTO since GWBasic and then only rarely,so why can't I do this,

Code: QB64: [Select]
  1. hello: if inkey$<>chr$(27) then hello
  2.  
  3. sub Hello
  4. GOTO hello
  5.  
That one says "Label not defined"

The reason for that is because you can't use GOTO, GOSUB, or RETURN to enter or exit a subprogram.
The label that you want to GOTO is required to be _inside_ the SUB.


BUT
Code: QB64: [Select]
  1. hello: if inkey$<>chr$(27) then hello
  2.  
  3. sub Hello
  4. hello:
  5. GOTO hello
  6.  
that one says "duplicate label"

That's because the same name for a label was used in the module-level code.
Each line number or label in a module is _required_ to be unique -- including all the SUB and function definitions in the module.

7
Fooling around a little with Win API... I hope the wife doesn't find out. So, coincidence or does this code actually work...

Yes!  I added your code to the top of my sample program, made changes on two lines, and it works perfectly.

Now, if one of the developers could incorporate this into QB64.exe (at least for the Windows part of the code) then the _DESKTOPWIDTH and _DESKTOPHEIGHT commands would work a lot better.

Code: QB64: [Select]
  1.     FUNCTION GetSystemMetrics& (BYVAL Index AS _OFFSET)
  2.  
  3. REM xResult& = GetSystemMetrics&(0)
  4. REM yResult& = GetSystemMetrics&(1)
  5. REM PRINT xResult&; "x"; yResult&
  6.  
  7.  
  8.  
  9.  
  10.  
  11. PRINT "The desktop resolution when this program was started    :";
  12. '''''PRINT _DESKTOPWIDTH; "x"; _DESKTOPHEIGHT
  13. PRINT GetSystemMetrics&(0); "x"; GetSystemMetrics&(1)
  14.  
  15.  
  16.    PRINT
  17.    PRINT "Change to a different screen resolution and then"
  18.    PRINT "press <ENTER> to update the info...  ";
  19.    DO
  20.       _LIMIT 30
  21.    LOOP WHILE INKEY$ <> CHR$(13)
  22.    PRINT "current resolution :"; '''''_DESKTOPWIDTH; "x"; _DESKTOPHEIGHT
  23.    PRINT GetSystemMetrics&(0); "x"; GetSystemMetrics&(1)
  24.  

8
Now, whether that Width/Height is only calculated once at program start-up, or on the fly as needed, I honestly don’t know.

If your program requires detections for this type of thing, you may need to resort to using declare library with the windows api (or Linux/Mac equivalent).


Thanks for the quick response.

DECLARE LIBRARY and the Windows API are beyond my current programming capabilities...

It would be nice if Width/Height were calculated on the fly, but I can get by with it being calculated only at start-up since most people probably wouldn't be changing the screen resolution _after_ running a program anyway.

9
I'm not sure if this is a bug or if it's by design but when a QB64 program first starts, _DESKTOPWIDTH and _DESKTOPHEIGHT both return the correct values for the desktop size...

...However, if the desktop resolution is changed _after_ the program has been started, _DESKTOPWIDTH and _DESKTOPHEIGHT still return the same values as they did when the program was first started.

Code: QB64: [Select]
  1. PRINT "The desktop resolution when this program was started    :";
  2.  
  3.  
  4.    PRINT
  5.    PRINT "Change to a different screen resolution and then"
  6.    PRINT "press <ENTER> to update the info...  ";
  7.    DO
  8.       _LIMIT 30
  9.    LOOP WHILE INKEY$ <> CHR$(13)
  10.    PRINT "current resolution :"; _DESKTOPWIDTH; "x"; _DESKTOPHEIGHT
  11.  

10
QB64 Discussion / Blank lines appear sometimes when TAB is used.
« on: December 07, 2018, 09:48:43 am »
This problem was first reported back in October of 2015 on the [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there] forum, but I wanted to repost it here since [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there] isn't available anymore and new users of QB64 may not be aware of it.


It seems that TAB is using the "remaining spaces" info (_in addition to the "current POSition" info_) to determine if it needs to move to the next line before actually tabbing and printing.

Sometimes an extra blank line appears -- it all depends on what the current print POSition is (_and_ how many spaces are remaining on the line) when TAB is used.


The demo program below can be used to see the problem when using QB64.

QB64 and QB4.5 screenshots show what each output screen looks like.

Code: QB64: [Select]
  1. '********** This "TAB_bug" demo assumes an 80-column screen width. **********
  2. PRINT TAB(1287); "one" '''''''''''''''''''''''''''''''''no problem here
  3. PRINT TAB(255); "two" ''''''''''''''''''''''''''''''''''no problem here
  4. PRINT TAB(-5); "three" '''''''''''''''''''''''''''''''''no problem here
  5.  
  6. PRINT "1234567890123456789"; TAB(20); "-four-" '''''''''no problem here
  7.  
  8. PRINT "12345678901234567890"; TAB(20); "five" ''''''''''no problem here
  9.  
  10. PRINT "123456789012345678901234567890123456789012345678901234567890"; TAB(20); "six" ''''''''no problem here
  11.  
  12. PRINT "1234567890123456789012345678901234567890123456789012345678901"; TAB(20); "seven" '''''An extra blank line is printed here!
  13.  
  14. PRINT "0        1         2         3         4         5         6         7         8"
  15. PRINT "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
  16.  
  17. PRINT "TAB(20) is used before the words '-four-', 'five', 'six', and 'seven'."
  18. PRINT "QB64 prints a blank line before the word 'seven', but QB4.5 doesn't..."
  19. PRINT "Note that the line before 'seven' has only 19 spaces remaining at the"
  20. PRINT "end -- so it seems that TAB is also using the 'remaining spaces' info"
  21. PRINT "in addition to the 'current POSition' info to determine if it needs to"
  22. PRINT "move to the next line (which it does 2 times instead of just 1 time)."
  23.  
  24.  

  [ You are not allowed to view this attachment ]  

  [ You are not allowed to view this attachment ]  
  [ You are not allowed to view this attachment ]  

11
QB64 Discussion / ON KEY(n) is using ON TIMER(n)'s subroutine sometimes
« on: December 06, 2018, 02:53:06 pm »
This problem was first reported back in May of 2014 on the [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there] forum, but I wanted to repost it here since [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there] isn't available anymore and new users of QB64 may not be aware of it.

ON KEY(n) and ON TIMER(n) both work, but if they are used together in the same program there _will_ be unexpected results.


For some reason, after the "ON TIMER(n)" statement has been used and then "TIMER ON" activates it and then "TIMER OFF" disables it, the subroutine that it uses gets called by the "ON KEY(n)" statement instead of the subroutine that "ON KEY(n)" is supposed to use.

I am including an example program that demonstrates this odd behavior if anyone wants to check into it.

The example program works in QB4.5 without any problems, but QB64 has a problem with it.

Basically, if/after ON TIMER(n) GOSUB is used, then : 
After TIMER ON (and then TIMER OFF) is used XX number of times, then
ON KEY(n) will use the ON TIMER(n) subroutine XX number of times before
it starts to use it's own subroutine.

I'm currently running Windows XP Home Edition SP3 (using QB64GL version 1.2) and I've also tested this as far back as SDL version 0.954 and it has the same problem.


As I recall, back in 2014, the verdict was that there IS a problem BUT the section of code that handles these events was written by Galleon and he would have to check into it himself.


Code: QB64: [Select]
  1.    'ON TIMER will be used to erase a message
  2.    'five seconds after it has been printed.
  3.    '
  4.    ON TIMER(5) GOSUB 5000
  5.  
  6.  
  7.  
  8.    'Set up "K" to use the ON KEY(n) statement.
  9.    '
  10.    KEY 15, CHR$(&H0) + CHR$(&H25) '<K>
  11.    ON KEY(15) GOSUB 6000
  12.    KEY 16, CHR$(&H20) + CHR$(&H25) '<NUMLOCK> + <K>
  13.    ON KEY(16) GOSUB 6000
  14.    KEY 17, CHR$(&H40) + CHR$(&H25) '<CAPSLOCK> + <K>
  15.    ON KEY(17) GOSUB 6000
  16.    KEY 18, CHR$(&H60) + CHR$(&H25) '<NUMLOCK> + <CAPSLOCK> + <K>
  17.    ON KEY(18) GOSUB 6000
  18.  
  19.  
  20.  
  21.    KEY(15) ON: KEY(16) ON: KEY(17) ON: KEY(18) ON
  22.  
  23.  
  24.  
  25.  
  26.  
  27.    SCREEN 0: WIDTH 80, 50
  28.    _FONT 14
  29.  
  30.    CLS
  31.    PRINT
  32.    PRINT
  33.    COLOR 15
  34.    PRINT "         THIS IS USED TO DEMONSTRATE A PROBLEM THAT EXISTS IN QB64 WHEN"
  35.    PRINT "         'ON TIMER' AND 'ON KEY' ARE USED TOGETHER IN THE SAME PROGRAM."
  36.    PRINT
  37.    PRINT
  38.    PRINT
  39.    COLOR 2
  40.    PRINT "    Press 'T' for a message to appear and a 5 second TIMER cycle to start."
  41.    PRINT
  42.    PRINT "    After 5 seconds the message is replaced and a counter will be updated."
  43.    PRINT
  44.    PRINT "    Do this 2 or 3 times and wait for the counter to update each time."
  45.    PRINT
  46.    PRINT
  47.    PRINT
  48.    COLOR 3
  49.    PRINT "    Next, press 'K' and a differnt message and counter SHOULD appear..."
  50.    PRINT
  51.    PRINT "    ...but the counter for the timer routine counts up INSTEAD."
  52.    PRINT
  53.    PRINT "    This will happen for as many times as 'T' was pressed earlier,"
  54.    PRINT "    and THEN the correct subroutine for 'ON KEY' will be used."
  55.    PRINT
  56.    PRINT
  57.    PRINT
  58.    COLOR 7
  59.    PRINT "        The steps above can be repeated without restarting the program."
  60.    PRINT
  61.    PRINT "        This demo works without any problems in QB4.5 but not in QB64."
  62.    PRINT
  63.    PRINT
  64.    PRINT
  65.  
  66.  
  67.  
  68.    COLOR 14
  69.    PRINT
  70.    PRINT
  71.    PRINT "Press 'T' to use the ON TIMER subroutine."
  72.    PRINT
  73.    PRINT "Press 'K' to use the ON KEY subroutine."
  74.    PRINT
  75.    PRINT "Press 'Q' to quit."
  76.  
  77.    LN = CSRLIN + 2
  78.  
  79.  
  80. 30 K$ = UCASE$(INKEY$)
  81.    IF K$ = "T" THEN GOSUB 100
  82.    IF K$ = "Q" THEN 200
  83.  
  84.    _LIMIT 10
  85.    GOTO 30
  86.  
  87.  
  88.  
  89.  
  90.     REM ----- (SUBROUTINE) -- Display a message and turn on the timer.
  91.     '
  92. 100 TIMER ON
  93.  
  94.     LOCATE LN, 1
  95.     COLOR 15, 4
  96.     PRINT " --> The TIMER ON command has just been used. ";
  97.     PRINT "                                              ";
  98.     PRINT " After 5 seconds the counter will be updated  ";
  99.     PRINT " and the TIMER OFF command will be used.      ";
  100.     COLOR 7, 0
  101.  
  102.     RETURN
  103.  
  104.  
  105.  
  106.  
  107.     REM -- Quit this program.
  108. 200 COLOR 7, 0: CLS: SYSTEM
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.      REM ----- (SUBROUTINE) -- for ON TIMER.
  119.      '
  120.      'Disable the TIMER and erase the message after 5 seconds is up.
  121.      '
  122. 5000 TIMER OFF
  123.  
  124.      TIMERnum = TIMERnum + 1
  125.      IF C = 10 THEN C = 15 ELSE C = 10
  126.      COLOR C
  127.  
  128.      LOCATE LN, 1
  129.      PRINT TAB(80); " "
  130.      PRINT "The TIMER OFF command was just used ---------> this counter ="; TIMERnum
  131.      PRINT TAB(80); " "
  132.      PRINT TAB(80); " "
  133.  
  134.      SOUND 1000, .4
  135.      RETURN
  136.  
  137.  
  138.  
  139.      REM ----- (SUBROUTINE) -- for ON KEY.
  140.      '
  141. 6000 KEYnum = KEYnum + 1
  142.  
  143.      IF CC = 11 THEN CC = 15 ELSE CC = 11
  144.      COLOR CC
  145.  
  146.      LOCATE LN + 5, 1
  147.      PRINT "You are in the ON KEY subroutine ------------> this counter ="; KEYnum
  148.  
  149.      SOUND 500, .4
  150.      RETURN
  151.  
  152.  

  [ You are not allowed to view this attachment ]  

Pages: [1]