'=========================================================================== ' Subject: DATA STATEMENT COUNTER Date: 03-29-98 (22:04) ' Author: Tony L. Damigo Code: PB ' Origin: kvdojo@lightspeed.net Packet: PB.ABC '=========================================================================== DEFINT A-Z SCREEN 0,0,0 COLOR 7,1 CLS ' *********************** C O U N T D A T A ************************ ' ********************************************************************* ' A DATA Statement counter Code: Tony Damigo Date: 03-29-98 ' 100% PUBLIC DOMAIN : kvdojo@lightspeed.net ' ' PowerBasic 1.1 ' ' Purpose: Count the number of statements in a DATA BLOCK and return ' the total for dimensioning Arrays(). Allows you to add new ' statments on-the-fly. ' ' Disclaimer: I have tested this code and had no problems with it. ' I will assume no respondsibility for problems, or damages. ' Use this code at your own risk. bla! bla! bla! ;-) ' ' ********************************************************************* ' TRY THIS YOUR SELF ' ********************************************************************* ' Delete the lines below and try some data of your own, BUT remember ' to end the last DATA statment with a comma [,] and 2 [##] POUND signs. ' The three smsbles ,## act as a "end of data" (eod) marker. The (eod) ' must be used as the last piece of data in that "DATA BLOCK". ' ' <<< NOTE >>> ' If you fail to use the (eod) marker, CountData will attempt to count ' ALL YOUR DATA statements throughout the program (you don't want that!). ' ' <<< PUT YOUR STRING DATA HERE >>> USERLABLE1: DATA ,"<< This is the users DATA section >>",

, DATA To try out the,@R,,CountData,@B,,function,you need to erase the,"DATA" DATA ,"lines in the actual COUNTDAT.BAS (this file), add your own lines, ", DATA "and run this file again...",

,

, DATA "This function works with all statements, String and Numeric.",## ' --------------------------------------------------------------- ' <<< PUT NUMARIC DATA HERE >>> USERLABLE2: DATA 1,2,3,4,5,6,7,8,9,10,11,12,,13,14,15 DATA 200,300,400,500,600,700,800,900,1000 DATA 3.14,14.3,.012,6754321.999943,## ' --------------------------------------------------------------- GOSUB ScreenStuff ' ********************************************************************* ' ----------------- COUNTDATA FUNCTION --------------------- ' ********************************************************************* FUNCTION CountData ON LOCAL Error GOTO RDH1: LOCAL PTR1,PTR2, HALT$ PTR=0 : HALT$ = "##" : NUL$="" ' ---------------------------------- ' First try to read numeric data ' ---------------------------------- DO : READ NUL : INCR PTR LOOP RDH1: ' ---------------------------------- ' We set func to 0 for numeric data ' or set func to 1 and jump to RDH2 ' ---------------------------------- IF ERR=2 AND PTR=0 THEN ' STRINGS FUNC=PTR RESUME RDH2 ELSE ' NUMBERS FUNCTION=PTR RESUME RDH4 END IF RDH2: ' ---------------------------------- ' here we reset the error handler ' and retest for the string data ' ---------------------------------- ON LOCAL Error GOTO RDH3 PTR=0 DO: READ NUL$ INCR PTR IF (NUL$=HALT$) THEN FUNCTION=PTR GOTO RDH4 END IF LOOP RDH3: FUNCTION=PTR RESUME RDH4 ' ---------------------------------- ' The RDH4 lable below provides the ' the exit point for the function. ' ---------------------------------- RDH4: END FUNCTION ' ************************ END OF FUNCTION *************************** ScreenStuff: PTR=1 DO SELECT CASE PTR CASE 1 CLS GOSUB GETSCREEN DO : LOOP UNTIL INSTAT A$=INKEY$ PTR=0 CASE 0 CLS GOSUB UserStuff DO : LOOP UNTIL INSTAT A$=INKEY$ PTR=1 END SELECT IF A$=CHR$(27) THEN CLS : PRINT PRINT " Happy Codeing...." END END IF LOOP END GETSCREEN: ' ***************************************************************** RESTORE LABLE1 '<-------------- Restore data at lable REDIM D$(CountData) '<-------\ RESTORE LABLE1 '<-----\ \---- Get data count for array FOR X = 1 TO UBOUND(D$) '<---\ \ READ D$(X) ' \ \---- Restore data at lable NEXT X ' \ ' \---- Use UBOUND( array ) to '------------------------- ' to establish your upper ' ACT ON YOUR CODE HERE < limits. '------------------------- \ ' \ ' \ ' \------- Use you data as you wish ' I ues this gosub, get your own :-) GOSUB PrintStringData ' ****************************************************************** RESTORE LABLE3 REDIM D$(CountData) RESTORE LABLE3 FOR X = 1 TO UBOUND(D$) READ D$(X) NEXT X GOSUB PrintStringData RESTORE LABLE2 REDIM D$(CountData) RESTORE LABLE2 FOR X = 1 TO UBOUND(D$) READ D$(X) NEXT X GOSUB PrintStringData RESTORE LABLE4 REDIM D$(CountData) RESTORE LABLE4 FOR X = 1 TO UBOUND(D$) READ D$(X) NEXT X GOSUB PrintStringData RETURN UserStuff: RESTORE USERLABLE1 REDIM D$(CountData) RESTORE USERLABLE1 FOR X = 1 TO UBOUND(D$) READ D$(X) NEXT X GOSUB PrintStringData RESTORE USERLABLE2 REDIM D#(CountData) RESTORE USERLABLE2 FOR X = 1 TO UBOUND(D#) READ D#(X) NEXT X GOSUB PrintNumericData RESTORE LABLE2 REDIM D$(CountData) RESTORE LABLE2 FOR X = 1 TO UBOUND(D$) READ D$(X) NEXT X GOSUB PrintStringData RESTORE LABLE4 REDIM D$(CountData) RESTORE LABLE4 FOR X = 1 TO UBOUND(D$) READ D$(X) NEXT X GOSUB PrintStringData RETURN '-------------------------------------------------------------------- ' Nothing of any real value in this section :-( ' Just some minor formating junk for printing ' the data statment to the screen. PrintStringData: FOR X = 1 TO UBOUND(D$) SELECT CASE UCASE$(D$(X)) CASE "

" PRINT CASE "" PRINT PRINT SPC(5); CASE "" PRINT SPC(5); CASE "@R" 'RED COLOR 7,4 CASE "@B" 'BLUE COLOR 7,1 CASE "@D" 'WHITE COLOR 15,1 CASE ELSE PRINT D$(X);" "; END SELECT D$(X)="" NEXT RETURN PrintNumericData: LOCATE 12,1 FOR X = 1 TO UBOUND(D#) PRINT SPC(5);"[";D#(X);"]";, NEXT RETURN '-------------------------------------------------------------------- ' Here are the data statements used to generate EVERYTHING you see ' when run this file. Don't get sidetracked by the junk in < braces > ' it's only there for the purpose of formatting. It has NOTHING to do ' with the CountData function. LABLE1: DATA ,@D,"CountData Function [ Public Domain ]",@B DATA

,,HAVE,YOU,EVER,'mis-counted',the,"DATA",statments,to,be,placed DATA into,,an,ARRAY.,,You,"know,",what,I,mean,.....,

,,@D DATA "FOR X = 1",TO,[ ??,whatever, this,number,is ],,,READ,ARRAY(X) DATA ,,PRINT,ARRAY(X),,NEXT,X,@B,

,,Then,you,get,an,@R, DATA ERROR,-,OUT,OF,"DATA ",@B," message",because,you,forgot,to, DATA update,the,[ ??,count,number ],after,adding,more,"data.", DATA ,## 'DATA,## '<---\ ' \ ' \ [ NOTE ] ' \--- This is the (EOD), or "End Of Data" marker ' It must be the last data statement in each ' data block (convenience always has a price) ' LABLE2: DATA ,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,* DATA *,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,

,## LABLE4: DATA , DATA Press,@D,Esc,@B,to,"exit,",or,@D,ANY,@B,other,key,for,the,next,"page.",## LABLE3: DATA ,Well,"then,",this,little,FUNCTION,is,for,you.,,It,determines DATA the,amount,,of,ARRAY,SPACE,needed,before,you,read,the,"DATA," DATA and,you,can,update,,your,statements,on,the,fly,":-)", DATA "Actually,",it,"pre-reads",a,"DATA",BLOCK,,then,returns,an,acount DATA of,statements.,,!! Examine,the CODE !!,

,,BY,the,"way,",the DATA information,you've,been,reading,came,form,individual,,"DATA" DATA statements,accessed,by,the,@D,COUNTDATA,@B,function.,

,##