Qbasicnews.com
April 05, 2020, 01:29:06 AM *
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: Random characters  (Read 1622 times)
Leprakon
Member
*
Posts: 42


« on: August 05, 2003, 06:36:45 PM »

lol, i could think of a good name for this thread...

anyway, here's my question- i made a program to get characters from the user, and randomly displays them on the screen 2147483648 times- i was origionally trying to do a sort of 'matrix intro' thing, with the green numbers and characters scrolling.

It was working just great until i added a way to exit the while loop ( IF (INKEY$ = "q") THEN GOTO ec ), when i added that, it still runs in the Qbasic editor, but when i make it a standalone .exe file, after about 5 seconds of running, the characters stop printing on the screen as fast as they had been. If i hit any key other than q, it speeds up again for the same interval of time. So my guess is that the inkey check is holding up the program?

Another thing of note is this line:

WHILE (endless& <= 2147483648#)  

i didn't put the # there- when i ran the program inside the editor, when i was done running it, the # was there- what's with that?



Here's the code in it's entirety, thanks for the help


CLS
SCREEN 0
COLOR 10, 0


PRINT "______________________________________"
PRINT "|------------------------------------|"
PRINT "|The Cascading Characters of Doom!!!!|"
PRINT "|------------------------------------|"
PRINT
INPUT "How many characters in the set"; char%

DIM choice$(char%)

FOR ctr = 1 TO char%
   
    CLS
    PRINT "______________________________________"
    PRINT "|------------------------------------|"
    PRINT "|The Cascading Characters of Doom!!!!|"
    PRINT "|------------------------------------|"
    PRINT "Enter character number "; ctr;
    INPUT " ", choice$(ctr)

NEXT ctr
     
                             
RANDOMIZE TIMER

endless& = 0
count& = 0

WHILE (endless& <= 2147483648#)

 count& = count& + 1
   
 IF (count& <= 80) THEN
  ran% = INT(RND * (char% - 1 + 1)) + 1
  PRINT choice$(ran%);
 END IF

 IF (count& > 80) THEN
  PRINT
  count& = 0
 END IF
 endless& = endless& + 1


IF (INKEY$ = "q") THEN GOTO ec

WEND
 

ec:
CLS
END
Logged
xhantt
Member
*
Posts: 90



« Reply #1 on: August 05, 2003, 08:52:47 PM »

Quote from: "Leprakon"
lol, i could think of a good name for this thread...


I'll put "Matrix intro"

Quote
anyway, here's my question- i made a program to get characters from the user, and randomly displays them on the screen 2147483648 times- i was origionally trying to do a sort of 'matrix intro' thing, with the green numbers and characters scrolling.

It was working just great until i added a way to exit the while loop ( IF (INKEY$ = "q") THEN GOTO ec ), when i added that, it still runs in the Qbasic editor, but when i make it a standalone .exe file, after about 5 seconds of running, the characters stop printing on the screen as fast as they had been. If i hit any key other than q, it speeds up again for the same interval of time. So my guess is that the inkey check is holding up the program?


I try it, but it just run fine.

Quote
Another thing of note is this line:

WHILE (endless& <= 2147483648#)  

i didn't put the # there- when i ran the program inside the editor, when i was done running it, the # was there- what's with that?


Note that 2147483648 = 2^32, so it isn't a long. The range of long is -2^32...2^32-1. Qb know that and append the #.
Logged
Leprakon
Member
*
Posts: 42


« Reply #2 on: August 06, 2003, 09:19:45 AM »

did you run it in a window, or full screen?? it works correctly in the window, but it full screen, it has issues..
Logged
xhantt
Member
*
Posts: 90



« Reply #3 on: August 07, 2003, 12:48:58 AM »

I run in fullscreen under win98, compiled with qb45.
Logged
Phydaux
Senior Member
**
Posts: 200



« Reply #4 on: August 07, 2003, 07:55:57 AM »

Quote from: "Leprakon"

  ran% = INT(RND * (char% - 1 + 1)) + 1
  PRINT choice$(ran%);

Umm...  Firstly -1+1 = 0 so
Code:
ran% = INT(RND * (char% - 1 + 1)) + 1
is the same as
Code:
ran% = INT(RND * char%) + 1

and if you want random characters you could use the code
Code:
PRINT CHR$(INT(RND*222)+33)

It prints all the characters in the range 33-254 Smiley
Logged

url=http://www.spreadfirefox.com/?q=affiliates&id=60131&t=79][/url]
END OF LINE.
Mac
Senior Member
**
Posts: 243


WWW
« Reply #5 on: August 10, 2003, 11:22:39 PM »

Why didn't you look at the answers to your post here: http://www.network54.com/Hide/Forum/message?forumid=13959&messageid=1060115167

Mac
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!