Basic Building Blocks is a collection of QuickBasic subprograms and assembler routines that I created and use for my own program development as a self-employed programmer. I try to make them as small, fast, and efficient as is practical, and sometimes I even go way past being practical and stray into fanatical. All routines come with fully documented source code. I have made a special effort to provide clean, clear, and complete documentation within each source module itself. I don't like having to reach for a manual every time I need to check the syntax or function of a routine, so I did away with the manual. Everything you need to know about a routine is in it. I do like code that is educational and teaches good programming techniques by example. There is as much art in creating a descriptive narrative as there is in creating efficient computer code. I try to do both. To order the Basic Building Blocks diskette, complete the following form (please print legibly) and send it with $35 to: Martin Systems 120 Fence Post Court Fountain, CO 80817 Diskette type: [ ] 360K [ ] 720K Your name ___________________________________________________________ Address ___________________________________________________________ City ___________________________ State _______ Zip __________ Phone (______)___________________ Current version: 1.01 Supports QuickBasic versions 3.0, 4.0, 4.5 Free updates are available for a one year period after the purchase date, either by mail or modem. By mail, send a blank, formatted diskette and a self-addressed, stamped diskette mailer (or send $4 and I'll provide the diskette, mailer, and stamps). By modem, call (719) 382-8216 to reach the BBS (2400 baud, N81). If you think of a routine that would be a useful addition to this package, please tell me and I will consider creating it. I have several planned already, which is why I'm offering the free updates to initial purchasers. A simple example of the format used for all routines is shown below: ---------------------------- Begin CENTER.BAS ---------------------------- 'Purpose: Centers text (or any other string) on screen. ' ' Syntax: call CenterText (text$, row) ' ' Pass: text$ String to center on screen. ' row Row where string will display. ' 'Returns: nothing ' ' Note: Row should be 1 to 25. String length should be <= 80. ' Screen width is assumed to be 80 characters. Initial ' cursor position is unchanged. Color used for display ' is current color. ' defint a-z sub CenterText (text$, row) static OldRow = csrlin : OldCol = pos(0) 'save current cursor position locate row, 41 - (len(text$)+1) \ 2 'place cursor where printing begins print text$; 'display the text on-screen locate OldRow, OldCol 'restore initial cursor position end sub ----------------------------- End CENTER.BAS ----------------------------- List of current Basic Building Blocks routines (5/11/92): BAS file Syntax and Use --------- -------------- BITS call ChkBit (BitArray(), BitPos, BitOn) call SetBit (BitArray(), BitPos, BitValue) call ToggleBits (BitArray()) call CountSetBits (BitArray(), MaxBit, Count) call FindNextBit (BitArray(), BitPos, BitValue, Direction, Found) Collection of routines to manipulate individual bits in an integer array. BSEARCH call SearchStrArray (SearchStr$, Array$(), Rank(), ElementNum) Quickly searches any string array using pointers (binary search). CENTERQ call CenterText (Text$, row) Centers a string on-screen at the desired row. Uses PrintQ for fast screen writes. CHECKKB call CheckKB (WaitFlag, KeyPressed) Reads chrs from keyboard, optionally waiting for a key press. DATECNV call ConvertDate (DateStr$, NumDays, WeekDay) call RestoreDate (NumDays, DateStr$) Facilitates date arithmetic. DELAY call Delay (DelayTime!) Produces a timed delay, regardless of computer speed. DOTPROF call DotProfile (LowVal, HighVal, StepVal, StepLen, Score!, Graph$) Draws a text-based, horizontal graph (like a thermometer graph). DRAWBOXQ call DrawBoxQ (ulr, ulc, lrr, lrc, BoxChar, BoxColor) Draws a box frame on-screen. Uses PrintQ for fast screen writes. GETCOLOR call GetColor (CurrentAttr) Returns the current COLOR setting. GETFIELD call GetField (row, col, MaxLen, FillChr, Text$, CrsrPos, EditCode) Replaces INPUT statement with full editing and re-entrancy. Uses PrintQ for fast screen writes. HEADER '$include: 'header.bas' Convenient first line for modules, sets constants. INSSTR call InsStr (MainStr$, FindStr$, ReplaceStr$, Found) A find & replace utility for text strings. MENUBOXQ call MenuBoxQ (choice$(), prompt$(), BoxChr, Colors(), Flags, MenuChoice) Displays a scrolling, bounce bar menu with item prompts. Uses PrintQ for fast screen writes. MSGBOXQ call MsgBoxQ (message$(), TextColor, BoxChar, BoxColor, BoxWidth) Display a window containing a message. Uses PrintQ for fast screen writes. PARSE call Parse (Text$, Delimiter$, StartPos, SubStr$) General purpose re-entrant parser. SAVECRSR call PushCrsr (CrsrStack()) call PopCrsr (CrsrStack()) Used to save/restore cursor position & shape - may be nested 10 deep. STRIP call Strip (Text$, chr) Strips strings of unwanted leading and trailing chrs. SORT call SortStrArray (a$(), rank()) Sorts a string array using pointers. SORT_STR call SortFixedRecStr (RecStr$, RecLen, NumRec, rank()) Sorts fixed-length records in a record string using pointers. YESORNO call YesOrNo (KeyPressed) Asks for a Yes or No response from operator. ASM file Syntax and Use --------- -------------- CHNGCASE call ChngCase (Action, Text$) Converts a string to upper/lower case. CHNGCHRS call ChngChrs (Text$, FindChr, ReplaceChr) Replaces all matching chrs in a string. CHECKKB call CheckKB (WaitFlag, KeyPressed) Reads chrs from keyboard, optionally waiting for a key press. Desqview, Windows, and OS/2 aware - releases time slice when waiting for user input for optimal multitasking performance. CRSRINFO call CrsrInfo (Row, Col, Visible, StartLine, EndLine) Returns info about the cursor position, shape, and on/off status. CRYPT call Crypt (Text$, Password$, Action) Encrypts/decrypts any string. DISKINFO call DiskInfo (DriveLetter$, Bytes, Sectors, Clusters, ClustersFree) Returns free space, used space, total space for desired drive. EXIST Exist (FileName$, Found) Reports if a file currently exists. FILEINFO call FileInfo (FileSpec$, Found, Info$) Checks if a file exists and returns its attributes, size, and date/time stamp in a string. QB4+ only (uses long integers). GETCPU call GetCPU (ID) Returns the current CPU type - 8088, 80286, 80386, or 80486. GETFILES GetFiles (FileSpec$, DirList$) Read files names from a directory. GETPATH call GetPath (PathSpec$) Returns the default drive and directory. INTVAL call IntVal (r$, Integer) Fast replacement of VAL(r$) for integers only. MIDCHAR call MidChar (Text$, ChrPos, ChrCode) Returns ASCII code of any character in a string. Like QB's ChrCode = asc(mid$(Text$,ChrPos,1)), only faster! PAINTBOX call PaintBox (TRow, LCol, BRow, RCol, Attr) Changes the color of a rectangular area on-screen without erasing any text in the area. PRINTQ call PrintQ (Row, Col, Attr, Text$) Displays strings on-screen QUICKLY using direct screen writes. Desqview aware. PRINTQA call PrintQ (Row, Col, Attr, Text$) Displays strings on-screen QUICKLY using direct screen writes. Desqview aware. Can change colors on a per character basis using embedded attribute codes in Text$ PUTCHAR call PutChar (Text$, ChrPos, ChrCode) Replaces any character in a string. Like QB's mid$(Text$,ChrPos) = chr$(Chrcode), only faster! PTRINIT call PtrInit (NumElements, segment, offset) Fast way to set the integer pointer array used by the sort routines. REBOOT call ReBoot (BootType) Reboots the computer using either a warm or cold reboot. SCANSTR call ScanStr (StartPos, r$, ChrCode, Action, ChrPos) Search a string forwards/backwards for the next character match/ nonmatch. SCRLLBOX call ScrollBox (ULRow, ULCol, LRRow, LRCol, Action, ColorCode) Scroll or clear a rectangular area on-screen. SCRNSRA call ScrnSaveA (ULrow, ULcol, LRrow, LRcol, Segment, Offset) call ScrnRestA (ULrow, ULcol, LRrow, LRcol, Segment, Offset) Saves/restores a specified region of the display screen to an integer array in far memory. SCRNCOPY call ScrnCopy (Source, Destination) Saves/restores two entire screen displays using simplified parameters. STRSAVE call StrSave (r$, segment, offset) call StrRest (r$, segment, offset) Saves/Restores a string to far memory (an integer array). TESTPRN TestPrn (LPTPort, PrnOK) Reports if printer is on-line and ready. Utility programs Use ---------------- --- XQB4CAPS.BAS Converts those $@#! upper case QB4 keywords in your source code file to easier-to-read lower case, without affecting anything else. Source code included. XDOT.BAS Converts old-style variable names containing periods in your source file to variable names without periods. Example: old.style.name => OldStyleName Variable names using periods are so much easier to read, but Microsoft would like to see them used only for user-defined type fields. READPRN.BAS Reports the printer status for all three LPT ports. DISKINFO.BAS Reports hard drive partition sizes and percent free space. Demo programs -------------- Most routines are demonstrated with short, commented, example programs. About the author (Hugh Martin): Ever wonder about the people who do this kind of stuff? I do, so here's a bit about me. I earn my living as a computer programmer, consultant, and systems integrator. I'm have two kids (Miriam - Apr 87 and Eric - Jan 91), who are driving my wife and me crazy with their boundless energy. We are energetic ourselves, preferring to ski, bicycle, play tennis, or hike, but have been forced to put all that on low while we raise these little rascals . We all speak both French and English at home, though Miriam has discovered that English is much more universal in our neighborhood and is insisting on using it more and more, despite having learned French first. I'm a bit of a gourmet and like to grow my own vegetables because they taste so much better. I keep a trampoline in the back yard and use it regularly and expertly. Yes, like many computer people, I'm a little bit strange. My neighbors don't understand a grown man doing flips on a trampoline. I'm an independent soul, and enjoy forming my own opinions. When something breaks, I prefer to fix it myself, regardless of the time it takes, because I know I'll learn something, and probably do a better job than most repairmen. Learning, being independent, and doing the job right are major motivators for me. I am a critical observer, and pay close attention to details, but also tend to think globally. I'm betting man will destroy his own environment, but I'm basically an optimist. Gee, doctor, I feel a lot better now. How much do I owe you?