'=========================================================================== ' Subject: QUICKBASIC FAQ Date: 06/01/94 (00:00) ' Author: Mike Audleman Code: TEXT ' Origin: QUICKBASIC,FAQ Packet: FAQS.ABC '=========================================================================== The psudo, almost real, semi- ÉÍÍÍ» ÉÍ͸ ÉÍ͸ Ò ÉÍÍÍ» Ò ÉÍÍÍ» Ò º º Ì͵ Ì͵ º º º ÌÍÍ͹ º º º º º º º º º º º ÈÍÍͼ Ð Ð Ð ÈÍÍͼ Ð Ð Ð ÈÍ; looking ÉÍÍÍ» Ò Ò Ò ÉÍÍÍ» Ò / ÉÍÍÍ» ÉÍÍÍ» ÉÍÍ͸ Ò ÉÍÍÍ» º º º º º º º / ÌÍÍ͹ ÌÍÍ͹ ÈÍÍÍ» º º º \º º º º º º/\ º º º º º º º ÈÍÍͼ\ ÈÍÍͼ Ð ÈÍÍͼ Ð \ ÈÍÍͼ Ð Ð ÔÍÍͼ Ð ÈÍÍͼ ÉÍ͸ ÉÍÍÍ» ÉÍÍÍ» Ì͵ ÌÍÍ͹ º º º º º º \º Ð .Ð Ð.ÈÍÍͼ\. Frequently Asked Questions Version 1.0 - Release 6/1/94 Written and Created by Mike Audleman Copyright (C) 1994 by Mike Audleman Please distribute freely but UNMODIFIED. If you have contributions, you may send them to MIKE AUDLEMAN at FIDO address 1:154/288 or on the Quick_Basic FIDO echo. Please send them as ASCII text only, no formatted doccuments (WP, W4WIN etc.). This is not an OFFICIAL document and as such all information is provided ASIS and no warrenties are implied as to the acuracy of anything included here. The questions and answers here are take from the Quick_Basic echo that I read weekly and reflect general questions that seem to appear on a regular basis. I write this in an effort to reduce the load on the net and plan to release new or updated versions on a monthly basis unless the load seems such that another interval is warrented. Since this is NOT a CODE SNIPPIT publication, code here will be limited severely. Only enough code to present information will be included. At this time, I do not know if there is anyone maintaining a snippit file, but if someone is, please forward the name and fido address that it can be freq'd from and I will include the info on it here. This publication is not connected in any way to any commercial concern, mine or otherwise and is free to all. No information contained herin is to be considered as an advertisment for any product, consider it as INFORMATION only. One last note, I do not own any version of PDS so I am unable to test ANY of the information with regard to that package. I do have QB45 and have tested MOST but NOT all on it. Additionally, much of this information will not be compatible to QBasic provided with MSDOS 5.0 and above since it is missing many of the features of the full compiler version. Thank you. Mike Audleman FIDO: 1:154/280 INDEX "How do I get arguments from the command line?" "How do I make QB45 stop converting COMMAND$ to uppercase?" "How do I make QuickBasic exit with an ErrorLevel?" "How do I load QB with two LIBs?" "Are there any good books on QuickBasic?" "How do I get a number from a string into an Integer?" "How do I remove spaces from a string?" "What are 'String Descriptors'?" "What is the difference between QBASIC and QuickBasic?" "How do I convert from a HEX number to DECIMAL or DECIMAL to HEX?" "How do I make QuickBasic reboot the system?" "Could anybody show me how `INKEY$' works please?" "How do you do ARCSIN and ARCCOS?" "How do the AND, OR, and XOR work?" "How do I seperate command line arguments?" *> "How do I get arguments from the command line?" Use the COMMAND$ function in QB, QB45 and PDS thus: Commandline$=COMMAND$ One caviat here is that QB and QB45 converts the command line to UPPERCASE only. I am not sure about PDS on the uppercase. *> "How do I make QB45 stop converting COMMAND$ to uppercase?" One method is to obtain a addon lib that provides direct access to the PSP and the unconverted command line. The LIB I released in 5/94 on the Quick_Basic net provides this and it is free. This method provides the same capability in the design environment as well as when the file is compiled, the patch mentioned next does not. The second method is to apply a patch to one of your QB45 files. The following patch for QB45 will prevent QB from forcing the command line to uppercase. Once you make this patch, you will have to use UCASE$(COMMAND$) to retreive an uppercase only string. The following steps will extract the OSCMD.OBJ file from your BCOM45.LIB, modify it and then replace it with the modified version. As always, MAKE A BACKUP OF BCOM45.LIB FIRST! One note, this will not affect the design environment, it will still force to uppercase. When the BAS file is compiled and linked, it will return the command line as typed. I still have not found the correct patch to QB.EXE. First, enter the following command: LIB BCOM45 *OSCMD Then run the following basic program Search$ = "" FOR X% = 1 TO 10 READ Y% Search$ = Search$ + CHR$(Y%) NEXT X% Replace$ = CHR$(235) + CHR$(8) + STRING$(8, 144) PRINT "OSCMD.OBJ "; OPEN "OSCMD.OBJ" FOR BINARY AS 1 X$ = SPACE$(LOF(1)) GET 1, , X$ X% = INSTR(X$, Search$) IF X% = 0 THEN PRINT "Not Modified.": CLOSE : END MID$(X$, X%) = Replace$ PUT 1, 1, X$ CLOSE : PRINT "Modified.": END DATA 60,97,114,6,60,122,119,2,52,32 Now enter the following command: LIB BCOM45 -OSCMD +OSCMD,,BCOM45 You should now have a modified BCOM45.LIB. *> "How do I make QuickBasic exit with an ErrorLevel?" Add the following declare statement at the beginning of your program: DECLARE SUB ExitWithErrLvl ALIAS "_exit" (BYVAL ERRORLEVEL%) Then to exit with an Error level contained in a variable: ExitWithErrorLvl Oops% WARNING: DO NOT USE THIS WHILE IN THE DEVELOPEMENT ENVIRONMENT IT WILL EXIT TO DOS WITHOUT PROMPTING FOR A SAVE. IT HAS ON OCCASION LOCKED UP MY XT AND MY 386 WHEN USED IN THE ENVIRONMENT. *> "How do I load QB with two LIBs?" You can't. You must combine the two LIBs into one and load that one instead. This is a common situation that there are routines in the stock QB.LIB you need as well as an addon at the same time. Here is how you combine two LIBs and generate a third to use. This combines QB.LIB and FOO.LIB into MYLIB.LIB generating a MYLIB.CAT catalog file: LIB QB.lib +FOO.LIB,MYLIB.CAT,MYLIB.CAT Now we must take the combined MYLIB.LIB and generate MYLIB.QLB: LINK /q MYLIB.LIB,MYLIB.QLB,nul,BQLB45 ; Note that the above lines assume that the current directory is your directory that contains QB45 and all the files, if not you must provide complete paths to all files not in the current directory. *> "Are there any good books on QuickBasic?" Yes, probably the most recomended is: "MicroSoft QuickBasic Bible" by the Waite Group MicroSoft Press ISBN: 1-55615-262-0 * Good examples on EVERY command Another good book that deals with INTERRUPT programming: "MD-DOS 5 Programming" by Peter G. Aitken MicroSoft Press ISBN: 1-55615-471-2 * Sample code in QuickBasic and C for MANY interrupt calls *> "How do I get a number from a string into an Integer?" Use: X% = VAL(TheString$) *> "How do I remove spaces from a string?" To remove spaces at the beginning of a string use X$ = LTRIM$(TheString$) To remove spaces at the end of a string use X$ = RTRIM$(TheString$) To remove at both beginning and end use X$ = LTRIM$(RTRIM$(TheString$)) *> "What are 'String Descriptors'?" Generally you will never need to know this unless you plan to write ASM or C routines to use with QuickBasic. String Descriptors are packs of 4 bytes that contain the offset within the DGROUP that the actual text of the string starts at and the length of the data. QB does not use ASCIIZ strings (strings that end with a CHR$(0)) so you must convert them in your code if you wish to use them with C in most cases. The block looks like: 2 bytes Offset within DGROUP 2 bytes Length of string data Both are UNSIGNED integers (0-65535) *> "What is the difference between QBASIC and QuickBasic?" A lot! Some of them are: QBASIC will not compile a BAS file into a EXE, QB45 does. QBASIC does not have a CALL INTERRUPT, QB45 does. QBASIC does not allow use of LIBs, QB45 does. QBASIC is a stripped down version of QB45 included with DOS 5.0 and above. QuickBasic must be purchased. The retail price varies but should be around $65-$80 U.S.. Generally, almost all BAS code will run in QBASIC. The exception is that if is uses INTERRUPTS or outside LIBs, it will not. There is however a CALL ABSOLUTE that does allow SOME access to ASM code but it is not simple and the routines must be small. Generally, if you are an occasional programmer, QBASIC will do just fine, however, if you want to end up with an EXE file or do some serious programming, QB45, or PDS would really be the way to go. Other packages available are Power Basic and Visual Basic for DOS. These other two packages are fine too and provide some additional commands over QB45 but as such are not backward compatible to QB45. *> "How do I convert from a HEX number to DECIMAL or DECIMAL to HEX?" To change from a HEX string to an integer: TheString$="6B" X%=VAL("&H"+TheString$) To change from an integer to a HEX string: X$=HEX$(TheInteger%) *> "How do I make QuickBasic reboot the system?" Here is a simple code snippit to do just this: SUB WarmBoot DEF SEG = 0 POKE &h473, &h12 POKE &h472, &h34 DEF SEG = &hFFFF CALL ABSOLUTE(0) END SUB SUB ColdBoot DEF SEG = &hFFFF CALL ABSOLUTE(0) END SUB *> "Could anybody show me how `INKEY$' works please?" Inkey simply checks the keyboard and then returns. If there was a keypress then it is returned, if not, inkey returns a NULL string. There are several methods of it's use. One is a one time scan.... For x=1 to 1000 ;do your stuff if inkey$=chr$(27) then exit for next x The other is to use it to scan the keyboard in a continuous loop until a key is pressed.... Function GetKey$ do:X$=Inkey$:loop while X$="" GetKey$=X$ End Function Here is a similar routine to accept keys and Capitolize the first letter of each word.... Function GetKeyCap$ Toggle%=False Stuff$="" Do X$=Inkey$ If X$=CHR$(13) then exit do 'User Pressed ENTER If Toggle% then X$=Lcase$(X$) else X$=Ucase$(X$) Stuff$=Stuff$+X$ Toggle%=( X$<>" ") 'Is it a Space? Loop GetKeyCap$=Stuff$ End Function *> "How do you do ARCSIN and ARCCOS?" ARCSIN and ARCCOS are "derived" functions. You can compute them using the following: CONST PI=3.141593 ARCSIN(A) = ATN(A / SQR(-A * A+1)) ARCCOS(A) = PI / 2 - ATN(A / SQR(-A * A+1)) To convert these into full blown functions: Function ARCSIN# (A#) ARCSIN# = ATN(A# / SQR(-A# * A#+1#)) end Function Function ARCCOS# (A#) ARCCOS# = PI / 2# - ATN(A# / SQR(-A# * A#+1#)) end Function *> "How do the AND, OR, and XOR work?" Well, AND, OR and XOR can be mathmatical or comparative functions. The math functions would be (this is BIT level): AND OR XOR ----------- ----------- ----------- 0 AND 0 = 0 0 OR 0 = 0 0 XOR 0 = 0 1 AND 0 = 0 1 OR 0 = 1 1 XOR 0 = 1 0 AND 1 = 0 0 OR 1 = 1 0 XOR 1 = 1 1 AND 1 = 1 1 OR 1 = 1 1 XOR 1 = 0 15=1111, 7=0111, 6=0110, 2=0010, 10=1010 so: 15 AND 7 = 7, 6 OR 2 = 6, 10 XOR 10 = 0 The comparitive functions are like this: AND = "This AND That" OR = "This OR That" XOR = "This OR That BUT NOT BOTH" If (5 > 1) AND (6 < 10 ) then Yep If 5 is larger than 1 and 6 is less than 10 *> "How do I seperate command line arguments?" You can use the following routine to seperate anything in a string variable that is seperated by spaces: DIM SHARED arg$(20) 'Max of 20 arguments, increase/decrease for your app. 'Set up string and make call: TheString$="This is a test of the EBS system." NumOfWords%=ArgSplit%(TheString$) For x%=0 to NumOfWords% Print arg$(x%) Next x% SUB ArgSplit%(cline$) I = 1: arg = LBOUND(arg$): inword = -1 WHILE I <= LENGTH ch$ = MID$(cline$, I, 1) IF ch$ <> " " THEN IF NOT inword THEN inword = -1 arg$(arg) = arg$(arg) + ch$ ELSEIF inword THEN arg = arg + 1 inword = 0 END IF I = I + 1 WEND ArgSplit% = arg END SUB END of FAQ Document