home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 038 / vbfq1194.zip / VBWINFAQ.TXT
Internet Message Format  |  1994-12-11  |  102KB

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