'=========================================================================== ' Subject: TIP OF THE DAY CGI PROGRAM Date: 06-06-99 (09:11) ' Author: The ABC Programmer Code: BEC ' Origin: voxel@edmc.net Packet: BASEC.ABC '=========================================================================== '-- TIPS.BAS for BASEC v0.20 by William Yu [June 1, 1999] ' '-- Tip of the Day CGI Program tested under Linux/Unix server '-- Not really "the day," more like, whatever I can find... '-- In this example, I'm listing all tips in the data.txt file. '-- You can use RND to randomly select one. '-- 2 things before you can get going: '-- 1. Create data.txt in your cgi-bin directory '-- 2. chmod 666 data.txt ' '-- This is a good example of how you can read text files. '-- You'll notice that BOTH Read/Write on the file must be SET (chmod 666)! '-- That is a flaw in the BASEC language, since any BINARY file is open '-- for reading and writing. '-- If you really wanted to, you can pretty much write a very nice, '-- but slow, search engine from this example and using the "Simple CGI '-- Form Parser" example from BASEC.ABC ' Example DATA.TXT file ' ' 2 ' Tip 1: Hello World! ' Tip 2: I forget... DIM NUM AS LONG DIM A$ AS STRING DIM I AS INTEGER OPEN "B", 1, "data.txt" '-- The first value is the number of lines/tips in the data.txt file. '-- You have to hard code (type) that in, no error checking... '-- Obviously you can modify this program to avoid using this method. A$ = SPACE$(20) GET #1, , A$ I = INSTR(A$, CHR$(10)) '-- Grab the number SEEK #1, I + 1 '-- Points to first tip... A$ = LEFT$(A$, I - 1) NUM = VAL(A$) '-- Why waste... DIM Lines(1 TO NUM) AS STRING GOSUB GetLines CLOSE #1 PRINT "Content-type: text/html" PRINT : PRINT "" PRINT "
" PRINT "Tip of the Day

" FOR I = 1 TO NUM PRINT Lines(I) + "
" '-- All tips are listed, you can change this NEXT I PRINT "
" PRINT "" END GetLines: '' Cheap cheap cheap, BASEC has no LINE INPUT command I = 1 WHILE I <= NUM IF EOF(1) THEN RETURN '' Really cheap, can't attach to WHILE... A$ = SPACE$(1) GET #1, , A$ IF A$ = CHR$(10) THEN I = I + 1 ELSE Lines(I) = Lines(I) + A$ END IF WEND RETURN