BBS: Inland Empire Archive Date: 03-21-93 (12:53) Number: 205 From: QUINN TYLER JACKSON Refer#: NONE To: ALL Recvd: NO Subj: Unofficial FAQ 2.0 4/ Conf: (2) Quik_Bas
>>> Continued from previous message =======>8 SAMPLE 1.0 ENDS HERE 8<========= Q2.2 I'm having trouble reading the communications buffer properly. Things seem to be clipping off the end. What's happening? A2.2 This is not an uncommon problem with beginning, and sometimes intermediate programmers. Even with communications error-trapping, it is possible, even probable, that the comm buffer will have more than one byte in it when the communications handler is called by the ON COM(n) statement. The way to empty the buffer COMPLETELY whenever the handler is called is to use the LOF(n) statement, since with communications, LOF(n) signifies how many bytes are waiting in the buffer. Here is an example that would work in a program that had the statement ON COM(1) GOTO BufferFlush and the COM1 port opened with the handle #1. BufferFlush: AllTheBytes$ = INPUT$(#1, LOF(1)) This reads ALL the bytes from the buffer, not just the first byte. Q2.3 I want to be able to compile a program that scans a file for a given words and returns the number of times that word occurs. Thing is, I want to be able to just type COUNT /FILENAME.EXT /WORD on the command line. How do I get my QuickBASIC program to recognize the command line parameter I have supplied? A2.3 In QuickBASIC and above, there is a system variable called COMMAND$ that contains an uppercase representation of what was entered at the command line. A bit of source from Microsoft that parses the command line and returns its parts in an array: S2.0 COMLINE.BAS DEFINT A-Z 'SUB procedure to get command line and split into arguments. 'Parameters: NumArgs : Number of command line args found. ' Args$() : Array in which to return arguments. ' MaxArgs : Maximum number of arguments array can return. STATIC SUB Comline (NumArgs, Args$(), MaxArgs) CONST TRUE = -1, FALSE = 0 NumArgs = 0: In = FALSE 'Get the command line using the COMMAND$ function. Cl$ = COMMAND$ L = LEN(Cl$) 'Go through the command line a character at a time. FOR I = 1 TO L C$ = MID$(Cl$, I, 1) 'Test for character being a blank or a tab. IF (C$ <> " " AND C$ <> CHR$(9)) THEN 'Neither blank nor tab. Test if you're already inside an argument. IF NOT In THEN 'You've found the start of a new argument. 'Test for too many arguments. IF NumArgs = MaxArgs THEN EXIT FOR NumArgs = NumArgs + 1 In = TRUE END IF 'Add the character to the current argument. Args$(NumArgs) = Args$(NumArgs) + C$ ELSE 'Found a blank or a tab. 'Set "Not in an argument" flag to FALSE. In = FALSE END IF NEXT I END SUB =======>8 SAMPLE 2.0 ENDS HERE 8<========= Q2.4 Hey! Thanks a lot! Now, suppose I have another question for you? A2.4 Well, my next QUIK_BAS FAQ will deal with different file access methods in BASIC. You could wait for that to be posted in about a month. Or, you can contact me via netmail at 1:153/151. Just make sure that the first line of your netmail says: "I, ____________, agree that I will not hold Quinn Tyler Jackson or JackMack Consulting & Development resonsible for any advice he gives me about QUIK_BAS or programming in general. In return for his not asking to be paid for his advice, I waive my right to legal recourse." Or, you may want to write me via post at: ATT: Ask Doctor JackMack JackMack Consulting & Development, #302-9085 Gildwood Drive, Burnaby, British Columbia V3N 4L9 CANADA Be sure that the above waiver is included with your question. The waiver is only necessary because consultants are responsible for their advice, whether or not the advice was paid for, and since liability insurance costs money, I cannot allow recourse against me or my company for advice that does not earn enough money to pay for the insurance. END OF QUIK_BAS FAQ2.0 * OLX 2.1 TD * QUIK_BAS FAQ 2.0 --- Maximus/2 2.01wb * Origin: The Nibble's Roost, Richmond BC Canada 604-244-8009 (1:153/918)
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET