home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #2 / Amiga Plus CD - 1995 - No. 2.iso / internet / faq / englisch / comp.lang.basic.visual-dos < prev    next >
Encoding:
Text File  |  1995-04-11  |  12.2 KB  |  266 lines

  1. Posted-By: auto-faq 3.1.1.2
  2. Archive-name: visual-basic-faq/dos
  3.  
  4. Last-Modified: 06/10/94
  5.  
  6.                    VISUAL BASIC FOR DOS (VBDOS)
  7.                 Commonly asked Questions & Answers
  8.                          Section IX - B
  9.                -----------------------------------
  10.  
  11. PREFACE:
  12. This document is a compilation of frequently asked questions and their
  13. answers about Visual Basic for DOS which have been gathered from the
  14. comp.lang.basic.visual newsgroup.   Although some efforts have been
  15. made to find obvious errors, there is no guarantee that the information in
  16. this document is error-free.  The FAQ maintainer, or anyone else
  17. associated with this document, assume NO liability for the content or use
  18. of this document.  If you find any errors, please report them to the address
  19. given below.
  20.  
  21. Most FAQs (including this one) are available at the anonymous ftp archive
  22. site "rtfm.mit.edu".  All four parts of the VB FAQ may be found in the
  23. directory "pub/usenet/news.answers/visual-basic-faq".
  24.  
  25. You can also have the VB FAQs e-mailed to you by sending a message
  26. to "mail-server@rtfm.mit.edu" with ONLY the text "send
  27. usenet/news.answers/visual-basic-faq/*" in the body of the message.
  28.  
  29. As the FAQ maintainer, I don't have time to explore all of the aspects of
  30. Visual Basic.  I rely on your submissions to improve the quality and
  31. inclusiveness of this document.  If you have found a VB hint, tip, trick,
  32. work-around, etc., please write it up and send it to me!
  33.   Peter Millardac150@freenet.buffalo.edu   - VBDOS FAQ maintainer
  34.  
  35. Table of Contents:
  36. 1.   How do I use (create) global variables in VBDOS?
  37. 2.   Does VBDOS make standalone .exe files?
  38. 3.   What is the current version of the VBDOS compiler?
  39. 4.   How do I not make a text box beep when I hit the enter key?
  40. 5.   How does Visual Basic handle shelled tasks? How do I find out
  41.      when they are finished.
  42. 6.   How do I break lines of long text into multiple lines of text in
  43.      the msgbox?
  44. 7.   What's the difference between MODAL and MODELESS
  45.      forms?
  46. 8.   When/Why should I use Option Explicit?
  47. 9.   Why doesn't PRINT or CLS from a frm module work?
  48. 10.  How do I invoke FKey traps which won't be triggered by other
  49.      keys which share the same KeyCode?
  50. 11.  How do I boost memory available to VBDOS.EXE (the IDE)?
  51. 12.  My program runs in the IDE, but won't run when compiled??
  52. 13.  MISC. Programming TIPS:
  53.  
  54. -----------------------------------------------------------------------------
  55.  
  56. 1.   How do I use (create) global variables in VBDOS?
  57.      1.1. VBDOS provides the user with two types of global variables.
  58.           These are both used in declarations of variables.
  59.  
  60.           To share variables between all subs and functions in a specific
  61.           module, use the SHARED keyword. This makes that specific
  62.           variable global _in that module_. For example:
  63.  
  64.                   DIM SHARED CancelFlag AS INTEGER
  65.  
  66.           would make the variable CancelFlag a global variable in that
  67.           module.
  68.  
  69.           To share global variables between separate modules, use the
  70.           COMMON keyword. For example:
  71.  
  72.                  COMMON SHARED CancelFlag AS INTEGER
  73.  
  74.           would make the variable global between all modules that this
  75.           common statement appears in, and since we are using the
  76.           SHARED keyword also, this will also be shared in all the subs
  77.           and functions in the modules which this declare statement
  78.           appears. All COMMON statements must be matched between
  79.           modules which the variables should be global in. For example,
  80.           if you have one set of 10 COMMON statements in one module,
  81.           and a different set of 10 COMMON statements in another
  82.           module in the same project, you will get a 'Type Mismatch
  83.           Error'. Make all COMMON blocks identical in all the modules
  84.           in a specific project. (See Misc. Programming Tips Below).
  85.  
  86. 2.   Does VBDOS make standalone .exe files?
  87.      2.1. VBDOS can compile programs in two different ways (user
  88.           option). It can compile programs to use a RUNTIME file (like
  89.           a DLL) or can be compiled as a standalone .exe file. 
  90.  
  91. 3.   What is the current version of the VBDOS compiler?
  92.      3.1. VBDOS is currently at version 1.0
  93.  
  94. 4.   How do I not make a text box beep when I hit the enter key?
  95.      4.1. Put "something else" in your _KeyPress event, depending on
  96.           what you really want. This code example makes *nothing*
  97.           happen, for an extended period of time:
  98.  
  99.           Sub Text1_KeyPress (KeyAscii As Integer)
  100.               If KeyAscii = 13 Then   '13 is Key_Return
  101.                    KeyAscii = 0  '0 (zero) is nothing
  102.               End If
  103.           End Sub
  104.  
  105.           This might not be a very nice thing to do, since your users
  106.           usually have some intention when they press Enter. Usually
  107.           they will want to jump to the next control, like the Tab key
  108.           does. You will then change the line KeyAscii=0 to KeyAscii=9
  109.           (Key_Tab) in the example above. 
  110.  
  111.           BTW, you'll also find this in the Microsoft VB
  112.           KnowledgeBase. They add that you should set the MultiLine
  113.           property to False. Of course.
  114.  
  115. 5.   How does Visual Basic handle shelled tasks? How do I find out
  116.      when they are finished.
  117.      5.1. In VBDOS, all shelled tasks are completed before control
  118.           returns to the program. No tasks are done while the DOS
  119.           command is being executed.
  120.  
  121. 6.   How do I break lines of long text into multiple lines of text in the
  122.      msgbox?
  123.      6.1. Use the append a chr$(13) to the end of the string to break
  124.           lines into multiple lines. EG:
  125.  
  126.                msg$ = "This is line 1" + chr$(13)
  127.                msg$ = msg$ + "This is line 2"
  128.                MSGBOX msg$
  129.  
  130. 7.   What's the difference between MODAL and MODELESS forms?
  131.      7.1. Modal forms are forms which require user input before any
  132.           other actions can be taken place. In other words, a modal form
  133.           has exclusive focus until it is dismissed. When showing a
  134.           modal form, the program pauses at the SHOW command until
  135.           the modal form is either hidden or unloaded. The internal
  136.           MSGBOX and INPUTBOX$ forms are examples of modal
  137.           forms. To show a form modally, use the syntax:
  138.           MyForm.SHOW 1
  139.  
  140.      7.2. Modeless forms are those which are shown but do not require
  141.           immediate user input. Most child forms (in a MDI application)
  142.           are typically modeless. To show a form modeless, use the
  143.           syntax: MyForm.SHOW
  144.  
  145. 8.   When/Why should I use Option Explicit?
  146.      8.1. Opinions vary greatly on this subject. The main reason to use
  147.           the OPTION EXPLICIT statement at the top of all modules is
  148.           to minimize the amount of bugs introduced into your code by
  149.           misspelling a variable name. Most variants of BASIC
  150.           (including VB) have the capability to create variables 'on the
  151.           fly' (without any declarations). This capability can be a double
  152.           edged sword.
  153.  
  154.           At the minimum, it is suggested to use the DEFINT A-Z
  155.           statement in leu of OPTION EXPLICIT. This statement will
  156.           cause any variables which are created on the fly to be created
  157.           as integers as opposed to single precisions. (Integers take up
  158.           less memory). 
  159.  
  160.           The OPTION EXPLICIT statement causes VB to 'disable' it's
  161.           ability to create variables on the fly. Thus, all variables must be
  162.           declared using a DIM or REDIM statement. All variables not
  163.           declared will cause an error when the OPTION EXPLICIT
  164.           statement is used. This will eliminate any bugs when a variable
  165.           is misspelled.
  166.  
  167. 9.   Why doesn't PRINT or CLS from a frm module work?
  168.      9.1. To print information to the screen bypassing the desktop, the
  169.           commands must be issued from a .BAS module. All
  170.           PRINT/CLS output from a form module is directed to the nul:
  171.           device.
  172.  
  173. 10.  How do I invoke FKey traps which won't be triggered by other keys
  174.      which share the same KeyCode?
  175.      10.1.     To trap the only FKeys in events you need to use a
  176.                combination of the KeyDown, KeyPress, and KeyUp
  177.                events. 
  178.  
  179.           The basic concept for this is that _all_ keys trap the UP &
  180.           DOWN events, while only 'printable' characters trigger the
  181.           KeyPress event. Thus, when a character key is pressed, it will
  182.           trigger the KeyDown, the KeyPress, then the KeyUp events (in
  183.           that order). While a FKey (or arrow, or tab, etc...) will trigger
  184.           the KeyDown, then the KeyUp events (in that order). 
  185.  
  186.           The following code uses a textbox tag property to decide
  187.           whether a printable character is pressed or not.
  188.  
  189.                SUB Text1_KeyDown()
  190.                     Text1.tag = "key"
  191.                END SUB
  192.  
  193.                SUB Text1_KeyPress()
  194.                     Text1.tag = ""
  195.                END SUB
  196.  
  197.                SUB Text1_KeyUp()
  198.                   IF Text1.tag = "key" then
  199.                     '--PUT F-KEY HANDLER HERE----
  200.                   ELSE
  201.                     '--PUT OTHER KEY HANDLERS HERE----
  202.                   END IF
  203.                END SUB
  204.  
  205. 11.  How do I boost memory available to VBDOS.EXE (the IDE)?
  206.      11.1.     Try to have as much EMM available as possible.
  207.                VBDOS.EXE allocates subroutines & functions which are
  208.                < 16K into EMM.
  209.      11.2.     To make more conventional mem availble, use the /S:n
  210.                switch. This will make VBDOS.EXE use a specific
  211.                amount of conventional memory. A good compromise
  212.                between speed & memory is /S:340. The lower the n
  213.                value, the slower the environment runs.
  214.      11.3.     Running out of DGROUP usually causes most 'out of
  215.                memory' errors. Possible causes are:
  216.           11.3.1.Too many subs & functions exist. Each one takes up
  217.                46 bytes of DGROUP.
  218.           11.3.2.   Large static arrays. All static arrays are stored in
  219.                     DGROUP. If a DIM statement is for a COMMON
  220.                     SHARED statement, the array becomes static. Make
  221.                     the COMMON SHARED statement appear before
  222.                     the DIM statement to make the array Dynamic &
  223.                     therefore will not be stored in DGROUP.
  224.           11.3.3.   Variable Overhead. Each var has a 4 byte overhead
  225.                     for _each_ module. For multiple modules projects
  226.                     which use lots of Global (COMMON) statements,
  227.                     this overhead is repeated for _each_ module.
  228.      11.4.     Possible causes for running out conventional memory:
  229.           11.4.1.   Not enough EMM.
  230.           11.4.2.   Subs or functions which exceed 16K.
  231.           11.4.3.   Large arrays. Non-variable length string arrays can
  232.                     be stored in EMM using the /ea switch.
  233.  
  234. 12.  My program runs in the IDE, but won't run when compiled??
  235.      12.1.     Arrays are dynamic by default in the IDE, but when they
  236.                are compiled, they are static by default. Therefore, they
  237.                are stored in DGROUP instead of the far heap. Use
  238.                '$DYNAMIC to make all arrays dynamic or use REDIM
  239.                instead of DIM.
  240.      12.2.     Program generates a "program memory overflow" during
  241.                compile. You need to break a single module into multiple
  242.                ones.
  243.  
  244.      
  245. 13.  MISC. Programming TIPS:
  246.      13.1.     When useing the form designed, to continuously draw
  247.                controls of a specific type, hold down the control key
  248.                when clicking on the appropriate control from the tool-
  249.                box.
  250.      13.2.     Use the INCLUDE statement to manage large numbers of
  251.                COMMON SHARED statements, user defined data types,
  252.                or external function DECLARES. To use an include file,
  253.                simply put all the VBDOS statements that will be shared
  254.                into a single file. Save the file as something appropriate.
  255.                (Typical naming convention is to use an extension of .BI
  256.                for basic include files). Then simply insert the line:
  257.                         'INCLUDE: 'foobar.bi'
  258.                into either your .BAS module, or the module level code
  259.                in a form. 
  260.  
  261. -- 
  262.  
  263. Kris Nosack      knosack@park.uvsc.edu
  264.  
  265. >>>--->  Be strange, but not a stranger!  <---<<<
  266.