

                         VBForums -    ̳ 


                         .       
               


         VBForums-̳: HTTP://hzsoft.yeah.net
            
                  ύʼ: VBForums@usa.net?Subject=VBForums

            нϵ: ympang@bigfoot.com




:
    richtextboxؼУùһƪֺ󣬳к
    һֲֵɼVB֣ʱʹÿؼıı
    ԶУлл

                                - !!!!

:
    ʣActiveBarؼ(OFFICE97ĹͰť) 
    Ҳ̫λѻҽǳл
                                - Aim

 VB  FAQ

How can I display an ampersand (&) in a menu item or in a label?

The ampersand is a special symbol to windows denoting a keyboard accelerator
key (underscoring the ALT<key> used to access the command from the keyboard).
To display an actual ampersand in a label or menu, use two ampersands together,
i.e. 'Save && Exit' displays as 'Save & Exit'


How can I use an accelerator in a label but have the focus move to the textbox
or control associated with that label?

Label controls, although they support the ampersand accelerator and tabstop,
can never actually receive focus. By setting the tabstop of the textbox or
control to one more than the label tabstop, pressing the label accelerator key
will move the focus to the next control in the tabstop array.


I've finished designing, but is there an easy way to reorder my Tabstops at
design time?

The easiest and most sure-fire way of keeping your tabstops in numerical order
is to begin with the LAST control you want in the tabstop order, and set it's
tab index to 0. Then move to the next-to-last control, and set IT'S tab index
to 0. Continue backwards through the controls setting each to 0 until the first
control's tabstop has been reset; the rest of the controls will then be ordered
correctly.


Could someone please tell me why this code returns an overflow? I've correctly
declared the result variable as Long:
   Dim x as Long
   x = 33 * 1000   'generates overflow error
   ...yet when I set the value x = 33000 directly, it works with no error.

VB, in calculating the results to assign to x, uses a temporary variable. In
doing so, it uses a temp of the same data type as the data types in the
expression to compute. In the case above, because the two data types being
multiplied are integers, VB uses an integer as the temp. When the
multiplication exceeds 32k (the limit for an integer), the overflow error is
generated. The 'fix' is to assign a type declaration character to one of the
values in the expression forcing VB to use a temp variable of sufficient
capability to hold the result, i.e...
   x = 33 * 1000&
Even though 1000 isn't a 'long', VB will use a long to create the temp variable
for the result. However, be aware that the code:
   x = 33 * 1000 * 100&
will still generate the error as VB attempts to compute the first part of the
multiplication into an integer, despite the declaration of a long in the
equation. The fix here is to assign the long to the largest value, or to
bracket the equation to have VB perform the long computation first:
   x = 33 * 1000& * 100
   x = 33 * (1000 * 100&)

How can I show the Windows95 'Open With' dialog in response to a command button
click?
The Open With dialog can be invoked with the following code:

Private Sub Command1_Click()

   Dim x As Long
   x = Shell("rundll32.exe shell32.dll,OpenAs_RunDLL [path]filename.ext")

End Sub

How can I activate a running app, or launch it if it's not running?
Declare the FindWindow and BringWindowToTop APIs in a form or module, then use:

Private Sub Command1_Click()

   Dim hCalcWnd As Long
   Dim x As Long

   hCalcWnd = FindWindow("SciCalc", "Calculator")

   If hCalcWnd = 0 Then
           x = Shell("CALC.EXE", vbNormalFocus)
   Else: BringWindowToTop (hCalcWnd)
  End If

End Sub

I have a simple project. Can I declare an API or user-defined type (UDT) just
in a form?
Yes, however the declare or Type must be prefaced with the Private keyword.
This restricts the scope of the variable or API to the form declared in.

Can I add my own variables to a form or control sub to passing additional data?
No. Form and control routines that are listed in the Object combo box in the
code window can only use the fixed variables assigned that make up the
routine's declaration. 

How do I call a procedure in one form from a routine in another form in VB4?
In VB4, any new sub or function that you create in the form will be exposed to
all other forms and bas modules if you declare the routine as Public. Note
though that you can not invoke a control's subs this way, that is, you can not
use Form2!Command1_Click. The routines that are listed in the code window
Object combo box are always private to that form unless you change them to
Public. However, this practice is unnecessary as the control and it's
properties are available to other forms and modules, and can be fired by using
the <formname>!<controlname>.<property> syntax, as in Form2!Command1.Value =
True.

How do I call a procedure in one form from a routine in another form in VB3?
VB3 does not support Public routines in a form, so form-level routines are not
directly callable from outside that form.

How do I declare a variable to make it available to all procedures in all
forms?
In a BAS module, place the word Public (VB4) or Global (VB2,3) before the
variable.

How do I declare a constant to make it available to all procedures in all
forms?
In a BAS module, place the words Public Const (VB4) or Global Const (VB2,3)
before the variable assignment.

What is the scope of a variable declared in different parts of a project?
A variable DIM'med in any sub or function is local to that routine only, and is
destroyed upon exiting that routine.

A variable DIM'med in the general declarations section of a Form, regardless of
whether you use Public or Private, is available only to routines in that form.
The variable remains valid as long as the form is loaded.

A variable DIM'med Private in the general declarations section of a BAS module
is available routines only in that bas module. The Private keyword is not
available in VB2 or 3; use a standard DIM statement.

A variable DIM'med Public (or Global - VB2,3) in the general declarations
section of a BAS module is available to all routines in all forms and bas
modules.

A variable DIM'med in any sub or function that has the same name as a Public or
Global variable takes precedence over the Public one in the routine where it is
DIM'med. It's initial value is 0 or empty. The Public variable is not affected
by use of the local variable of the same name. The local variable is destroyed
upon exiting that routine; the global variable remains valid. Download a VB4
demo and view the code. Generally, using the same name for a Public and Local
variable is considered poor programming practice. 

How can I find out how many MDI child forms are open in a MDI project?
The Count property of the Forms collection returns the number of forms
currently loaded in the project. However, this number also includes the MDI
parent form itself, as well as any other non-MDI child forms and hidden forms
open in the project. To determine which open forms are actual MDI child
windows, you can use use:

Public Function GetMDIChildCount() As Integer

  Dim frm As Form
  Dim cnt As Integer

  For Each frm In Forms
      If (frm.MDIChild And frm.Visible) Then cnt = cnt + 1
  Next frm

  GetMDIChildCount = cnt

End Function

Call the routine as:
  NumberOfOpenForms = GetMDIChildCount()


˶ http://server.com/WebApps/mail-list-unsubscribe.cgi?id=4093


