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-windows < prev    next >
Encoding:
Text File  |  1995-04-11  |  98.6 KB  |  2,494 lines

  1. Posted-By: auto-faq 3.1.1.2
  2. Archive-name: visual-basic-faq/windows
  3.  
  4. Last-modified: 17.11.94
  5.  
  6.  
  7.                     VISUAL BASIC FOR WINDOWS (VB/Win)
  8.                    Frequently asked Questions & Answers
  9.                               Section IX - B
  10.  
  11.  
  12.    The following symbols indicates new & updated topics:
  13.  
  14.    [++] means topic is updated in this issue
  15.    [**] means topic is new in this issue
  16.  
  17.    Hope this makes it easier for Our Regular Readers   ;-)
  18.  
  19.  
  20.  
  21.    TABLE OF CONTENTS:
  22.    ******************
  23.  
  24.  
  25.    A. PREFACE
  26.  
  27.  
  28.    B. GENERAL VISUAL BASIC QUESTIONS
  29.  
  30.           1. Does VB/Win make standalone .EXE files?
  31.  
  32.           2. What is the current version of Visual Basic for Windows?
  33.  
  34.           3. Where can I get updated VB and other Microsoft files?
  35.  
  36.           4. Help! I am lost on ftp.microsoft.com.
  37.  
  38.           5. Where can I get good up-to-date information about VB?
  39.               [++]
  40.  
  41.           6. Are there any examples of commercial applications built
  42.               using Visual Basic?
  43.  
  44.  
  45.    C. COMMON VISUAL BASIC PROGRAMMING QUESTIONS
  46.  
  47.           1. What's the difference between MODAL and MODELESS forms?
  48.  
  49.           2. When/Why should I use Option Explicit?
  50.  
  51.           3. Why does everybody say I should save in TEXT not BINARY?
  52.  
  53.           4. Is the Variant type slower than using other variable
  54.               types?
  55.  
  56.           5. How do I make a text box not beep but do something else
  57.               when I hit the Enter key?
  58.  
  59.           6. How do I implement an incremental search in
  60.               list/dir/combo/file boxes? [++]
  61.  
  62.           7. How do I get the Tab key to be treated like a normal
  63.               character?
  64.  
  65.           8. How do I make an animated icon for my program?
  66.  
  67.           9. What is passing by reference?
  68.  
  69.           10. I get a "file not found" error on the IIF function when
  70.               I distribute by program. Uh?
  71.  
  72.           11. Is there any way to pass a variable to a form apart from
  73.               using global variables?
  74.  
  75.           12. How should dates be implemented so they work with other
  76.               language and country formats?
  77.  
  78.           13. Can a VB application be an OLE server?
  79.  
  80.           14. How do I dial a phone number without using the MSCOMM
  81.               VBX?
  82.  
  83.           15. I have [several] megabytes of memory. Why do I get an
  84.               "out of memory" error?
  85.  
  86.           16. How do I mimic a toggle button?
  87.  
  88.           17. How do I get my application on top?
  89.  
  90.           18. Is there a way to break long lines in VB code?
  91.  
  92.           19. How do I remove/change the picture property of a control
  93.               at design time?
  94.  
  95.           20. Is a [foo] VBX/DLL available as shareware/freeware?
  96.  
  97.           21. How do I make my applications screen-resolution
  98.               independent?
  99.  
  100.           22. How do I do Peek and Poke? [++]
  101.  
  102.           23. Why doesn't "my string" & Chr$(13) do what I want?
  103.  
  104.           24. How do I prevent multiple instances of my program?
  105.  
  106.           25. How do I implement an accelerator key for a text box?
  107.  
  108.           26. How do I force a file dialogue box to reread the currect
  109.               disk? [**]
  110.  
  111.  
  112.    D. ADVANCED VISUAL BASIC PROGRAMMING ISSUES
  113.  
  114.           1. How do I tell when an application executed using the
  115.               SHELL command is finished?
  116.  
  117.           2. How do I access C style strings?
  118.  
  119.           3. How can I change the printer Windows uses in code without
  120.               using the print common dialog?
  121.  
  122.           4. Any tips for speeding up VB?
  123.  
  124.           5. How do I speed up control property access?
  125.  
  126.           6. How much gain in performance will I get if I write my
  127.               number crunching routines in C instead of Visual Basic?
  128.  
  129.           7. How do you make a TEXTBOX read only? Or, how do I prevent
  130.               the user from changing the text in a TEXTBOX?
  131.  
  132.           8. How can I create a VBX?
  133.  
  134.           9. How do you change the system menu (on the Control-Menu
  135.               Box)?
  136.  
  137.           10. How do I play MID, WAV or other multimedia files?
  138.  
  139.           11. How can I call a 'hidden' DOS program from VB?
  140.  
  141.           12. How do I do drag & drop between applications? [++]
  142.  
  143.           13. How do I use GetPrivateProfileString to read from INI
  144.               files? [++]
  145.  
  146.           14. How do I implement Undo?
  147.  
  148.           15. How do I create a window with a small title bar as in a
  149.               floating toolbar?
  150.  
  151.           16. What is Pseudocode?
  152.  
  153.           17. Does VB support pointers to functions?
  154.  
  155.           18. How do I program the Novell NetWare API from VB? [++]
  156.  
  157.           19. Some Visual Basic 4 rumours
  158.  
  159.  
  160.    E. CALLING THE WINDOWS API AND DLLs IN GENERAL
  161.  
  162.           1. What is the Windows API?
  163.  
  164.           2. How do I call a DLL?
  165.  
  166.           3. What about DLL calls that require callbacks?
  167.  
  168.           4. Tips for calling DLLs (such as the Windows API)
  169.  
  170.  
  171.    F. VISUAL BASIC AND DATABASES
  172.  
  173.           1. Why can't I use an index with my VB accessed database?
  174.  
  175.           2. Why does my compiled VB database app generate an error
  176.               when it ran just fine in the design environment?
  177.  
  178.           3. Is the Access Engine and Visual Basic Pro good enough for
  179.               database work?
  180.  
  181.           4. How do you avoid the "Invalid use of null" error when
  182.               reading null values from a database?
  183.  
  184.           5. What is "NULL"?
  185.  
  186.           6. How can I access a record by record number?
  187.  
  188.           7. How about Access 2.0 compatibility?
  189.  
  190.           8. Tips for VB database programming:
  191.  
  192.           9. How come I get a "No Current Record" error when I use a a
  193.               Data Control on an empty table?
  194.  
  195.           10. How can I speed up my VB database application?
  196.  
  197.           11. How do I get a bitmap picture in a field in an Access
  198.               database?
  199.  
  200.           12. What is "Reserved Error -1209"? [**]
  201.  
  202.           13. "Cannot perform operation. illegal.." with Paradox 3.5
  203.               table(s) [**]
  204.  
  205.  
  206.    G. DISTRIBUTING VISUAL BASIC APPLICATIONS
  207.  
  208.           1. What are some tips for using Setup Wizard?
  209.  
  210.           2. Are there restrictions on what I can distribute with my
  211.               VB program?
  212.  
  213.           3. What alternatives to setup wizard do I have?
  214.  
  215.           4. Do I need to worry about users who have Progman
  216.               replacements such as Norton Desktop and PC Tools?
  217.  
  218.           5. Can I distribute my app without vbrunXXX.dll?
  219.  
  220.           6. Why won't my setup program install commdlg.dll et. al.?
  221.  
  222.           7. Where do I install VBXs and DLLs?
  223.  
  224.  
  225.    H. MISCELLANEOUS TIPS AND INFORMATION
  226.  
  227.           1. Multiple identifiers after the DIM statement can be
  228.               confusing
  229.  
  230.           2. "Clean up" your project before final EXE compilation.
  231.  
  232.           3. Multiple END statements can be dangerous; or, The program
  233.               that refused to terminate.
  234.  
  235.           4. What are the latest versions of the various files used by
  236.               VB?
  237.  
  238.  
  239.    I. VISUAL BASIC FOR APPLICATIONS (VBA)
  240.  
  241.           1. Any tips for VB/Win 3 programmers moving to VBA?
  242.  
  243.           2. Does VBA support VBXs?
  244.  
  245.           3. How do I access properties on my dialog boxes in VBA?
  246.  
  247.           4. How do I use database routines from Excel VBA?
  248.  
  249.  
  250.  
  251. A. PREFACE
  252.  
  253.  
  254.    This document is a compilation of frequently asked questions and
  255.    their answers about Visual Basic for Windows and Visual Basic for
  256.    Applications which have been gathered from posts to the
  257.    comp.lang.basic.visual newsgroup.  Although efforts have been made
  258.    to find obvious errors, there is no guarantee that the information
  259.    in this document is error-free. Neither the FAQ maintainer nor
  260.    anyone else associated with this document assume ANY liability for
  261.    the content or use of this document. If you find any errors, please
  262.    report them to the address given below.
  263.  
  264.    This FAQ document is protected by international copyright
  265.    regulations. Permission is granted to distribute it freely, both in
  266.    electronic and written format, provided no charge is made. Also, do
  267.    not make changes to this document without the consent of the
  268.    maintainer. Usenet netiquette applies.
  269.  
  270.    Most FAQs (including this one) are available at the anonymous ftp
  271.    archive site "rtfm.mit.edu". All parts of the VB FAQ may be found
  272.    in the directory "pub/usenet/comp.lang.basic.visual".
  273.  
  274.    You can also have the VB FAQs e-mailed to you by sending a message
  275.    to "mail-server@rtfm.mit.edu" with ONLY the text
  276.  
  277.       send usenet/news.answers/visual-basic-faq/*
  278.  
  279.    in the BODY of the message.
  280.  
  281.    In this document, whenever a long line of code must be split into
  282.    two or more lines of text in the code examples, a | symbol will
  283.    precede each line which should be appended to the line above it.
  284.  
  285.    As the FAQ maintainer, I don't have time to explore all of the
  286.    aspects of Visual Basic. I rely on your submissions to improve the
  287.    quality and inclusiveness of this document. If you have found a VB
  288.    hint, tip, trick, work-around, etc., please write it up and send it
  289.    to me!
  290.  
  291.    Jan Steinar Haugland (Jan.Haugland@uib.no), VB/Win FAQ maintainer
  292.  
  293.    Please note that my first language is not English. You can safely
  294.    ignore all typos, but if you find an error that is so embarrassing
  295.    you can't help pulling your hair and screaming loud, just send me a
  296.    note and I'll correct it quietly. OK?
  297.  
  298.    I would like to thank all contributers, and also all those who have
  299.    given constructive feedback. This FAQ is now widely distributed in
  300.    the net community.
  301.  
  302.    Special thanks to the following people who have made many and
  303.    invaluable contributions to the VB/Win FAQ:  Kris Nosack (the
  304.    previous maintainer), Peter Millard, Nic Gibson, Mr. "D" (the
  305.    anonymous contributor), George Tatge (gat@csn.org), Andy Dingley
  306.    (dingbat@codesmth.demon.co.uk), and those I may have forgotten
  307.    (sorry).
  308.  
  309.    Your help is GREATLY appreciated!
  310.  
  311.  
  312. B. GENERAL VISUAL BASIC QUESTIONS
  313.  
  314.  
  315. 1. Does VB/Win make standalone .EXE files?
  316.  
  317.    VB/Win produces .exe files, but they are not standalone. All VB/Win
  318.    programs must be distributed with the VBRUNx00.DLL file (where x is
  319.    the major version number). This DLL must accompany all VB/Win
  320.    programs, but only one such file should reside on every system
  321.    where VB programs are used.
  322.  
  323. 2. What is the current version of Visual Basic for Windows?
  324.  
  325.    VB/Win is currently at version 3.0
  326.  
  327. 3. Where can I get updated VB and other Microsoft files?
  328.  
  329.    Microsoft Software Library (MSL) is accessible from the following
  330.    services:
  331.  
  332.    - Compu$erve
  333.  
  334.      GO MSL
  335.      Search for <filename.EXE>
  336.  
  337.    - Microsoft Download Service (MSDL)
  338.      Dial (206) 936-6735 to connect to MSDL
  339.  
  340.    - Internet (anonymous FTP)
  341.      ftp ftp.microsoft.com
  342.      Change to the \softlib\mslfiles directory
  343.      (There are a LOT of files in this directory! It is not
  344.      advisable to list all the files unless you have good time.
  345.      See map below.)
  346.  
  347. 4. Help! I am lost on ftp.microsoft.com.
  348.  
  349.    You no longer have to be! The site have been reorganised, and
  350.    you'll find the file DIRMAP.TXT in root (or whatever it's called on
  351.    a 3.5 NT server). Here's the file as I found it (stolen ruthlessly
  352.    from the server for yoru convenience):
  353.  
  354.    *------------------------------------------------------------------
  355.    -----*
  356.    This file is to help you find your way around ftp.microsoft.com.
  357.    This
  358.    file only covers the directory structure two levels deep.  If you
  359.    see a
  360.    'kb' directory in a second level directory, it contains all of the
  361.    information regarding that second level directory.  For example,
  362.    the
  363.    /developr/win32dk directory has a kb directory in it.  This kb
  364.    directory
  365.    contains all of the articles for any 32 bit development kit.
  366.  
  367.    ROOT DIRECTORY         SUB DIRECTORY         CONTENTS
  368.    ---------------------------------------------------------------
  369.    
  370.    ADVSYS                               Advanced Systems, Networks,
  371.                                         Mail
  372.                             LANMAN      LanMan & other networks
  373.                             MAIL        Mail and Schedule+
  374.                             MSCLIENT    Microsoft Networking Client
  375.                             SQL_ODBC    SQL and ODBC
  376.                             WINNT       Windows NT
  377.                             WINSOCK     Windows Sockets information
  378.  
  379.    DESKAPPS                             Desktop Applications
  380.                             ACCESS      Access
  381.                             DOSWORD     Word for MS-DOS
  382.                             EXCEL       Excel
  383.                             GAMES       Entertainment Packs, Flight
  384.                                         Sim, etc.
  385.                             HOMEAPPS    Home applications
  386.                                         (Fine Artist, Creative Writer)
  387.                             MISCAPPS    Other applications
  388.                             MMAPPS      Multimedia Titles
  389.                             OFFICE      Microsoft Office
  390.                             POWERPT     PowerPoint
  391.                             PROJECT     Project
  392.                             PUBLISHER   Publisher
  393.                             WORD        Word for Windows & Macintosh
  394.                             WRKS_MNY    Works and Money
  395.  
  396.    DEVELOPR                             Developer Tools and Information
  397.                             BASIC       Quick Basic & other Basics
  398.                             DEVCAST     DevCast information
  399.                             DEVUTIL     MS Test, Delta, EXEMOD, EXEPACK,
  400.                                         & LIB Utility
  401.                             DRG         Developer Relations Group
  402.                             FORTRAN     Fortran and Fortran
  403.    PowerStation
  404.                             FOX         FoxPro and FoxBase
  405.                             MAPI        Messaging API information
  406.                             MASM        Macro Assembler
  407.                             MSDN        Microsoft Developer Network
  408.                             MSJ         Microsoft Systems Journal
  409.                             OLE         OLE
  410.                             TAPI        Telephony API information
  411.                             VB          Visual Basic
  412.                             VISUAL_C    Visual C++, MFC, & other C
  413.                                         products
  414.  
  415.                             WIN_DK      Windows SDK, DKs & At Work
  416.                             WIN32DK     32 bit Development Kits
  417.  
  418.    MSEDCERT                             Microsoft Education and Certification
  419.                             EDUCATIO    Microsoft Education information
  420.                             CERTIFIC    Microsoft Certified Professional info
  421.  
  422.    MSFT                                 Microsoft shareholder information
  423.                             ANNREPT     Microsoft Annual Report
  424.                             BACKGRND    Background information on Microsoft
  425.                             PRESSREL    Microsoft Press Releases
  426.                             SEC         Recent filings with the Securities and
  427.                                         Exchange Commission
  428.  
  429.    SOFTLIB                              Instructions & index for software library
  430.                             MSLFILES    Software library files (> 1500 files)
  431.  
  432.    PEROPSYS                             Personal Operating Systems and Hardware
  433.                             HARDWARE    Mouse & other Hardware
  434.                             MSDOS       MS-DOS
  435.                             WINDOWS     Windows (all versions)
  436.                             WIN_NEWS    Information on Windows "Chicago"
  437.  
  438.    TECHNET                              Information on TechNet
  439.                             SERVDIR     Microsoft Services Directory
  440.  
  441.    *-----------------------------------------------------------------*
  442.  
  443.    NOTE: Directory and file names at ftp.microsoft.com are NOT case
  444.    sensitive.
  445.  
  446.    Thanks to Richard Mason (richard@whitney.demon.co.uk) for the map
  447.    he made for us before this long overdue reorganisation, and thanks
  448.    for bringing this to my attention.
  449.  
  450. 5. Where can I get good up-to-date information about VB? [++]
  451.  
  452.    If you do any VB programming at all, you really should get the
  453.    latest copy of the Microsoft Knowledge Base from one of the sources
  454.    listed above!  The filename is VBKB.EXE or VBKB_FT.EXE for the
  455.    version with full text searching. The Knowledge Base is a Windows
  456.    help formatted document that is updated almost monthly. (Beware:
  457.    The files are huge!)
  458.  
  459.    The EXE files on ftp.microsoft.com (and other places) are simple
  460.    self-extracting files. They don't do any automatic updating of your
  461.    system, just dump the file(s) inside them in the current directory
  462.    on your disk, uncompressed and ready for use. Just replace the old
  463.    files on your system with the new files (same name, usually).
  464.  
  465.    This FAQ (ahem) is a pretty good source as a digest of many of the
  466.    VB issues that are discussed in the comp.lang.basic.visual
  467.    newsgroup, but as such the information contained in this FAQ may
  468.    not have been thoroughly tested or verified.
  469.  
  470.    For easier access to and use of this FAQ document, get the Windows
  471.    Help file format FAQ doc by anonymous ftp to quasar.sba.dal.ca and
  472.  
  473.    look under /www/hlp. The .HLP version is made by Tim Roberts
  474.    (TJR@SBACOOP.SBA.DAL.CA). This is HIGHLY RECOMMENDED.
  475.  
  476.    Dave McCarter puts out a nice Windows help formatted document
  477.    called "Visual Basic Tips and Tricks". A good resource with
  478.    information that isn't found in the Knowledge Base. It can be found
  479.    by anonymous ftp to ftp.cica.indiana.edu
  480.    /pub/pc/win3/programr/vbasic/ as VBTIPS??.ZIP, where '??' is the
  481.    version number (yes, get the one with the highest number).
  482.  
  483.    Mark Schoonover has started a monthly magazine called _VBWin
  484.    Programmer's Magazine_ that is compiled around the Discussion of
  485.    Microsoft Visual Basic and Related Issues mailing list. This
  486.    magazine is available at the usual ftp sites like cica and at his
  487.    BBS (619) 571-2846. Mark can be contacted at schoon@cts.com. It
  488.    also has its own anonymous ftp site: ftp.cts.com in the
  489.    /pub/schoon/VBWM.Issues directory.
  490.  
  491.    There is presently an effort to put together a VB code library so
  492.    that VB users can share their best - and trickiest - programming
  493.    work. The code library project is being spear headed by Hein Ragas
  494.    who has managed to get a directory on CICA for code snippets to be
  495.    deposited. Stayed tuned to comp.lang.basic.visual for more
  496.    information.
  497.  
  498.    There's a VISBAS-L mailing list for Visual Basic. You can subscribe
  499.    to this mailing list by sending an email to
  500.  
  501.      LISTSERV@tamvm1.tamu.edu
  502.  
  503.    Place the following text in the *body* of the message (no, not the
  504.    subject line):
  505.  
  506.      SUB VISBAS-L Real Name
  507.  
  508.    Where Real Name is just that, *your full real name* not your email
  509.    address. Note that the traffic on this list may overflow your
  510.    mailbox if you have a limited mail buffer. Expect around 40-50
  511.    messages every weekday, a bit less during weekends. Also, to
  512.    unsubscribe, do as above but with "UNSUB" in the body of the
  513.    message to the LISTSERV address, *not* to the VISBAS-L list address
  514.    itself (Believe it or not, we usually receive 2-3 sub/unsub mails
  515.    every day on the list, and we're really fed up!) Also, this mail
  516.    server was split and a new list called VBDATA-L was made for Vb
  517.    database (Jet) related topics. Same procedure for registering (SUB
  518.    VBDATA-L Real Name).
  519.  
  520.    The address for the MS ACCESS listserver is listserv@indycms.bitnet
  521.    or listserv@indycms.iupui.edu The list name is ACCESS-L. To
  522.    subscribe, you follow the same procedure as for the other lists.
  523.  
  524.    Sorry, I know no mailservers or other Internet resources dedicated
  525.    to VBA specifically. Send me any information you may have, and I'll
  526.    bring it on.
  527.  
  528.    There are several Usenet newsgroups dedicated to MS Windows
  529.    programming and use. There's recently been a major group creation
  530.    process. Those groups that may be of special interest to VB
  531.    programmers are marked with *:
  532.  
  533.    comp.os.ms-windows.misc
  534.    comp.os.ms-windows.programmer.misc
  535.    comp.binaries.ms-windows
  536.    comp.os.ms-windows.advocacy
  537.    comp.os.ms-windows.announce
  538.    comp.os.ms-windows.apps
  539.    comp.os.ms-windows.nt.misc
  540.    comp.os.ms-windows.nt.setup
  541.    comp.os.ms-windows.programmer.tools     *
  542.  
  543.    comp.os.ms-windows.programmer.win32
  544.    comp.os.ms-windows.setup                *
  545.    comp.os.ms-windows.programmer.winhelp   *
  546.    comp.os.ms-windows.programmer.networks
  547.    comp.os.ms-windows.programmer.graphics
  548.    comp.os.ms-windows.programmer.controls  *
  549.  
  550.    The latest groups have been added to split the enormous traffic on
  551.    the *.misc groups down in managable chunks. However, the second
  552.    group (.programmer.misc) contains lots of interesting info (mostly
  553.    C related), if you have the time to read it all!
  554.  
  555.    Also note comp.lang.pascal which is a very good newsgroup for
  556.    Pascal, including Borland Pascal and Turbo Pascal for Windows.
  557.  
  558.    Please don't use this guide to find out where you should crosspost
  559.    VB questions. Check the charter for each group before posting to
  560.    it. If you are sure that your crosspost is legitimate, please note
  561.    the crossposting in the text.
  562.  
  563.    NOTE: PLEASE don't post VB stuff to comp.lang.visual. This group
  564.    has *nothing* to do with Visual Basic, and the academics discussing
  565.    "real" visual programming there are very, very annoyed at what they
  566.    call "quasi-visual" stuff and postings about those languages to
  567.    their group.
  568.  
  569.    If you have a Compu$erve account, you will find a forum for Visual
  570.    Basic there, including some support from Microsoft:
  571.  
  572.    MS BASIC Forum    (GO MSBASIC)
  573.  
  574.    Message Sections Available:             Libraries Available:
  575.     1 Forum News/Info                       1 MS Info and Index
  576.     2 Setup Wizard/Kit                      2 Setup Wizard/Kit
  577.     3 Data Access Objects                   3 Data Access Objects
  578.     4 The Data Control                      4 The Data Control
  579.     5 Programming Issues                    5 Programming Issues
  580.     6 ODBC Connectivity                     6 ODBC Connectivity
  581.     7 SQL Queries                           7 SQL Queries
  582.     8 ProEdition Controls                   8 ProEdition Controls
  583.     9 Calling API's/DLL's                   9 Calling API's/DLL's
  584.    10 Using OLE/DDE                        10 VBWIN-ODBC/Database
  585.    11 MSCOMM control                       11 MSCOMM control
  586.    12 MCI/MAPI controls                    12 MCI/MAPI controls
  587.    13 DOS Visual Basic                     13 DOS Visual Basic
  588.    14 DOS and Mac Basic                    14 DOS and Mac Basic
  589.    15 Suggestions/Mktg.                    15 Suggestions/Mktg.
  590.    16 CDK                                  16 CDK
  591.    17 3rd Party Products                   17 3rd Party Products
  592.  
  593.    There are magazines dedicated to VB. The best known is Fawcett
  594.    Technical Publications' _Visual Basic Programmer's Journal_ (VSPJ).
  595.    Phone 800-848-5523 (for US credit card orders) or 303-541-0610
  596.    (int'l and US other orders), Email 74003.224@compuserve.com to
  597.    Shirley Modric for subscription info. Address is 280 Second Street,
  598.    Suite 200, Los Altos, CA 94022-3603 USA.
  599.  
  600.    From Randy Coates (rcoates@telerama.lm.com):
  601.    I currently subscribe to "Inside Visual BASIC for Windows" from the
  602.    Cobb Group.  Although it is a helpful monthly paper (about 14 pages
  603.    per publication), I find it to be overpriced when compared to VB
  604.    Programmers Journal.  Here is the information anyway: Domestic
  605.    $59/yr ($7.00 each); Outside US $79/yr ($8.50 each)
  606.    Phone: Toll Free: 800-223-8720),  Local: 502-491-1900, Customer
  607.    Relations Fax: 502-491-8050, Editorial Department Fax: 502-491-
  608.    4200. Address: _Inside Visual BASIC for Windows_, 9420 Bunsen
  609.    Parkway, Suite 300, Louisville, KY  40220.
  610.  
  611.    (Note: for completeness other VB magazines should be listed, and I
  612.    would like to receive info on those!)
  613.  
  614. 6. Are there any examples of commercial applications built using
  615.    Visual Basic?
  616.  
  617.    Profit by Microsoft was written mostly in Visual Basic. In fact,
  618.    Profit was one of three programs selected as PC Magazine's Editor's
  619.    Choice among Windows small business accounting packages.
  620.  
  621.    Microsoft uses VB extensively for smaller utilities. 3 of the small
  622.    apps in the Windows and Windows for Workgroups Resource Toolkits
  623.    are written in VB. Also, if you have the Microsoft Bookshelf CD-
  624.    ROM, you will notice that the MVOPTION.EXE program, which is an
  625.    "options" program for MS Viewer, is created in VB.
  626.  
  627.    Note: The existence of VBX files in a package doesn't ecessarily
  628.    mean that it was written in VB. The most popular C++ compilers also
  629.    support VBXes.
  630.  
  631.  
  632. C. COMMON VISUAL BASIC PROGRAMMING QUESTIONS
  633.  
  634.  
  635. 1. What's the difference between MODAL and MODELESS forms?
  636.  
  637.    MODAL forms are forms which require user input before any other
  638.    actions can be taken place. In other words, a modal form has
  639.    exclusive focus until it is dismissed. When showing a modal form,
  640.    the program pauses at the SHOW command until the modal form is
  641.    either hidden or unloaded. The internal MsgBox and InputBox forms
  642.    are examples of modal forms. To show a form modally, use the
  643.    syntax:
  644.  
  645.      MyForm.SHOW 1
  646.  
  647.    MODELESS forms are those which are shown but do not require
  648.    immediate user input. MDI child forms are always modeless. To show
  649.    a form modeless, use the syntax:
  650.  
  651.      MyForm.SHOW
  652.  
  653. 2. When/Why should I use Option Explicit?
  654.  
  655.    Option Explicit forces you to declare all variables before using
  656.    them. Opinions vary greatly on this subject. The main reason to use
  657.    the OPTION EXPLICIT statement at the top of all modules is to
  658.    minimize the amount of bugs introduced into your code by
  659.    misspelling a variable name. Most variants of BASIC (including VB)
  660.    have the capability to create variables 'on the fly' (without any
  661.    declarations). This capability can be a double edged sword.
  662.  
  663.    At the minimum, some suggest using the DEFINT A-Z statement in leu
  664.    of OPTION EXPLICIT. This statement will cause any variables which
  665.    are created on the fly to be created as integers as opposed to
  666.    variant (VB 3.0) or single precision (VB 1.0 and 2.0). (Integers
  667.    take up less memory).
  668.  
  669.    The OPTION EXPLICIT statement causes VB to 'disable' its ability to
  670.    create variables on the fly. Thus, all variables must be declared
  671.    using a DIM or REDIM statement. All variables not declared will
  672.    cause an error when the OPTION EXPLICIT statement is used. This
  673.    will eliminate bugs caused by a misspelled variable. The option
  674.    works module-wide, so you can have some modules with and some
  675.    without this option in your project.
  676.  
  677. 3. Why does everybody say I should save in TEXT not BINARY?
  678.  
  679.    Actually, saving in binary mode is a bit faster, so why do we
  680.    recommend you to save in text?
  681.  
  682.    If you save the source and the project as text, it becomes ASCII
  683.    (or really, ANSI) code that you can edit with any text editor or
  684.    (if you are careful when you save) word processor. If you save in
  685.    binary, only the VB development environment, current or later
  686.    versions, will understand the code. The Setup Wizard can not scan
  687.    binary projects. Also, source documenters and other programming
  688.    tools usually require text mode. If you use text, you can use a
  689.    simple text editor (ie. notepad) to cut and paste code from other
  690.    source/form modules into your current project. Some 'tricks' (like
  691.    making an array of 1 control into a single non-array control again)
  692.    is easily done with an editor but not that easy in the environment.
  693.    If you want to print your project to paper the file|print option in
  694.    the VB environment is often not good enough; you may want to import
  695.    the text files into your word processor. And, finally, if something
  696.    goes wrong (only one byte is changed!) you may be out of luck in
  697.    binary mode. In text mode you will more easily be able to fix it.
  698.  
  699. 4. Is the Variant type slower than using other variable types?
  700.  
  701.    Generally, yes, if we are talking numeric variable types. The
  702.    Variant type also increases memory overhead. To test the speed
  703.    difference, try the following piece of code in something like a
  704.    button_click event and keep the debug window on the screen:
  705.  
  706.      Dim Va As Variant
  707.      Dim In As Integer
  708.      T1! = Timer
  709.      For i% = 1 To 32766
  710.        Va = i%
  711.      Next i%
  712.      T2! = Timer
  713.      Debug.Print "With variant:  "; Format$((T2! - T1!), "0.0000")
  714.      T1! = Timer
  715.      For i% = 1 To 32766
  716.        In = i%
  717.      Next i%
  718.      T2! = Timer
  719.      Debug.Print "With integer:  "; Format$((T2! - T1!),"0.0000")
  720.  
  721.    This test shows (on our test system) that integers are ~60% faster!
  722.    However, for strings there where no real difference, or in some
  723.    instances, variants were faster than strings for routines with
  724.    heavy conversion usage. For the best result in your application,
  725.    test your routines directly.
  726.  
  727. 5. How do I make a text box not beep but do something else when I hit
  728.    the Enter key?
  729.  
  730.    Put "something else" in your _KeyPress event, depending on what you
  731.    really want. This code example makes *nothing* happen, for an
  732.    extended period of time:
  733.  
  734.      Sub Text1_KeyPress (KeyAscii As Integer)
  735.          If KeyAscii = 13 Then   '13 is Key_Return
  736.             KeyAscii = 0
  737.          End If
  738.      End Sub
  739.  
  740.    This might not be a very nice thing to do, since your users usually
  741.    have some intention when they press Enter. Often they will want to
  742.    jump to the next control, like the Tab key does. To have the Enter
  743.    key emulate the Tab key action, you will need to add the line
  744.    'SendKeys "{tab}"' above 'KeyAscii=0' in the example above (Yes, I
  745.  
  746.    thought KeyAscii=9 works but it doesn't! Tab is obviously handled
  747.    by Windows on a lower level).
  748.  
  749.    By the way, you'll also find this in the Microsoft VB Knowledge
  750.    Base (see KB Q78305 and Q85562).
  751.  
  752.    Note: If MultiLine=True you will *not* want to disable the normal
  753.    behaviour of the Enter key.
  754.  
  755. 6. How do I implement an incremental search in list/dir/combo/file
  756.    boxes? [++]
  757.  
  758.    This is your lucky day. Dan Champagne (Dan_Champagne@dell.com) made
  759.    some VB code (no DLLs are necessary!) which easily provides this
  760.    feature for your applications:
  761.  
  762.      ' Code by Dan Champagne
  763.      ' 4/18/94
  764.  
  765.      ' This code can be used to do an incremental search in either a
  766.      ' list box, dir, combo, or a file box. The following code is set
  767.      ' for a file box called FILE1. To make it work with a list box, or
  768.      ' a file box with a different name, change all occurences of FILE1
  769.      ' with whatever you or VB has named your list, combo, dir, or file box.
  770.      ' There are two places where you will need to change these. They are
  771.      ' on the last couple of lines in the KeyPress code.
  772.      ' Also, thanks to John Tarr for helping debug the code.
  773.  
  774.      'In a .BAS file, add the following:
  775.      'searchme$ is a global vaiable that will keep track of what the
  776.      'user has typed so far.
  777.      Global searchme$
  778.  
  779.      'The following needs to be on one line.
  780.      Declare Function SendMessageBystring& Lib "User" ALIAS
  781.      |"SendMessage" (ByVal hWnd%, ByVal wMsg%, ByVal
  782.      |wParam%, ByVal lParam$)
  783.  
  784.      Global Const WM_USER = &H400
  785.      Global Const LB_SELECTSTRING = (WM_USER + 13)
  786.      Global Const LB_FINDSTRING = (WM_USER + 16)
  787.  
  788.      'In File1 under keydown, add the following:
  789.      'This checks if the user has pressed the up or down arrow.
  790.      'If they have, reset searchme$ to "".
  791.      If KeyCode = 40 Or KeyCode = 38 Then
  792.         searchme$ = ""
  793.      End If
  794.  
  795.      'In File1 under lostfocus, pathchange, patternchange, and click add:
  796.  
  797.      'If the user has done any of the above, reset the searchme$
  798.      'string.
  799.      searchme$ = ""
  800.  
  801.      'In File1 under keypress add:
  802.  
  803.      Dim result&
  804.  
  805.      Select Case KeyAscii
  806.          Case 8     'Backspace
  807.              If searchme$ <> "" Then
  808.                  searchme$ = Left$(searchme$, Len(searchme$) - 1)
  809.              Else
  810.                 File1.ListIndex = 0
  811.              End If
  812.              KeyAscii = 0
  813.              Exit Sub
  814.          Case 27    'Escape
  815.  
  816.              searchme$ = ""
  817.              KeyAscii = 0
  818.              Exit Sub
  819.          Case 13    'Enter
  820.              searchme$ = ""
  821.              KeyAscii = 0
  822.              Exit Sub
  823.          Case Asc("a") To Asc("z"), Asc("A") To Asc("Z"), Asc("'"),
  824.          |Asc("."), Asc(" "), Asc("0") To Asc("9")
  825.              searchme$ = searchme$ & Chr$(KeyAscii)
  826.              KeyAscii = 0
  827.      End Select
  828.  
  829.      result& = SendMessageBystring(FILE1.hWnd, LB_FINDSTRING,
  830.      |0, searchme$)
  831.  
  832.      If result& = -1 Then
  833.         searchme$ = Left$(searchme$, Len(searchme$) - 1)
  834.      Else
  835.         result& = SendMessageBystring(FILE1.hWnd, LB_SELECTSTRING,
  836.         |-1, searchme$)
  837.      End If
  838.  
  839. 7. How do I get the Tab key to be treated like a normal character?
  840.  
  841.    You must set TabStop = False for ALL controls on the active form.
  842.    Then you will be able to insert "tab" (chr 9) characters in
  843.    controls like the text box.
  844.  
  845.    If you feel you need the Tab key to behave "normal" (ie. jump to
  846.    next control) outside this specific control, it is trivial to
  847.    emulate its functionality in code:
  848.  
  849.      Sub Command1_KeyDown (KeyCode As Integer, Shift As Integer)
  850.        If KeyCode = 9 Then
  851.          If Shift = 0 Then
  852.             Command2.SetFocus 'Tab=Next control
  853.          ElseIf Shift = 1 Then
  854.             Command3.SetFocus 'Shift-Tab=Prev.ctrl.
  855.          End If
  856.        End If
  857.      End Sub
  858.  
  859.    ...etc.
  860.  
  861. 8. How do I make an animated icon for my program?
  862.  
  863.    For an example on how you change the icon for your application as
  864.    it is displayed when it is minimized, see the example REDTOP in the
  865.    \samples\picclip directory for VB/Win 3 Pro. This demonstrates a
  866.    fancy animated icon.
  867.  
  868. 9. What is passing by reference?
  869.  
  870.    Arguments are either passed by reference or by value. When they are
  871.    passed by value, they cannot be changed by the procedure or
  872.    function they are passed to. They *can* be altered when passed by
  873.    reference, since passing by reference is just passing the address.
  874.  
  875.    Note that procedures are less strict about variable types when you
  876.    use BYVAL. If you declare that your Sub takes a Variant, VB takes
  877.    that seriously and gives a nasty "mismatch error" if you try to
  878.    pass ie. a string to it. Make it ByVal (at the cost of some speed)
  879.    and your sub will be more tolerant.
  880.  
  881.    Also note the following nasty trap:  Arguments are passed by
  882.    reference unless enclosed by parentheses or declared using the
  883.    ByVal keyword. [VBWin Language Ref., p. 55]
  884.  
  885. 10.I get a "file not found" error on the IIF function when I
  886.    distribute by program. Uh?
  887.  
  888.    There's a documentation error, since the manual does not tell you
  889.    that the IIF function requires the file MSAFINX.DLL to be
  890.    distributed with your application. No, IIF is not financial (I
  891.    should know, I study finance right now, or at least I should be
  892.    doing that ;-] ).
  893.  
  894. 11.Is there any way to pass a variable to a form apart from using
  895.    global variables?
  896.  
  897.    The standard workaround is to put an invisible text box (or caption
  898.    or any other control that suits your use.) on the target form and
  899.    access it by Form.textbox = "value". Then you can use the Change
  900.    event of that control to do anything you want in that form. Also,
  901.    check out the .Tag property which is a "what-you-want" property
  902.    where you can hook any string you want onto a control. This
  903.    property can also be accessed from other modules.
  904.    [Dave Mitton (mitton@dave.enet.dec.com)]
  905.  
  906. 12.How should dates be implemented so they work with other language
  907.    and country formats?
  908.  
  909.    If you use ie. MM/DD/YY format dates in a program, you will get
  910.    either a runtime-error (ie. month>12) or the wrong date (ie. March
  911.    12 instead of December 3) when your program is used in Europe. And
  912.    vice versa, of course. Even Microsoft's own example programs (like
  913.    the MAPI sample) make this stupid mistake and fail miserably. Use
  914.    the Format command to make sure you get the date you want. For
  915.    example:
  916.  
  917.      strTodaysDate = Format[$](Now, "Short Date")
  918.  
  919.    As a side note, Microsoft has taken much heat on the newsgroup for
  920.    VB's bad support for internationalization! Just try to make a date
  921.    literal in source code that works everywhere as a little exercise.
  922.    Answer elsewhere in this document. No prizes  :-)
  923.  
  924. 13.Can a VB application be an OLE server?
  925.  
  926.    No. You'll have to use an external DLL/VBX. If you see any
  927.    examples, please tell the newsgroup.
  928.  
  929. 14.How do I dial a phone number without using the MSCOMM VBX?
  930.  
  931.    The MSCOMM VBX that comes with VB/Pro is great for creating
  932.    communication programs, but it's overkill for dialing a phone
  933.    number. Try the following code:
  934.  
  935.      PhoneNumber$ = "(123)456-7890"
  936.      Open "COM2" For Output As #1   'or COM1
  937.      Print #1, "ATDT" & PhoneNumber$ & Chr$(13)
  938.      Close #1
  939.  
  940.    Ian Storrs <exuian@exu.ericsson.se> informed me that he had
  941.    experienced problems with this when the VB program was run from a
  942.    network drive. A file named "COM1" was created on the disk! This
  943.    trick is probably not a good idea for bigger applications, but it's
  944.    nice for small personal utilities.
  945.  
  946. 15.I have [several] megabytes of memory. Why do I get an "out of
  947.    memory" error?
  948.  
  949.    Unfortunately, Microsoft has been more famous for memory barriers
  950.    than anything else. This is a late descendant of the infamous 640K
  951.    barrier that has been plaguing us for years. Although Windows
  952.    allows the user to access several megabytes of memory, it uses two
  953.    limited (64K) memory areas called User Heap and GDI Heap for some
  954.    specific data structures. Go to the Help|About box in Program
  955.    Manager to see the percentage of free resources in the *most*
  956.    exhausted heap. If these areas are exhausted, you are out of luck.
  957.    VB programs are unfortunately rather greedy on these structures.
  958.    Windows 4 is supposed to free us from this limitation...
  959.  
  960.    Note that every visible control (ie every button) is a window to
  961.    Windows. Every new control takes up some bytes in the precious User
  962.    heap.
  963.  
  964.    Also, there is another way to run out of memory in Windows, not
  965.    related to VB. Windows requires free Upper Memory Area (UMA, also
  966.    called Upper Memory Blocks, not to be confused with High RAM, which
  967.    is the first 64K of extended memory) to do certain tasks. If you
  968.    use QEMM or DOS 6+ MemMaker and you have many device drivers
  969.    (network, etc) this area may have been filled up before you launch
  970.    Windows. You will then be unable to start applications, even though
  971.    you have plenty of free RAM. The problem can be solved with careful
  972.    memory setup, but this is far beyond the scope of this FAQ.
  973.  
  974.    On a completely unrelated problem: When you run a program with an
  975.    outline control with some ATI graphics cards, it may crash with
  976.    just that error message. (see Knowledge Base Q100194 PRB: "Some ATI
  977.    Video Drivers Hang When Using MSOUTLIN.VBX")
  978.  
  979. 16.How do I mimic a toggle button?
  980.  
  981.    The only "fix" we know for this problem is to use a picture or
  982.    image control to mimic the action of a button or button3d control.
  983.    You need two bitmaps, one for buttonup and one for buttondown (and
  984.    perhaps one more for inactive state). This is a kluge, we know.
  985.    Look at the button bar used in the MDINOTE sample program supplied
  986.    with VB for an example of this.
  987.  
  988. 17.How do I get my application on top?
  989.  
  990.    To force a form to the front of the screen, do the following
  991.    command:
  992.  
  993.      Form1.ZOrder
  994.  
  995.    To make the application *stay* on top, put the Zorder command in a
  996.    Timer event repeatedly called, say, every 1000 msecs. This makes a
  997.    "softer" on-top than other methods, and allows the user to make a
  998.    short peek below the form.
  999.  
  1000.    There are two different "Zorder"'s of forms in Windows, both
  1001.    implemented internally as linked lists. One is for "normal"
  1002.    windows, the other for real "topmost" windows (like the Clock
  1003.    application which is distributed with MS Windows). The Zorder
  1004.    command above simply moves your window to the top of the "normal"
  1005.    window stack. To make your window truly topmost, use the
  1006.    SetWindowPos API call like this:
  1007.  
  1008.      'Make these declares:
  1009.      Declare Function SetWindowPos Lib "user" (ByVal h%,
  1010.      |ByVal hb%, ByVal x%, ByVal y%, ByVal cx%, ByVal cy%,
  1011.      |ByVal f%) As Integer
  1012.      Global Const SWP_NOMOVE = 2
  1013.      Global Const SWP_NOSIZE = 1
  1014.      Global Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
  1015.      Global Const HWND_TOPMOST = -1
  1016.      Global Const HWND_NOTOPMOST = -2
  1017.  
  1018.      'To set Form1 as a TopMost form, do the following:
  1019.      res% = SetWindowPos (Form1.hWnd, HWND_TOPMOST, 0, 0,
  1020.      |0, 0, FLAGS)
  1021.      'if res%=0, there is an error
  1022.  
  1023.      'To turn off topmost (make the form act normal again):
  1024.      res% = SetWindowPos (Form1.hWnd, HWND_NOTOPMOST, 0, 0,
  1025.      |0, 0, FLAGS)
  1026.  
  1027. 18.Is there a way to break long lines in VB code?
  1028.  
  1029.    There is unfortunately no line continuation character in VB/Win
  1030.    3.0. Excel 5 VBA does, however, use Space+Underscore (" _") as a
  1031.    line continuation character, and we hope this will be included in
  1032.    the next version of VB.
  1033.  
  1034.    There are a few tricks you can use to reduce line length, but
  1035.    unfortunately there is very little to do with DECLARE statements
  1036.    which can get very long.
  1037.  
  1038.    Print your source in landscape   :-/
  1039.  
  1040. 19.How do I remove/change the picture property of a control at design
  1041.    time?
  1042.  
  1043.    Mark the (bitmap) or (icon) text in the property window and press
  1044.    Del or Backspace. "No!" I hear you cry, "It doesn't work". Well, it
  1045.    does if you first select the object from the combo box at the top
  1046.    of the Properties Window, and then immediately afterwards
  1047.    doubleclick (or paint over) the "(bitmap)" text and press Del.
  1048.    Alternatively, just click on another control, then click back to
  1049.    the first control. Now Del works. Who said "bug"?
  1050.  
  1051.    If you want to paste your picture directly into the VB program by
  1052.    pressing Ctrl-V when you are editing the picture property, you will
  1053.    have to use a semilar procedure: select the control, select the
  1054.    property, press Ctrl-V. If you try it again without deselecting the
  1055.    control first (or selecting it from the combo box), it doesn't
  1056.    work.
  1057.  
  1058. 20.Is a [foo] VBX/DLL available as shareware/freeware?
  1059.  
  1060.    Part 4 of the FAQ is Adam Harris' excellent "Shareware Custom
  1061.    Controls List". Please consult this list before you post this
  1062.    question.
  1063.  
  1064.    The following type of controls are NOT known to be available as
  1065.    sw/pd/fw for Visual Basic, only as commercial toolboxes (If you
  1066.    feel like making any of these for VB and sharing it for a modest
  1067.    fee, you will become very popular!):
  1068.  
  1069.    a. ZModem communication control/source
  1070.  
  1071.    b. Rich Text Format-control or other mixed font/word processor
  1072.       control (rumours indicate that this will be in the Windows 4
  1073.       API, and therefor available from VB)
  1074.  
  1075.    c. Matrix math
  1076.  
  1077.    If any of these should be available, please tell us.
  1078.  
  1079. 21.How do I make my applications screen-resolution independent?
  1080.  
  1081.    There are two methods: Either get a custom control that does the
  1082.    job for you, or you write lots of complicated code in the Load and
  1083.    Resize events.
  1084.  
  1085.    For the first option, check out VideoSoft's $hareware VSVBX.VBX
  1086.    (download VSVBX.ZIP from Cica or mirrors). It has a will of its
  1087.    own, as you will experience, but it's generally better than trying
  1088.    what is described below.
  1089.  
  1090.    For the brave (or stupid), try to write "screen resolution-smart
  1091.    code" in the form's Load event. If the form is resizable (normally
  1092.  
  1093.    it should be), you'll have to put some magic into the Resize event
  1094.    as well. There are 4 rules of thumb:
  1095.  
  1096.    a. Do not trust the form's height and width properties.  These
  1097.       measure the entire form, not the client area where your controls
  1098.       are.  To see this in action, create a simple applet with the
  1099.       only code being in the resize event which resets a line control
  1100.       from 0,0 to the form's width,height properties.  The top left
  1101.       corner is in the client area, the bottom right corner
  1102.       disappears.  The API call GetClientRect will return the size of
  1103.       the client area in pixels.  You can use the screen object's
  1104.       TwipsPerPixelX and TwipsPerPixelY properties to convert from
  1105.       pixels to twips. If that's not enough, GetWindowRect will return
  1106.       the actual size of the entire form, client and non-client areas
  1107.       combined.  GetSystemMetrics will return individual pieces of
  1108.       things like border width/hight, caption height, etc.
  1109.  
  1110.    b. Use the TextWidth and TextHeight properties.  You can use them
  1111.       off the form if all your controls share the same font, otherwise
  1112.       use them off of the given control.  I typically do a
  1113.       TextWidth("X") and TextHeight("X") to get a value which I use as
  1114.       a margin between controls.  I grab these values on startup, and
  1115.       multiply it by 2, 1.5, .75, .5, .25 to get varying margin sizes,
  1116.       depending on how close or far apart I want to space things. If
  1117.       your control has an autosize property, you may want to use it,
  1118.       and then calculate the maximum width of a control in a given
  1119.       "column" of controls on your screen and position all of them
  1120.       accordingly.
  1121.  
  1122.    c. Try not to resize your controls in the resize event.  You will
  1123.       spawn another resize event in the process.  Of course, you can
  1124.       use a flag to determine whether the resize event is the original
  1125.       event or the spawned one.  Using the load event, and setting the
  1126.       forms borders to fixed minimizes the amount of work you have to
  1127.       do.
  1128.  
  1129.    d. Make sure you use a consistant scale.  I don't even bother with
  1130.       the scale properties, but instead just convert pixels (from API
  1131.       calls) into twips and be done with it.  If you do use scale
  1132.       properties, be sure you convert your numbers correctly.  I had
  1133.       no end of difficulty when I failed to convert into twips with
  1134.       one number that was used in a series of calculations to position
  1135.       controls.  Also be sure all your controls share the same SCALE -
  1136.       - another nasty problem I had before I gave up on them
  1137.       completely.
  1138.       [Thanks to our generous anonymous source "D"]
  1139.  
  1140. 22.How do I do Peek and Poke? [++]
  1141.  
  1142.    VB provides no mechanism for this.  There are several 3rd party
  1143.    pkgs. which provide this.  Also, this often comes up in regards to
  1144.    the comm ports and you can many times do what you want with the
  1145.    mscomm.vbx.
  1146.    [George Tatge (gat@csn.org)]
  1147.  
  1148.    There's a shareware package for in/out routines but alas not for
  1149.    peek & poke.
  1150.  
  1151. 23.Why doesn't "my string" & Chr$(13) do what I want?
  1152.  
  1153.    You need to also add a Chr$(10):  "my string" & Chr$(13) & Chr$(10)
  1154.    will give you a CR and LF.
  1155.    [George Tatge (gat@csn.org)]
  1156.  
  1157. 24.How do I prevent multiple instances of my program?
  1158.  
  1159.    In VB 3, the property App.PrevInstance is set to True if an older
  1160.    instance of the program already exist.
  1161.  
  1162.    The following piece of code, stolen from MS KB article Q102480,
  1163.    will activate the old instance and then terminate itself:
  1164.  
  1165.      Sub Form_Load ()
  1166.        If App.PrevInstance Then
  1167.           SaveTitle$ = App.Title
  1168.           App.Title = "... duplicate instance."      'Pretty, eh?
  1169.           Form1.Caption = "... duplicate instance."
  1170.           AppActivate SaveTitle$
  1171.           SendKeys "% R", True
  1172.           End
  1173.        End If
  1174.      End Sub
  1175.  
  1176.    As Robert Knienider(rknienid@email.tuwien.ac.at) informed me, this
  1177.    piece of code WILL NOT work for non-English versions of MS Windows
  1178.    where the word for "Restore" does not have "R" as the underlined
  1179.    word. Replace the "R" in the SendKeys line above with "{ENTER}" or
  1180.    "~".
  1181.  
  1182.    Note that you shouldn't prevent multiple instances of your
  1183.    application unless you have a good reason to do so, since this is a
  1184.    very useful feature in MS Windows. Windows will only load the code
  1185.    and dynamic link code *once*, so it (normally) uses much less
  1186.    memory for the later instances than the first.
  1187.  
  1188. 25.How do I implement an accelerator key for a text box?
  1189.  
  1190.    You want to use a label caption to identify a text box and to act
  1191.    as if it were the text box caption:
  1192.  
  1193.    Example:
  1194.  
  1195.    &Label1  [text1      ]
  1196.  
  1197.    How should I do to set the focus to text1, by typing <ALT>L
  1198.  
  1199.    Make sure that the TabIndex property for the text box is 1 greater
  1200.    than the
  1201.    label's TabIndex. Since a label can't have the focus, the focus
  1202.    will go to the next item in the tab order, which would be the text
  1203.    box.
  1204.  
  1205.    Here's any easy way to set the TabIndex for a busy form. Select the
  1206.    object that should be last in the tab order and then select the
  1207.    TabIndex property. Press 0 (zero), click on the next to last
  1208.    object, press 0, click on the  the next object back, press 0, etc.
  1209.    When you're done, all of the TabIndexes  will be in order, because
  1210.    VB increments all of the higher TabIndexes when you put in a lower
  1211.    number.
  1212.  
  1213.    Many thanks to Jonathan Kinnick and Gary Weinfurther that provided
  1214.    the answer
  1215.    on the FIDO net echo VISUAL_BASIC.
  1216.    [Tiago Leal (Tiago.Leal@p25.f1.n283.z2.gds.nl)]
  1217.  
  1218. 26.How do I force a file dialogue box to reread the currect disk? [**]
  1219.  
  1220.    If you make a simple dialogue box modelled after common dialogue
  1221.    (normally you should *use* the common dialogue VBX!), you will
  1222.    notice that reselecting the diskette drive will not really rescan
  1223.    the disk. Very annoying to change to C:, and to reselect A: just to
  1224.    make it read the directory of a new diskette.
  1225.  
  1226.    To solve this problem, put
  1227.  
  1228.      drive1.refresh
  1229.      dir1.refresh
  1230.      file1.refresh
  1231.  
  1232.  
  1233.    in the code for the "Rescan" button (or whatever).
  1234.  
  1235.  
  1236. D. ADVANCED VISUAL BASIC PROGRAMMING ISSUES
  1237.  
  1238.  
  1239. 1. How do I tell when an application executed using the SHELL command
  1240.    is finished?
  1241.  
  1242.    Shell() doesn't really return a task handle, it returns an instance
  1243.    handle. Any documentation that says otherwise is wrong. But never
  1244.    mind that; the answer to your question is to use the API call
  1245.    GetModuleUsage.
  1246.  
  1247.      'Put this in the general declarations of your form/module
  1248.      Declare Function GetModuleUsage Lib "Kernel" (ByVal
  1249.      |hModule As Integer) As Integer
  1250.  
  1251.      'Here's where you shell out to the other program
  1252.      intHandle = Shell("PROGRAM.EXE")
  1253.      Do While GetModuleUsage(intHandle) > 0
  1254.         DoEvents
  1255.      Loop
  1256.    [Kenn Nesbitt, Microsoft Consulting Services (kennn@netcom.com)]
  1257.  
  1258. 2. How do I access C style strings?
  1259.  
  1260.    Use the 'lstrlen' and 'lstrcpy' calls found in the Kernel DLL.
  1261.  
  1262. 3. How can I change the printer Windows uses in code without using the
  1263.    print common dialog?
  1264.  
  1265.    You can change the printer the VB 3.0 Printer object is pointing to
  1266.    programmatically (without using the common dialogs). Just use the
  1267.    WriteProfileString API call and rewrite the [WINDOWS],  DEVICE
  1268.    entry in the WIN.INI file!  VB will instantly use the new printer,
  1269.    when the next Printer.Print command is issued. If you get the old
  1270.    printer string before you rewrite it (GetProfileString API call),
  1271.    you can set it back after using a specific printer. This technique
  1272.    is especially useful, when you want to use a FAX printer driver:
  1273.    Select the FAX driver, send your fax by printing to it and switch
  1274.    back to the normal default printer.
  1275.    [Hajo Schmidt (hajo@bwl.bwl.th-darmstadt.de)]
  1276.  
  1277.    It is recommended (and polite, as we're multitasking) to send a
  1278.    WM_WININCHANGE (&H1A) to all windows to tell them of the change.
  1279.    Also, under some circumstances the printer object won't notice that
  1280.    you have changed the default printer unless you do this.
  1281.  
  1282.      Declare Function SendMessage(ByVal hWnd As Integer,
  1283.      |ByVal wMsg As Integer, ByVal wParam As Integer,
  1284.      |lParam As Any) As Long
  1285.      Global Const WM_WININICHANGE = &H1A
  1286.      Global Const HWND_BROADCAST = &HFFFF
  1287.      ' Dummy means send to all top windows.
  1288.  
  1289.      ' Send name of changed section as lParam.
  1290.      lRes = SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0,
  1291.      |ByVal "Windows")
  1292.    [Nic Gibson (nic@skin.demon.co.uk)]
  1293.  
  1294. 4. Any tips for speeding up VB?
  1295.  
  1296.    Who said "code in C"???? ;-)
  1297.  
  1298.    a. When SHOWing a form with lots of bound controls, have a blank
  1299.       frame covering everything. Then, in the Form_Activate event, set
  1300.       the Frame.Visible = False. This greatly speeds the display of
  1301.  
  1302.       the form and hides ugly thrashing as the data controls
  1303.       initialize.
  1304.       [Christopher Biow (biow@cs.umd.edu)]
  1305.  
  1306.    b. Try to keep any Global definitions to a minimum.  Massive
  1307.       numbers of global variables really seem to slow VB Windows down
  1308.       (besides chewing up memory).  In other words, if you've pasted a
  1309.       lot of stuff from the globals.txt file, trim all definitions and
  1310.       variables you don't use in your application.
  1311.  
  1312.    c. Keep the total number of controls and forms used to a minimum
  1313.       (you've probably already guessed that).
  1314.  
  1315.    d. Keep fancy graphics to a minimum (another one you know).
  1316.  
  1317.    e. Try "pre-processing" in the background (using Do_Events).
  1318.       Doesn't really speed anything up, but often there is a lot of
  1319.       "idle" time while the user is selecting menu's, buttons and such
  1320.       - if you can do some calculations, image loading or whatever
  1321.       during this idle time your user perceives the application is
  1322.       faster than it really is.
  1323.  
  1324.    f. Hide often-used forms rather than unloading them. Unloading
  1325.       saves memory, but it takes longer to re-load a form than to
  1326.       simply "un-hide" it.
  1327.       [Tips b to f by Galen Raben (galenr@gr.hp.com)]
  1328.  
  1329.    The following tip is along the same lines, but with a code sample.
  1330.    They are provided by Andy Dingley (dingbat@codesmth.demon.co.uk):
  1331.  
  1332.    You're limited by the system as to how quickly you can go from
  1333.    calling frmMyForm.Show to being able to type into the controls, but
  1334.    you can make the form *appear* to display faster. One technique is
  1335.    to keep forms loaded, and just switch their visibility on and off.
  1336.    This is heavy on resource usage, and doesn't help for the first
  1337.    time they're shown.
  1338.  
  1339.    Most forms have some processing (eg. querying a table to fill a
  1340.    list box) that goes on when they're first opened, and this is what
  1341.    causes the most serious delay. It's possible to display the form,
  1342.    make its controls appear on screen, then do the slow processing
  1343.    before finally making the form "live". As the user can see things
  1344.    happening, the perceived delay is less obvious.
  1345.  
  1346.    Include the following code in your form:
  1347.  
  1348.      Option Explicit
  1349.      Dim FirstActivation as integer
  1350.  
  1351.      Sub Form_Activate
  1352.         DoEvents   'Allow the _Load event to be seen on screen
  1353.         If FirstActivation Then
  1354.  
  1355.            ' Do all the slow loading stuff here
  1356.            If FillComboBox <> 0 Then
  1357.               Unload Me 'If it all goes horribly wrong, then you
  1358.                         'can call Unload from an _Activate event
  1359.                         '(Which you can't do from the _Load event)
  1360.            End If
  1361.            FirstActivation = False
  1362.         End If
  1363.         Screen.MousePointer = DEFAULT
  1364.      End Sub
  1365.  
  1366.      Sub Form_Load
  1367.         FirstActivation = True
  1368.      End Sub
  1369.  
  1370.    Show the form by using:
  1371.  
  1372.  
  1373.      Screen.MousePointer = HOURGLASS
  1374.      frmMyForm.Show MODAL
  1375.  
  1376.  
  1377.    Bruce Garrett (bruceg@access2.digex.net) had the following tips
  1378.    from his VBITS 93 notes:
  1379.  
  1380.    - Polling a control for its properties directly is 10 to 20
  1381.      times slower then placing the property values you need into
  1382.      variables and testing the value of the variables.
  1383.  
  1384.    - Swap tuning: Modules are not loaded until used; put related
  1385.      code in the same modules, reduce the number of intermodule
  1386.      calls and keep modules small.
  1387.  
  1388.    - Binary file I/O is faster then Text/Random.
  1389.  
  1390.    There was also a lot of discussion about "apparent" speed i.e: how
  1391.    it looks on the screen as opposed to how fast it's chugging
  1392.    internally. It was noted that the cute little flashing menu items
  1393.    and exploding windows in the Mac amounted to a little razzle-dazzle
  1394.    to distract you from how long it took to actually load something
  1395.    and get it on the screen.  Keeping all your forms loaded but hidden
  1396.    until needed was suggested.  Also the use of progress indicators
  1397.    and a simple quickly loaded and drawn startup form. Also preloading
  1398.    data you expect to need.
  1399.  
  1400. 5. How do I speed up control property access?
  1401.  
  1402.    Instead of using a property in a loop, you will be better off using
  1403.    a normal variable in the loop and then assign the variable once to
  1404.    the property afterwards. Also, when reading a property, you should
  1405.    read it once into a variable instead of using it in a loop.
  1406.  
  1407.    Sometimes it is not possible to simply put contents of a property
  1408.    into a variable. For example, if you are using a list box or you
  1409.    need to conserve memory. In these cases you can send the
  1410.    WM_SetRedraw message to the control to prevent redrawing. You can
  1411.    typically increase the speed 6-10 times - or even more.
  1412.  
  1413.      'Add the following declares:
  1414.      Declare Function SendMessage Lib "User" (ByVal hWnd As
  1415.      |Integer, ByVal wMsg As Integer, ByVal wParam As
  1416.      |Integer, lParam As Any) As Long
  1417.      Const WM_SetRedraw = &HB
  1418.  
  1419.      'Add this to your code:
  1420.      Result% = SendMessage(Text1.hWnd, WM_SetRedraw, 0, 0)
  1421.      'redraw off
  1422.      'Do your stuff here!
  1423.      Result% = SendMessage(Text1.hWnd, WM_SetRedraw, 1, 0)
  1424.      'redraw on
  1425.  
  1426.    This same method applies to list boxes and other controls.
  1427.  
  1428. 6. How much gain in performance will I get if I write my number
  1429.    crunching routines in C instead of Visual Basic?
  1430.  
  1431.    Probably the best solution to the number crunching problem is to
  1432.    write the number crunching routines as a custom control or a DLL,
  1433.    and plug it into a VB app. VB interface handling is not
  1434.    significantly slower than, say C++, and most of the wait is
  1435.    associated with Windows.
  1436.  
  1437.    Some real world experience speaks volumes about this one:
  1438.  
  1439.    I wrote some time consuming code in VB to solve a combinatorical
  1440.    (does this word exist in English?) problem. The code consists of
  1441.  
  1442.    one main recursive function, which calls itself very often. It took
  1443.    a night to compute a certain problem. I was rather disappointed and
  1444.    then decided to write the central routine in C++. It was a 1:1
  1445.    transcription. The routine was compiled with the MS C++-Compiler.
  1446.    It took only 22 Minutes for the same problem. Amazing, isn't it?
  1447.    The routine doesn't do any floating point arithmetic, only integer,
  1448.    and handles some arrays. The PC was a 33MHz 486. And the second
  1449.    amazing thing is, that a IBM RS6000 (560)-Risc-machine needed 17
  1450.    Min for the same code. I was the only one on the machine. I thought
  1451.    it should be much faster. The MS C++ seems to make very fast,
  1452.    optimized code. The optimization was configured to make fast code.
  1453.    [Christoph Steinbeck (steinbeck@uni-bonn.de)]
  1454.  
  1455. 7. How do you make a TEXTBOX read only? Or, how do I prevent the user
  1456.    from changing the text in a TEXTBOX?
  1457.  
  1458.    There's a lot of ideas on this one. You can grab the _KeyPress and
  1459.    _KeyDown events and set them to zero. However, the best idea is to
  1460.    use the Windows API SendMessage function to tell the control to
  1461.    become read-only:
  1462.  
  1463.      'After making the following declarations...
  1464.      Global Const WM_USER = &H400
  1465.      Global Const EM_SETREADONLY = (WM_USER + 31)
  1466.      Declare Function SendMessage Lib "User" (ByVal hWnd As
  1467.      |Integer ByVal wMsg As Integer, ByVal wParam As
  1468.      |Integer, lParam As Any) As Long
  1469.  
  1470.      'Then Try:
  1471.      SendMessage(Text1.hWnd, EM_SETREADONLY, 1, 0)
  1472.      [Pete Jones (pjones@csi.compuserve.com)]
  1473.  
  1474.    This will still allow the user to copy *from* the text box. If you
  1475.    need to disable this (why?), steal the Ctrl-C in the _KeyPress
  1476.    event.
  1477.  
  1478. 8. How can I create a VBX?
  1479.  
  1480.    VBXs (Visual Basic eXtensions) are practically always written is C
  1481.    (Borland C++, but mainly MS VC++). You should refer to the _Control
  1482.    Development Guide_ (in VB Professional Features Vol. I) and any
  1483.    relevant documentation for your compiler. Followup questions should
  1484.    normally be directed to comp.os.ms-windows.programmer.* or
  1485.    comp.lang.c*.
  1486.  
  1487.    There are some example VBX's with C code supplied with VB3 Pro.
  1488.    You'll find them under the directory [VB]\CDK.
  1489.  
  1490. 9. How do you change the system menu (on the Control-Menu Box)?
  1491.  
  1492.    You can turn off the minimize and maximize menu options by changing
  1493.    properties, but what if you need to remove the "close" option?
  1494.  
  1495.      'Make the following declares.
  1496.      Declare Function GetSystemMenu Lib "User" (ByVal hWnd
  1497.      |As Integer, ByVal bRevert As Integer) As Integer
  1498.      Declare Function RemoveMenu Lib "User" (ByVal hMenu
  1499.      |As Integer, ByVal nPosition As Integer, ByVal wFlags As
  1500.      |Integer) As Integer
  1501.      Global Const MF_BYPOSITION=&H400
  1502.  
  1503.      'Use the following code to remove the "close" option.
  1504.      SystemMenu% = GetSystemMenu (hWnd, 0)
  1505.      Res% = RemoveMenu(SystemMenu%,6, MF_BYPOSITION)
  1506.      '(also remove the separator line)
  1507.      Res% = RemoveMenu(SystemMenu%,6, MF_BYPOSITION)
  1508.  
  1509.    Adding menu items to the control menu is more complicated, since
  1510.    you need to respond to the events triggered when the user selects
  1511.  
  1512.    the new options. The newest Message Blaster (msgblast.vbx, see
  1513.    details in beginning of FAQ about how to get files) contains
  1514.    example code.
  1515.  
  1516. 10.How do I play MID, WAV or other multimedia files?
  1517.  
  1518.    Use the MSMCI.VBX, provided with VB/Win Pro 3.0. You can also
  1519.    declare and call the MM-functions manually:
  1520.  
  1521.      Declare Function mciExecute Lib "MMSystem"
  1522.      |(ByVal FileName as String) As Integer
  1523.  
  1524.      Sub Form1_Click ()
  1525.          iResult = mciExecute("Play c:\windows\mkmyday.wav")
  1526.      End Sub
  1527.  
  1528. 11.How can I call a 'hidden' DOS program from VB?
  1529.  
  1530.    If you run a DOS program minimized using the SHELL command, it will
  1531.    never complete. This is because DOS tasks by default are NOT setup
  1532.    to run in the background. The easiest way to get around this is to
  1533.    make a PIF file for the program you need to run with the
  1534.    "Background" option checked. Then SHELL to the PIF file to run the
  1535.    DOS program and it will return control to your VB application when
  1536.    it terminates.
  1537.  
  1538.    Tip: If you edit or replace the _DEFAULT.PIF file in the Windows
  1539.    directory to allow execution in background, this will apply to all
  1540.    DOS boxes that is not run with it's own .pif!
  1541.  
  1542. 12.How do I do drag & drop between applications? [++]
  1543.  
  1544.    MSGBLAST.ZIP (the famous Message Blaster by Ed Staffin and Kyle
  1545.    Marsh) available on Cica and mirrors tell you *everything* you want
  1546.    to know about this and other advanced stuff. This is now
  1547.    (inexpensive) shareware, but the older freeware version is still
  1548.    supposed to be available. Get the file mentined above for more
  1549.    info.
  1550.  
  1551.    Short glossary for the confused ones  :-)
  1552.    Drag & Drop Client: the form you drop objects to/on
  1553.    Drag & Drop Server: the form you drag object(s) from
  1554.  
  1555. 13.How do I use GetPrivateProfileString to read from INI files? [++]
  1556.  
  1557.    There's a good example of accessing *.INI files in the Knowledge
  1558.    Base, but here's the basic idea:
  1559.  
  1560.      'You declare these API function as usual:
  1561.      Declare Function GetPrivateProfileString Lib "Kernel"
  1562.      |(ByVal lpApplicationName As String, ByVal lpKeyName
  1563.      |As Any, ByVal lpDefault As String, ByVal
  1564.      |lpReturnedString As String, ByVal nSize As Integer,
  1565.      |ByVal lpFileName As String) As Integer
  1566.  
  1567.      'Then in your code you do like below:
  1568.      strIniFile = "WIN.INI"
  1569.      strSection = "MyProgram"
  1570.      strKey = "Language"
  1571.      strDefault = "English"
  1572.      iLength = 70
  1573.      strReturn = String$(iLength, " ")  'Pad the string first!
  1574.      iResult = GetPrivateProfileString(strSection, strKey,
  1575.      |strDefault, strReturn, iLength, strIniFile)
  1576.  
  1577.    WARNING: Be aware that there was an ERROR in the Windows 3.1 API
  1578.    documentation that came with VB. Here's the scoop:
  1579.  
  1580.    Knowledge Base article Q110826 (DOCERR: GetPrivateProfileString
  1581.    Declaration Incorrect in API) corrects a documentation error for
  1582.    the GetPrivateProfileString function call as described in the
  1583.    Windows version 3.1 API Reference help file that shipped with
  1584.    Microsoft Visual Basic version 3.0 for Windows. The CORRECT
  1585.    declaration is as follows:
  1586.  
  1587.      Declare Function GetPrivateProfileString Lib "Kernel"
  1588.      |(ByVal lpApplicationName As String, ByVal lpKeyName
  1589.      |As Any, ByVal lpDefault As String, ByVal
  1590.      |lpReturnedString As String, ByVal nSize As Integer,
  1591.      |ByVal lpFileName As String) As Integer
  1592.  
  1593.    Note that the "ByVal" keyword was omitted from the second parameter
  1594.    in the online reference. This means that the function is passing
  1595.    the second parameter (lpKeyName) by reference. It needs to be
  1596.    passed by value.
  1597.  
  1598.    The most common problem that occurs when using the incorrect
  1599.    declaration is that when the function is called, it returns a copy
  1600.    of "lpdefault" in the "lpReturnedString" parameter instead of the
  1601.    actual value referenced by KeyName.
  1602.  
  1603.    OOPS: As P. Wierenga (pwiereng@sol.UVic.CA) told me, the same doc
  1604.    error applies to Writeblablabla:
  1605.  
  1606.    DOCERR: WriteProfileString Declaration Incorrect in API Article ID:
  1607.    Q115328
  1608.  
  1609.    The correct declaration is as follows:
  1610.  
  1611.    Declare Function WritePrivateProfileString Lib "Kernel"
  1612.                                     (ByVal lpApplicationName As
  1613.    String,
  1614.                                      ByVal lpKeyName As Any,
  1615.                                      ByVal lpString As Any,
  1616.                                      ByVal lplFileName As String) As
  1617.    Integer
  1618.  
  1619.    (all on one line of course!)
  1620.  
  1621.  
  1622. 14.How do I implement Undo?
  1623.  
  1624.    For most controls, you will have to keep track of changes yourself.
  1625.    There's no magic involved, just some coding. However, if you use
  1626.    the standard Text box or Combo box, Windows provides a "free" undo
  1627.    function for you!
  1628.  
  1629.      'Do the following declares:
  1630.      Declare Function SendMessage Lib "User" (ByVal hWnd As
  1631.      |Integer, ByVal wMsg As Integer, ByVal wParam As
  1632.      |Integer, lParam As Any) As Long
  1633.      Global Const WM_USER = &h400
  1634.      Global Const EM_UNDO = WM_USER + 23
  1635.  
  1636.      'And in your Undo Sub do the following:
  1637.      UndoResult = SendMessage(myControl.hWnd, EM_UNDO, 0, 0)
  1638.      'UndoResult = -1 indicates an error.
  1639.  
  1640. 15.How do I create a window with a small title bar as in a floating
  1641.    toolbar?
  1642.  
  1643.    Download the MSGBLAST VBX from ftp.microsoft.com (filename "8-
  1644.    3.ZIP") or (better) from ftp.cica.indiana.edu. The example files
  1645.    provide an example of a form with a small title. When you see it,
  1646.    you'll understand why I haven't include a full explanation here!
  1647.  
  1648. 16.What is Pseudocode?
  1649.  
  1650.    VB/Win does not generate machine code like most compilers do.
  1651.    Instead it creates what is called pseudocode (a real misnomer,
  1652.    IMO). A good explanation is given below:
  1653.  
  1654.    A bit of history: the original P-code was an instruction set for a
  1655.    "virtual Pascal" machine. This came with a portable Pascal compiler
  1656.    written at ETH in Zuerich. The portable compiler produced
  1657.    instructions for this phony machine which had an instruction set
  1658.    ideally suited to the stack and heap management of Pascal.  To
  1659.    executed portable Pascal programs, you had two choices: either
  1660.    write an interpreter for P-code, or translate the small set of P-
  1661.    code instructions (there were about 80) into assembler; assemble
  1662.    it; and run it at native speed.  Thus "P-code" originally stood for
  1663.    "Portable" or "Pascal" code. The broader meaning, "pseudo-code"
  1664.    came later. P-code was widely popularized by the UCSD Pascal
  1665.    system, a small workstation that was implemented entirely in Pcode
  1666.    and interpreted. It was sold for some years, and one company even
  1667.    re-did the microcode for a PDP-11 microchip to interpret P-code.
  1668.    The original Borland Turbo Pascal had obvious similarities to the
  1669.    UCSD system although it was not interpreted. The dialect was
  1670.    virtually identical.  Today P-code is used extensively in Microsoft
  1671.    apps, for two reasons. First, it is much more compact than  native
  1672.    code; so the apps are smaller. Second, having an interpreter at the
  1673.    core of an app makes it much easier to customize and extend. That
  1674.    is why VB is becoming the heart of the MS major apps.  It is simply
  1675.    not true that P-code apps run much slower than native apps. The
  1676.    slowdown is determined by the granularity of the interpreted
  1677.    routines. If every little thing is an interpreted op, the slowdown
  1678.    might be as much as 3-to-1 for the 80x86 architecture, or about 2-
  1679.    to-1 for the Motorola 68000 family (which is better suited to
  1680.    writing interpreters).  But in practice, modern P-code systems have
  1681.    large-scale instructions, each of which is executed by a big
  1682.    compiled subroutine. These subs run at native speed, so the
  1683.    overhead of the interpreter is occasional at worst.
  1684.    [Roger E. Ison (r_ison@csn.org)]
  1685.  
  1686.    It is also possible that since the code may not need recompilation
  1687.    to run on other platforms *if* the run-time interpreter is first
  1688.    ported, VB applications can become very portable. This depends on
  1689.    Microsoft's long-term plans.
  1690.  
  1691.    A note on the word "pseudocode": I wrote above that it is a
  1692.    misnomer, and I stand on that. Pseudocode is *really* the pascal-
  1693.    like (mostly) explanation of an algorithm that is intended for
  1694.    human readers, not computers. But since somehow the term pseudocode
  1695.    stuck to the psaudo-machine-code created by VB the word is used
  1696.    here.
  1697.  
  1698. 17.Does VB support pointers to functions?
  1699.  
  1700.    No, it does not.
  1701.    [George Tatge (gat@csn.org)]
  1702.  
  1703. 18.How do I program the Novell NetWare API from VB? [++]
  1704.  
  1705.    Tom Tregilgas (Tom.Tregilgas@InfoB.unisg.ch) had a lot of
  1706.    information on this one. Normally I leave it to the other FAQ parts
  1707.    to list books & how-to-get-info's, but since this topic is very
  1708.    specific and more NetWare than VB I include all the stuff here for
  1709.    your convenience:
  1710.  
  1711.    If you are interested in seeing how Visual Basic can be used for
  1712.    NetWare programming, obtain the following files from your friendly
  1713.    neighboorhood Novell FTP Mirror site.
  1714.  
  1715.    Mirror sites are (according to ftp.novell.com):
  1716.  
  1717.          Novell Germany            ftp.novell.de
  1718.          Netherlands               ftp.rug.nl
  1719.          United Kingdom            ftp.salford.ac.uk
  1720.          Logan, Utah               netlab2.usu.edu
  1721.          New Zealand               tui.lincoln.ac.nz
  1722.          Tuscaloosa, Alabama       risc.ua.edu
  1723.          Ottowa, Ontario, CA       novell.nrc.ca
  1724.          Boston, Mass              bnug.proteon.com
  1725.  
  1726.    novlib\11\nivb.zip              Netware Interface for Visual Basic
  1727.    novlib\11\nwtest.zip            NetWare Test for Visual Basic
  1728.  
  1729.    There are also two Novell App Notes on the subject of using NetWare
  1730.    with Visual Basic (although this is _NOT_ supported by Novell...)
  1731.    which are:
  1732.  
  1733.    October 92      Interfacing Visual Basic for Windows and NetWare
  1734.    July 93         A NetWare Interface for Visual Basic
  1735.  
  1736.    The AppNotes can be obtained by contacting the Novell Research
  1737.    Order Desk, FAX: +1 303 294-0903, Voice 800 377-4136, +1 303 297-
  1738.    2725.  Address as follows:
  1739.  
  1740.    Novell Research Order Desk
  1741.    1601 Park Avenue West
  1742.    Denver, CO 80216-5199
  1743.  
  1744.    AppNotes are $95/year ($135 outside US)
  1745.  
  1746.    Here are a few books which might help you out to figure the calls
  1747.    out:
  1748.  
  1749.    Windows Development on NetWare Systems, Lori Gauthier and Sue
  1750.    Whitehead (c) 1994, Windcrest, Blue Ridge Summit, PA 17294-0850
  1751.    (McGraw-Hill) $34.95 Comes with disk This book also tells you how
  1752.    to "upgrade" to the currently supported SDK calls
  1753.  
  1754.    NetWare System Interface Technical Overview, Novell (c) 1990,1989
  1755.    (Addison-Wesley), $32.95 (describes Novell's C Network Compiler
  1756.    API's)
  1757.  
  1758.    Visual Basic Programmer's Guide to the Windows API, Daniel Appleman
  1759.    Ziff-Davis Press, 5903 Christie Ave, Emeryville, CA 94608, $34.95
  1760.    Comes with disk
  1761.  
  1762.    It should be mentioned that the APIs included with the NIVB are
  1763.    _not_ current, and for this purpose, you should get the Novell SDK
  1764.    kit. Also, Novell will not support NIVB, but you can sometimes get
  1765.    some helpfrom Compu$erve, or from others on the Infobahn <g>
  1766.  
  1767.    Good luck!
  1768.  
  1769.    p.s. It behooves you to become a member in the PDP (Professional
  1770.    Developer's Program) since you get the AppNotes (& Bullets!)
  1771.    for...free.
  1772.  
  1773.    p.p.s. Novell does NOT support the NIVB...
  1774.  
  1775.    p.p.p.s. Also, no docs come with it.  You'll probably need the
  1776.    Client C SDK kit to be able to really _use_ the code.
  1777.  
  1778.    p.p.p.p.s. To make things even better, the calls in NIVB are fairly
  1779.    old, and not of the Client C SDK kit variety.  However, there _are_
  1780.    books which could help you out, e.g. "NetWare System Interface
  1781.    Technical Overview", by Novell. ISBN:0-201-57027-0, published by
  1782.    Addison-Wesley Publishing co, $32.95 US, $42.95 in Canada.
  1783.  
  1784.    Update:
  1785.  
  1786.    AppNotes are dead, however, Develper Notes live on.  There is one
  1787.    article about NetWare programming with Visual Basic here:
  1788.  
  1789.    July/Aug 94     NetWare Programming in Visual Basic:
  1790.                    Using Apiary's NetWare Client SDK for Visual Basic
  1791.  
  1792. 19.Some Visual Basic 4 rumours
  1793.  
  1794.    First, we have no special information. This is just rumours,
  1795.    guessing, gossip! But since there are many questions about this on
  1796.    the newsgroup, *and* Microsoft gives these controlled leakages
  1797.    through their beta testers, we bring on some of it (Please, don't
  1798.    start discussing NDA's on this group again!):
  1799.  
  1800.    a. Two versions: 32-bit and 16-bit
  1801.       Like Visual C++ 1.5, VB 4 will come with compilers for the 16-
  1802.       bit API from Windows 3.1 as well as a real 32-bit compiler (or
  1803.       pseudocompiler) for Windows 4 (Chicago) bundled together.
  1804.  
  1805.    b. New features will probably be inherited from VBA
  1806.  
  1807.       1)   Line continuation character " _" (space+underscore)
  1808.  
  1809.       2)   WITH statement, known from Pascal, to save typing and make
  1810.            code cleaner. An example:
  1811.  
  1812.              With Form1
  1813.                With Text1
  1814.                  Bold = true
  1815.                  FontName = "New Times Roman"
  1816.                End With
  1817.              End With
  1818.  
  1819.       3)   FOR EACH .. NEXT statement allows you to make changes to a
  1820.            group of objects at once better than FOR..NEXT. Object
  1821.            groups are also something you may have to work closer with
  1822.            in VB4.
  1823.  
  1824.       4)   An OPTIONAL statement allows you to leave some Variant
  1825.            parameteres undefined when calling a user-defined sub or
  1826.            function. Also in VBA is an ARRAY function that returns an
  1827.            array form a list supplied as parametres, and a special
  1828.            optional ParamArray optional parameter of Variants.
  1829.  
  1830.       5)   Boolean data type. Integer does the job, but this type can
  1831.            preserve space if Microsoft codes it right.
  1832.  
  1833.       6)   Byte data type? No, VBA does not support this. We can
  1834.            dream, however.
  1835.  
  1836.    c. VBX is dead. Long live OCX!
  1837.  
  1838.       You may not feel for celebrating this either, but the 32 bit VB
  1839.       4 will not support the old 16-bit VBX'es. The 16-bit version of
  1840.       VB 4 will support them for backwards compatibility, but be aware
  1841.       that OLE 2 and OCX is the way of the future, at least if
  1842.       Microsoft gets it as they want.
  1843.  
  1844.  
  1845. E. CALLING THE WINDOWS API AND DLLs IN GENERAL
  1846.  
  1847.  
  1848. 1. What is the Windows API?
  1849.  
  1850.    The Windows API (Application Program Interface) is a collection of
  1851.    Dynamic-Link Libraries (DLLs) that do most of the common things in
  1852.    Windows. Calls to the Windows API gives you access to routines that
  1853.    do things like drawing menu bars, manipulating bitmaps, playing
  1854.    sound files, and pretty much every other function of Windows.
  1855.  
  1856. 2. How do I call a DLL?
  1857.  
  1858.    Basically, you declare a DLL procedure which you can call in your
  1859.    VB program which in turn passes data to and/or retrieves data from
  1860.    the DLL. You should read the section of the VB manual that talks
  1861.    about calling DLLs ("Chapter 24  Calling Procedures in DLLs" in the
  1862.    VB 3.0 Programmer's Guide). This chapter covers the basics of using
  1863.    the Windows API DLLs and calling DLLs in general. Beyond that you
  1864.    may want to find a good book on this subject since it is too large
  1865.    to cover here (see the Book Listing in the Appendix of the General
  1866.    FAQ - Part 1). Don't be too intimidated!  Using DLLs (especially
  1867.    many of the Windows API functions) is quite easy, once you learn
  1868.    how to call them. In fact, many of the newer DLLs include VB-
  1869.    compatible modules!
  1870.  
  1871. 3. What about DLL calls that require callbacks?
  1872.  
  1873.    VB does not support callbacks, but various extensions can help.
  1874.  
  1875.    Dan Appleman's "Visual Basic Programmer's Guide to the Windows API"
  1876.    comes with a floppy disk which code samples and tools. It also
  1877.    includes a VBX which supports the callbacks which many API calls
  1878.    require. Dan is also founder and president of Desaware which sells
  1879.    more extensive tools, including SpyWorks, for VB developers.
  1880.    [Walter Hill (whill@netcom.com)]
  1881.  
  1882. 4. Tips for calling DLLs (such as the Windows API)
  1883.  
  1884.  
  1885.    a. Using the BYVAL keyword is critical. Using it when you're
  1886.       supposed to call by reference and (more common) not using it
  1887.       when you are to give a value to the external function are the
  1888.       single most common mistakes. Wrong calling convention can often
  1889.       result in a General Protection Fault (GPF) or, even worse,
  1890.       corruption of another applications' data.
  1891.  
  1892.    b. Check return and parameter types. For return types, a C function
  1893.       declared as "void" means you use a Sub not a Function.
  1894.  
  1895.    c. Initialize strings by padding it to the necessary length! If you
  1896.       pass a string that is too short to the API it will happily write
  1897.       past the end of the string and possibly corrupt data.
  1898.  
  1899.    d. Use Option Explicit. A typing error that results in a bug in the
  1900.       VB source will occasionally cause a GPF when you call external
  1901.       code.
  1902.  
  1903.    e. It's a jungle out there! Check parameter values as there is no
  1904.       type checking outside VB. If you make a mistake, you'll often
  1905.       get a GPF.
  1906.  
  1907.    f. Save before you run! You may even need to restart Windows after
  1908.       a GPF, since DLL's often aren't unloaded properly. As a second
  1909.       option you can check out WPS (Windows Process Status) which is
  1910.       distributed with VB/Pro and placed in the CDK directory. This
  1911.       utility allows you to kick out any module (EXE, DLL) from memory
  1912.       (shooting yourself in the foot if you want to. WPS is a nice way
  1913.       to find out what DLLs are actually used, but save your work
  1914.       first!).
  1915.  
  1916.  
  1917. F. VISUAL BASIC AND DATABASES
  1918.  
  1919.  
  1920. 1. Why can't I use an index with my VB accessed database?
  1921.  
  1922.    There is a mistake in the docs which says you can set the active
  1923.    index for a recordset. You can't. The data control uses the primary
  1924.    key for tables and physical order (I think) for dynasets.
  1925.  
  1926.    [Nic Gibson (nic@skin.demon.co.uk)]
  1927.  
  1928. 2. Why does my compiled VB database app generate an error when it ran
  1929.    just fine in the design environment?
  1930.  
  1931.    You can thank Microsoft for documenting this topic so poorly. When
  1932.    you compile your VB database application, you must also have an INI
  1933.    file for it which provides the correct pointers to the appropriate
  1934.    database drivers. Therefore, if your application is named
  1935.    "INVOICE.EXE", you will need to have a properly configured
  1936.    "INVOICE.INI" file in your Windows directory. The file,
  1937.    EXTERNAL.TXT, that came with VB should explain all about it.
  1938.  
  1939. 3. Is the Access Engine and Visual Basic Pro good enough for database
  1940.    work?
  1941.  
  1942.    That, of course, depends. Generally the answer is "yes", but you
  1943.    may need some third-party add-on products.
  1944.  
  1945.    These are the major weaknesses of VBPro's database functions:
  1946.  
  1947.    a. Limited data controls: No add, delete or search button; no bound
  1948.       list box or masked edit control and - the worst - no bound grid!
  1949.  
  1950.    b. No run-time query builder ("how good is your user in SQL?") or
  1951.       report builder.
  1952.  
  1953.    c. No direct advanced control of the Access 1.1 (or 2) Database
  1954.       Engine (ie. security, optimization, etc).
  1955.  
  1956.    The good news is that lots of companies are willing to sell you
  1957.    products which address one or more of the above weaknesses.
  1958.  
  1959.    Also, if you build a database application with advanced database
  1960.    relations, it can be a good idea to build the database itself with
  1961.    Access and the front-end with VB.
  1962.  
  1963. 4. How do you avoid the "Invalid use of null" error when reading null
  1964.    values from a database?
  1965.  
  1966.    If you try to retrieve a null value (empty field) from a database,
  1967.    you will get the error: "Invalid use of Null". Here is one way to
  1968.    get around this problem:
  1969.  
  1970.    I've worked around this problem with the following code:
  1971.  
  1972.      TextBox.Text = MyTest.Fields("TestFld") & ""
  1973.  
  1974.    This code converts the Null-Value into an empty string.
  1975.    [Ralf Metzing (rmm@dragon.stgt.sub.org)]
  1976.  
  1977. 5. What is "NULL"?
  1978.  
  1979.    Contrary to popular belief, Null is not nothing. It's even less
  1980.    than nothing.   8^)
  1981.  
  1982.    The VB documentation describes all the horrors of misunderstanding
  1983.    the infamous NULL. Since people don't read the documentation, we
  1984.    feel like informing that
  1985.  
  1986.      If ThisVarIsNull = NULL then DoSomething
  1987.  
  1988.    will *always* fail, and the DoSomething can't possibly be executed.
  1989.    You *must* use IsNull(ThisVarIsNull) which will return True if the
  1990.    var is Null (phew!).
  1991.  
  1992.    If you want to find out why someone came to think of this strange
  1993.    value, read some relational database theory.
  1994.  
  1995. 6. How can I access a record by record number?
  1996.  
  1997.    Use a counter or index field and access the record with this.
  1998.  
  1999.    It is *impossible* to ask a relational database system to give you
  2000.    ie. "field number 3 in record number 10" since by definition a
  2001.    relational database does not have row or column numbers. Databases
  2002.    allowing direct access like that is not even remotely relational.
  2003.  
  2004.    Access (and therefore, VB) is about as close to a real relational
  2005.    database system as you can get.
  2006.  
  2007. 7. How about Access 2.0 compatibility?
  2008.  
  2009.    You need the compatibility layer availability. The file COMLYR.EXE
  2010.    is in the MSBASIC library on Compuserve. This file provides all the
  2011.    items necessary for compatibility between VB 3.0 and Access 2.0.
  2012.    [Fred Griffin (72321.3230@compuserve.com)]
  2013.  
  2014.    The file COMLYR.EXE can be downloaded from ftp.microsoft.com. It is
  2015.    located in the directory /softlib/mslfiles.
  2016.  
  2017. 8. Tips for VB database programming:
  2018.  
  2019.  
  2020.    a. Use Access and QBE. Once it's "working" (even if the parameters
  2021.       are hardcoded), then open up View.SQL and copy the stuff from
  2022.       the SQL window into your VB code. If you need to insert VB
  2023.       variables, try testing this under Access by using parameters
  2024.       instead. They're then nice & easy to spot when it comes to
  2025.       converting into VB - I always call my parameters "PR_xxxx", so I
  2026.       can just search my VB code for this to find any instances that
  2027.       I've missed.
  2028.  
  2029.    b. It never works first time. So put an error handler into your VB
  2030.       code that copies the contents of SQLStr onto the clipboard,
  2031.       should the query fail. Now it's quick & easy to switch back to
  2032.       Access, find a scratch query and paste the erroneous SQL into
  2033.       that. It's *much* easier to debug a SQL query in Access, after
  2034.       the variables have been merged in, than it is to do it blind
  2035.       from VB.
  2036.  
  2037.    c. Use carriage returns to break up your SQL. One before each
  2038.       reserved word is sensible. They're not significant in SQL. I
  2039.       assume you're not stupid enough to put them in the middle of
  2040.       field names - unfortunately Debug.Print is!
  2041.  
  2042.    d. When merging in the contents of a variable (building a SQL query
  2043.       in a VB string), it should *always* be surrounded by an
  2044.       ampersand and 3 double quotes, or an ampersand and 2 mixed
  2045.       quotes, depending on your local conventions:
  2046.  
  2047.         SQLStr = SQLStr & "WHERE Username <= """ & Username$ """ "
  2048.  
  2049.         or
  2050.  
  2051.         SQLStr = SQLStr & "WHERE Username <= '" & Username$ "' "
  2052.  
  2053.    e. If you're using dates, then it will *always* be one quote, a
  2054.       hash and an ampersand:
  2055.  
  2056.         SQLStr = SQLStr & "WHERE Start_Date <= #" &
  2057.         |Format$(CutOffDate,"Long Date") & "# "
  2058.  
  2059.    f. Another tip with dates is to format them with the long date
  2060.       format, not the short date. This is then safe against the
  2061.       transatlantic reversal of month & day position.
  2062.  
  2063.    g. If you're merging in a field/table name, enclose it in square
  2064.       brackets. That way the SQL will still be valid if the variable
  2065.       contains spaces:
  2066.  
  2067.         SQLStr = "SELECT * FROM [" & TableName$ "] ;"
  2068.  
  2069.       When building SQL strings in VB, then you'll often do this on
  2070.       several lines, concatenating SQLStr with the new string. If you
  2071.       leave a space at the end of every string, then you can guarantee
  2072.       you won't have problems with the text from successive lines
  2073.       running into each other.
  2074.  
  2075.    h. If you're using Access 1, you'll keep running into the 1024
  2076.       character limit on the length of a SQL string. Keep the table &
  2077.       field names short, especially if many JOINs are concerned. Using
  2078.       underscores in names is shorter than spaces, as you don't need
  2079.       the extra 2 characters for the square brackets around them. If
  2080.       your SQL is slightly too long, then you'll probably see a
  2081.       "Missing semicolon" error, even though the semicolon is
  2082.       obviously there (To you, anyway!).
  2083.  
  2084.    i. Making a QueryDef is a complicated process that is often slower
  2085.       than executing the query ! Don't mess with the .SQL property, as
  2086.  
  2087.       that is equally slow (Access needs to do a lot of work to turn
  2088.       SQL into its internal query format). Two ways around this: Use
  2089.       ready-built queries, written with Access. If you need to merge
  2090.       in values from variables, then use a query with parameters.
  2091.       Setting parameter values is quick to execute.
  2092.  
  2093.    j. If you really need to build SQL on the fly -- you need to build
  2094.       an ad hoc query, or to supply table or field names (which can't
  2095.       be done with query parameters), then try using:
  2096.  
  2097.         database.Execute SQLStr
  2098.  
  2099.       As this doesn't build a QueryDef, then it's quick.
  2100.       [All tips a to j by Andy Dingley(dingbat@codesmth.demon.co.uk)]
  2101.  
  2102. 9. How come I get a "No Current Record" error when I use a a Data
  2103.    Control on an empty table?
  2104.  
  2105.    Well, this is a "feature" courtesy of Microsoft.  KB article
  2106.    Q106494 explains this in detail.  Basically, the workaround is to
  2107.    add an empty record to the table before the user can do anything
  2108.    (or before you try to do any Moves on the Table).
  2109.    [George Tatge (gat@csn.org)]
  2110.  
  2111. 10.How can I speed up my VB database application?
  2112.  
  2113.    KB article Q109830 gives some hints.  Things you should do include:
  2114.  
  2115.    - Use Snapshots when possible.
  2116.    - Use transactions whenever possible.
  2117.    - Use Dynasets when possible.
  2118.    - Use SQL action queries when possible.
  2119.    [George Tatge (gat@csn.org)]
  2120.  
  2121. 11.How do I get a bitmap picture in a field in an Access database?
  2122.  
  2123.    See p.466 of the Visual Basic (3.0) Programmer's Guide. It contains
  2124.    a section called "Using Bound Picture Box and Image Controls".
  2125.    Basically you have to bind the VB PictureBox to a field in the
  2126.    Access DB, set the .Picture property in the PictureBox, and then
  2127.    move to the next record or something. VB will then store your
  2128.    picture in Access in a form in which it can be retrieved by VB in
  2129.    the future.
  2130.  
  2131.    If you store the pictures in Access directly (using Access), VB
  2132.    won't be able to read them (using VB 3.0 and Access 1.1).
  2133.  
  2134.    You can also store the picture's filename as a text field in the
  2135.    database and use LoadPicture() to load that file into the VB
  2136.    PictureBox.
  2137.    [Tim Shea (shea@marcam.com)]
  2138.  
  2139. 12.What is "Reserved Error -1209"? [**]
  2140.  
  2141.    You will get a Reserved Error [-1209] ("There is no message for
  2142.    this error")
  2143.    when your database is corrupted. Try opening the database using MS
  2144.    Access;
  2145.    if it's corrupted you should get the option to repair it.
  2146.    [Joe Abley (joe_abley@originuk.demon.co.uk)]
  2147.  
  2148.    You should also compact it, after repair. I recommend you add the
  2149.    following to your File menu on your main form:
  2150.  
  2151.      Case ...
  2152.  
  2153.        RepairDatabase Curentdatabasename
  2154.  
  2155.      Case ....
  2156.  
  2157.  
  2158.        On Error resume next
  2159.        Kill "temp.MDB"
  2160.        Name  curentdatabasename as "temp.mdb"
  2161.        on error goto errcompact
  2162.        compactdatabase "temp.mdb", Currentdatabasename
  2163.        kill "temp.mbd"
  2164.        exit sub
  2165.  
  2166.      errcompact:
  2167.        msgbox "compaction failed"
  2168.        name "temp.mdb" as Currentdatabasename
  2169.  
  2170.      Case ...
  2171.  
  2172.    [Ayn Shipley (ashipley@hookup.net)]
  2173.  
  2174. 13."Cannot perform operation. illegal.." with Paradox 3.5 table(s)
  2175.    [**]
  2176.  
  2177.    Your Paradox table must have a primary key, or it will be read-only
  2178.    no matter    what you set its properties to.
  2179.    [Ayn Shipley (ashipley@hookup.net)]
  2180.  
  2181.  
  2182. G. DISTRIBUTING VISUAL BASIC APPLICATIONS
  2183.  
  2184.  
  2185. 1. What are some tips for using Setup Wizard?
  2186.  
  2187.    There were loads of bugs in the setup utilities supplied with VB3.
  2188.    Be sure to get the newest version of SETUPKIT (usually called
  2189.    SETUPK.EXE or -.ZIP). It is available from the sources listed in
  2190.    the beginning of this document, and in the General FAQ.
  2191.  
  2192.    Alternatively, if you have the older versions, you may have to
  2193.    manually remove the line referring to OLE2UI.DLL in the file
  2194.    SETUPWIZ.INI. See later in this document for dates of newest files
  2195.    on ftp.microsoft.com.
  2196.  
  2197.    Follow the instructions in SETUPK.TXT exactly. The files actually
  2198.    belong in two separate directories. Not placing them correctly can
  2199.    create strange and unusual side effects -- none of them good(!)
  2200.  
  2201.    Set all involved EXE, DLL and VBX files to Read-Only so that the
  2202.    setup program doesn't modify them.
  2203.    [Charles F. Mulks (21667cfm@msu.edu)]
  2204.  
  2205.    A *very* good tip. Actually, make all executables on your system
  2206.    read-only. If not, you can get a sharing violation if you try to
  2207.    run the same DOS executable twice at the same time.
  2208.  
  2209.    Also, the source code for a SETUP program is *included* with VB3
  2210.    Pro. It is quite trivial to tailor it to your specific needs.
  2211.  
  2212.    The question remains: Is SetupWiz good? No! Good enough? Perhaps.
  2213.  
  2214. 2. Are there restrictions on what I can distribute with my VB program?
  2215.  
  2216.    The documentation tells what parts of the Visual Basic kit you can
  2217.    freely distribute: the VBX files, some DLL's and what the SetupKit
  2218.    includes on your distribution diskettes. Reading software license
  2219.    agreements may be more boring than asking the newsgroup, but is
  2220.    nevertheless a good idea. 8^)
  2221.  
  2222.    There have been some rumours on the newsgroup that you can't
  2223.    redistribute programs written with VB freely. This is nonsense. All
  2224.    applications created with VB can be redistributed freely without
  2225.  
  2226.    royalties (as long as you don't distribute proprietary external
  2227.    files).
  2228.  
  2229.    The rumours probably originated when Microsoft announced that they
  2230.    will not sell kits allowing third-party software to include the
  2231.    Visual Basic for Applications (VBA) system.
  2232.  
  2233. 3. What alternatives to setup wizard do I have?
  2234.  
  2235.    Perhaps the best one is to simply modify the setup app which is
  2236.    supplied with VB.  Look in your VB directory for the setupkit\
  2237.    setup1 directory.  There you will find everything you need to do a
  2238.    complete setup program.  This sample setup is coded to install a
  2239.    few sample app files and create a program group.  You can comment
  2240.    out those lines and change to your files and program mgr. group.
  2241.    There are also a few global variables you will want to change.  All
  2242.    of this is contained in the comments in the code.
  2243.  
  2244.    Using this, and the distribution information in the manual telling
  2245.    you about which files to distribute with your app will make things
  2246.    much easier than using the setup wizard (IMNSHO).
  2247.  
  2248.    There are also several third party setup products available.
  2249.    [George Tatge (gat@csn.org)]
  2250.  
  2251. 4. Do I need to worry about users who have Progman replacements such
  2252.    as Norton Desktop and PC Tools?
  2253.  
  2254.    Earlier versions of those products and some others do not respond
  2255.    properly to the DLL commands to create groups and items.  More
  2256.    recent versions do.  All you can do in this case is to include some
  2257.    information in your readme.txt file that instructs users of those
  2258.    products to shut them down and start up program manager before
  2259.    installing.
  2260.    [George Tatge (gat@csn.org)]
  2261.  
  2262. 5. Can I distribute my app without vbrunXXX.dll?
  2263.  
  2264.    If you are sure that your users have it or can get it, you can
  2265.    easily distribute your app without vbrunXXX.dll.  Simply remove the
  2266.    file from your distribution disk or zip file and and ALSO remove it
  2267.    from the setup.lst file.
  2268.    [George Tatge (gat@csn.org)]
  2269.  
  2270. 6. Why won't my setup program install commdlg.dll et. al.?
  2271.  
  2272.    There are a couple of DLLs that are almost always in use by
  2273.    windows.  Commdlg.dll is the most common example.  When faced with
  2274.    this problem, there is no easy way out.  The full explanation is
  2275.    several pages long and beyond the scope of this FAQ.  The general
  2276.    idea is as follows:
  2277.  
  2278.    Your setup program will need to create a .BAT file to expand and
  2279.    then copy these files.  Then, it will need to shutdown Windows
  2280.    (see ExitWindowsExec API call) and run the .BAT file.  Then it will
  2281.    need to restart windows and continue your setup program.  Your
  2282.    setup program should delete the temporary .BAT file that is no
  2283.    longer needed.
  2284.    [George Tatge (gat@csn.org)]
  2285.  
  2286. 7. Where do I install VBXs and DLLs?
  2287.  
  2288.    PLEASE- this is one place where everybody's life is much easier if
  2289.    you will follow Microsoft's recommendations.  All PUBLIC VBXs and
  2290.    DLLs should be installed in the windows/system directory!  A
  2291.    "PUBLIC" DLL or VBX is any which can be purchased on the open
  2292.    market.  In other words, if another VB programmer might possibly
  2293.    use the same VBX or DLL, install it in the
  2294.    system directory.
  2295.  
  2296.  
  2297.    If you have written private VBXs or DLLs that will never be used by
  2298.    any program but yours, you can install them in the same directory
  2299.    where you install your application files.
  2300.  
  2301.    There are lots of good reasons for doing this, but it makes a short
  2302.    novel to rehearse them all.
  2303.    [George Tatge (gat@csn.org)]
  2304.  
  2305.  
  2306. H. MISCELLANEOUS TIPS AND INFORMATION
  2307.  
  2308.  
  2309. 1. Multiple identifiers after the DIM statement can be confusing
  2310.  
  2311.    Some programmers with background from Pascal can try the following
  2312.  
  2313.      Dim iA, iB, iC as Integer
  2314.  
  2315.    and think that all these 3 variables end up as Integer. In fact,
  2316.    the first two end up as default data type, normally Variant.
  2317.  
  2318.    Instead you should do
  2319.  
  2320.      Dim iA as Integer
  2321.      Dim iB as Integer
  2322.      Dim iC as Integer
  2323.  
  2324.    which takes up more space, but gives you room to comment your
  2325.    variables (hint, hint); *or*
  2326.  
  2327.      Dim iA%, iB%, iC%
  2328.  
  2329.    which does the whole job.
  2330.  
  2331. 2. "Clean up" your project before final EXE compilation.
  2332.  
  2333.    When you are ready to compile your VB project into your 'finished'
  2334.    EXE, be sure to save the project files, exit VB, restart Windows,
  2335.    run VB, load your project and go straight to compiling. Otherwise,
  2336.    your EXE may be larger in file size than necessary due to 'garbage'
  2337.    getting included in the EXE. For some reason, VB does not fully
  2338.    clean up all of the previously used variables or objects that you
  2339.    may have been playing with while developing your program so these
  2340.    get included in your EXE even though they aren't used. Other VB
  2341.    users have even advocated saving all the project files as ASCII,
  2342.    then loading the ASCII files before compiling to further "clean up"
  2343.    the resulting EXE file.
  2344.  
  2345. 3. Multiple END statements can be dangerous; or, The program that
  2346.    refused to terminate.
  2347.  
  2348.    Suggestion: put the END statement used to exit your program *only*
  2349.    in the Form_Unload event of the main form. Whenever you want to end
  2350.    the program, just tell the main form to unload.
  2351.  
  2352.    Some have reported that after their program have (supposedly)
  2353.    terminated, it still appears in the task list. This can happen if
  2354.    you only hide secondary forms and forget to unload them when you
  2355.    end/unload the main form.
  2356.  
  2357.    Also note that the Stop-button on the button-bar of the integrated
  2358.    development environment doesn't really unload anything. It *nukes*
  2359.    the program, which generally is a good idea since it could be a bug
  2360.    in it that caused it to be stuck in an eternal loop or something.
  2361.  
  2362. 4. What are the latest versions of the various files used by VB?
  2363.  
  2364.  
  2365.    Date       File to download  Updates files    Description
  2366.  
  2367.    3/7/94     BTR110.EXE        BTRV110.DLL      Btrieve IISAM Driver
  2368.  
  2369.    3/7/94     DATAINDX.EXE      DATAINDX.DOC     "Data Access Guide"
  2370.                                                  Index
  2371.  
  2372.    3/7/94     GENERIC.EXE       \VB\CDK\GENERIC  Sample custom control
  2373.                                                  source
  2374.  
  2375.    3/7/94     VBGRID.EXE        GRID.VBX         Grid control
  2376.  
  2377.    3/7/94     VBHC505.EXE       HC.EXE, HCP.EXE  WinHelp compiler
  2378.  
  2379.    3/7/94     MSAJT.EXE         MSAJT110.DLL     Access Database Engine
  2380.  
  2381.    3/8/94     MSCOMM.EXE        MSCOMM.VBX       Serial
  2382.                                                  Communications\control
  2383.  
  2384.    3/7/94     ORA110.EXE        ORACLE.TXT       Updated ORACLE.TXT file
  2385.  
  2386.    6/27/94    SETUPK.EXE        SETUP.EXE        Setup Toolkit
  2387.  
  2388.    3/7/94     VBRUN300.EXE      VBRUN300.DLL     Visual Basic Runtime
  2389.                                                  Library
  2390.  
  2391.    3/7/94     XBS110.EXE        XBS110.DLL       XBase IISAM Driver
  2392.  
  2393.  
  2394.    There is an article in the Microsoft Knowledge Base that points to
  2395.    each of these files and provides more detailed information about
  2396.    the update. To find these articles, query the Microsoft Knowledge
  2397.    Base using the file name and the word "update3.00".
  2398.  
  2399.    Note the NEW SETUPKIT update!
  2400.    [Thanks to Marks Harrop <harrop@werple.apana.org.au>]
  2401.  
  2402.    Please inform the FAQ maintainer about newer versions.
  2403.  
  2404.  
  2405. I. VISUAL BASIC FOR APPLICATIONS (VBA)
  2406.  
  2407.  
  2408. 1. Any tips for VB/Win 3 programmers moving to VBA?
  2409.  
  2410.    You are in for some surprises. VBA is more unlike VB 3 than most
  2411.    people thought. Especially the development environment is very
  2412.    different, and the language puts more emphasis on objects. The
  2413.    latter is a trend you can get used to for VB also.
  2414.  
  2415.    For Excel 5 VBA, be aware that the environment is based on the
  2416.    "workbook" idea Microsoft stole from Borland. Your controls will be
  2417.    placed in one sheet, and the code will be in another.
  2418.    Doubleclicking on the control to open the code window doesn't help.
  2419.    You have to use the "Tools|Assign Macro" menu option.
  2420.  
  2421.    Also, be aware that the list of events is nowhere close to what VB3
  2422.    supports! No GotFocus, no MouseMove, no nothing. You'll be very
  2423.    confused if you try to look for "events" in the VBA docs!
  2424.  
  2425. 2. Does VBA support VBXs?
  2426.  
  2427.    No. If Microsoft have its way, VBX is a dead end. There will never
  2428.    be 32-bit VBXs, but OCXs using OLE 2. VBA is more a subset of VB 4
  2429.    than VB 3, but it does not fully support OCX yet. It will, though.
  2430.  
  2431. 3. How do I access properties on my dialog boxes in VBA?
  2432.  
  2433.    As noted above, VBA is a cultural chock for VB programmers. If you
  2434.    create a textbox in VBA, call it txName and try to
  2435.  
  2436.      cMyVar=txName.Text
  2437.  
  2438.    the impolite interpreter will give you a "variable not defined"
  2439.    error.
  2440.  
  2441.    The magic is objects. You have to
  2442.  
  2443.      Dim txName as Object
  2444.      Set txName = DialogSheets("NameDialog".EditBoxes("txName"))
  2445.  
  2446.    And then you can access your properties like you used to in good
  2447.    ol' VB 3. (Anyone volunteer to beat senseless the guy who thought
  2448.    out this?)
  2449.  
  2450. 4. How do I use database routines from Excel VBA?
  2451.  
  2452.    The documentation is somewhere between sparse and inexistant on
  2453.    this topic. Any info on VBA and SQL would be much appreciated.
  2454.  
  2455.    Here Microsoft breaks the tradition and you *can't* use database
  2456.    objects, at least not the way you do in VB. Also, forget dynasets.
  2457.  
  2458.    I know nothing about databases in VBA. I just bring on the
  2459.    following tips from various magazines:
  2460.  
  2461.    Both SQLOpen and QueryGetData require a 'connection string'. That's
  2462.    about what the doc's say about the parameter. What is it? The doc
  2463.    is also tragically void of useful examples. Someone dug up the
  2464.    following example:
  2465.  
  2466.      "DSN=My data file;DBQ=c:\access\data.mdb;FIL=RedISAM;"
  2467.  
  2468.    which is about as understandable as it looks. If you use an empty
  2469.    string, you get a dialog which also can give you the string into a
  2470.    spreadsheet cell.
  2471.  
  2472.    Also, search for SQLREQUEST in the *main* help file for Excel 5
  2473.    (not the VBA help!) for these examples of connection_string's:
  2474.  
  2475.    dBASE             DSN=NWind;PWD=test
  2476.    SQL Server        DSN=MyServer;UID=dbayer;PWE=123;Database=Pubs
  2477.    ORACLE            DNS=My Oracle Data Source;DBQ=MYSER VER;
  2478.                      |UID=JohnS;PWD=Sesame
  2479.  
  2480.    There's a KnowledgeBase on Excel 5 on ftp.microsoft.com. Last time
  2481.    I looked, it was void of database stuff. Still, it may be a good
  2482.    idea to download it as the situation may have changed now.
  2483.  
  2484.  
  2485.    *** END OF VB/WIN FAQ DOCUMENT ***
  2486.  
  2487.  
  2488.  
  2489. -- 
  2490.  
  2491. Kris Nosack      knosack@park.uvsc.edu
  2492.  
  2493. >>>--->  Be strange, but not a stranger!  <---<<<
  2494.