QB / QB64 Discussion Forum      Other Subforums, Links and Downloads
 

 Return to Index  

This writes the ASCII values to files :D

March 17 2006 at 10:56 PM
KristopherWindsor  (Login KristopherWindsor)


Response to Fun challenge - 'Hello World'

 

This creates a directory, and then makes a different file for each ASCII character in the string. But it only writes the files the first time, so I think it loses for the "Most Inefficient" award. :P


'Say Hi! Version 1.0
'(C) 2006 Kristopher Windsor

SCREEN 0: WIDTH 80, 25: CLS : RANDOMIZE TIMER: ON ERROR GOTO handling

CHDIR "C:\sayhi" 'this begins handling
OPEN "C:\sayhi\index.txt" FOR INPUT AS #1: INPUT #1, c: CLOSE #1
DIM d(1 TO c)

FOR a = 1 TO c
OPEN LTRIM$(STR$(a)) + ".txt" FOR INPUT AS #1: INPUT #1, e: CLOSE #1
d(a) = e
NEXT a

FOR a = 1 TO c
LOCATE 2, a + 2: PRINT CHR$(d(a))
NEXT a

FOR a = 1 TO 10000
LOCATE INT(RND * 20) + 4, INT(RND * 78) + 1: PRINT CHR$(SCREEN(2, 3 + INT(RND * c)))
NEXT a
SYSTEM

handling:
s$ = "Hello, World!" 'doesn't assign 2 variable on second run-reads from file instead
SELECT CASE ERR
CASE 53 'creates files if the index is missing
OPEN "index.txt" FOR OUTPUT AS #1: WRITE #1, LEN(s$): CLOSE #1
FOR a = 1 TO LEN(s$)
OPEN LTRIM$(STR$(a)) + ".txt" FOR OUTPUT AS #1
WRITE #1, ASC(MID$(s$, a, 1)): WRITE #1, "This Number is (C) 2006 i-TECH"
WRITE #1, "Illegal Redistribution Will Get You in Jail!": CLOSE #1
NEXT a
CASE 76 'makes directory if it's missing
MKDIR "C:\sayhi"
CASE ELSE
PRINT "Error ", ERR: SYSTEM
END SELECT
RESUME

 
 Respond to this message   
 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement