Google
ResExcellence www


Main Sections
ATM Replacements
Application Splashes
Applescripts/Scripting
Clocks
Desktop Pictures
Explorer Splashes
GUI Software
Icons
Interarchy Interfaces
Linux Icebox
Makeovers & Skins
MacOS Startups
Netscape Splashes
Previous Edits
Previous Edits X
Snapshots
Throbbers
User Forum

Problems?
Files are in StuffIt 5 format (free download).
Tell me about a bad link (Thanks!).
Submission Policy

Using Chipmonk Basic to Manipulate Text Files by Michael Coyle

The ResExcellence Reader Survey has generated hundreds of responses. The form emails the readers selections in the following form: Item name: response. A typical email is shown below:

Email: coyle@ResExcellence.com
RATE: 10
SECTION1: XTIPS
SECTION2: DESKTOPS
SECTION3: RESEDIT
SECTION4: THROBB
SNAPSHOTS: NO_PREF
SPEED: MODEM
CLICKER: YES
PURCHASE: YES
EDUCATION: COLLEGE
STUDENT: FULL
PROGRAMER: NO
DESIGNER: DECLINE
AGE: 31-40
GENDER: MALE

This text needs to be cleaned up. All I need are the answers, not the item name. In order to import the responses into a database, I would like a 'comma delimited' text file with one record per line. For example, the above email response would become:

coyle@ResExcellence.com, 10, XTIPS, DESKTOPS, RESEDIT, THROBB, NO_PREF, MODEM, YES, YES, COLLEGE, FULL, NO, DECLINE, 31-40, MALE

I've been using BASIC for jobs like this since my dbase II days on an old DOS machine so Chipmonk Basic was a comfortable choice.

In Eudora, all the survey responses I have received to date were transferred to their own mailbox. I then selected them and saved the mailbox as one large text file, one email right after the next.

My methodology to attack the data is to input a line of text from the file and examine the first few letters to see what the item is. Then I switch to the right side of the line and working backward, one character at a time, I move from right to left looking for the blank space before the response.

Once I have found a blank-space, everything to the right is the response.

Once I have found the text I want, I will open a new file and output the record with each response separated by a comma.

Below is the entire program. Explanation follows...

100 clear
200 open "SFGetFile" for input as #1
225 open "Survey.out" for output as #2
300 while ( not eof )
310 line input #1,a$
312 if left$(a$,5) = "Email" then gosub 2000
315 if left$(a$,4) = "RATE" then rate$ = clean_it$(a$) : print #2,rate$ ", ";
320 if left$(a$,8) = "SECTION1" then sec1$ = clean_it$(a$) : print #2,sec1$ ", ";
325 if left$(a$,8) = "SECTION2" then sec2$ = clean_it$(a$) : print #2,sec2$ ", ";
330 if left$(a$,8) = "SECTION3" then sec3$ = clean_it$(a$) : print #2,sec3$ ", ";
335 if left$(a$,8) = "SECTION4" then sec4$ = clean_it$(a$) : print #2,sec4$ ", ";
340 if left$(a$,4) = "SNAP" then snap$ = clean_it$(a$) : print #2,snap$ ", ";
345 if left$(a$,5) = "SPEED" then speed$ = clean_it$(a$) : print #2,speed$ ", ";
350 if left$(a$,5) = "CLICK" then click$ = clean_it$(a$) : print #2,click$ ", ";
355 if left$(a$,8) = "PURCHASE" then purchase$ = clean_it$(a$) : print #2,purchase$ ", ";
360 if left$(a$,4) = "EDUC" then edu$ = clean_it$(a$) : print #2,edu$ ", ";
365 if left$(a$,4) = "STUD" then stud$ = clean_it$(a$) : print #2,stud$ ", ";
370 if left$(a$,4) = "PROG" then prog$ = clean_it$(a$) : print #2,prog$ ", ";
375 if left$(a$,4) = "DESI" then design$ = clean_it$(a$) : print #2,design$ ", ";
380 if left$(a$,3) = "AGE" then age$ = clean_it$(a$) : print #2,age$ ", ";
385 if left$(a$,4) = "GEND" then gender$ = clean_it$(a$) : print #2,gender$
390 wend
398 close #1 : close #2
399 end
2000 rem---- Special situation to check for an email.
2002 rem---- Takes into account a reader may not have entered an email
2010 cls : print "Printed :" x : x = x+1
2050 if len(a$) = 7 then email$ = "none" : print #2,email$ ", "; : return
2100 email$ = clean_it$(a$) : print #2,email$ ", ";
2999 return
3000 rem---- Takes the line of input and cleans it up by
3002 rem---- looking for the first space from the right.
3050 sub clean_it$(b$)
3100 len_of_as = len(b$)-1 : moving$ = "set to something NOT a space."
3200 while (moving$ <> " ")
3300 moving$ = mid$(b$,len_of_as,1)
3400 len_of_as = len_of_as-1
3500 wend
3550 first_let = (len(b$))-len_of_as-1
3560 clean$ = right$(b$,first_let)
3999 return (clean$)

Line 100 clears the window and 200's open two files, one for input, one for output.

Lines 300-399 read a line of text from the input file and depending on the first few characters, clean it up, and output it to a text file followed by a comma.

Lines 2000-2999 look for the special condition of a reader not providing his/her email address.

And lines 3000-39999 do the hard work of scanning the line starting at the right and looking for a space.

The resulting file, Survey.out, is now ready to be imported into a database for manipulation. Here are some test files for you to experiment with: Sample survey data (no email addresses), and the BASIC test file.

A simple BASIC interpreter like Chipmonk Basic won't give you the polished front end of REALBasic, but for simple text manipulation like the example above, it's cheap and fast.

Watch for more articles on processing the data from ResEx reader survey, the results of which will be posted upon completion.



Maintained by the Staff of ResExcellence. This entire site ©1997-2003 ResExcellence
Privacy Statement? Sure we gotta Privacy Statement.

[an error occurred while processing this directive]

[an error occurred while processing this directive] on the ResEx LinuxPPC Server