Professional Documents
Culture Documents
The following table shows the supported data types, including storage sizes and ranges.
Data type Byte Boolean Integer Long Declaration de variables type tableau (long integer) LongLong (LongLong integer) LongPtr (Long integer on 32-bit systems, LongLong integer on 64-bit systems) Single (single-precision floating-point) Double (double-precision floatingpoint) Currency (scaled integer) 8 bytes 8 bytes Storage size 1 byte 2 bytes 2 bytes 4 bytes Range 0 to 255 True or False -32,768 to 32,767 -2,147,483,648 to 2,147,483,647 -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (Valid on 64-bit platforms only.) -2,147,483,648 to 2,147,483,647 on 32-bit systems, 9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 on 64-bit systems -3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values -1.79769313486231E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E324 to 1.79769313486232E308 for positive values -922,337,203,685,477.5808 to 922,337,203,685,477.5807 +/-79,228,162,514,264,337,593,543,950,335 with no decimal point; Decimal 14 bytes +/-7.9228162514264337593543950335 with 28 places to the right of the decimal; smallest non-zero number is +/-0.0000000000000000000000000001 Date Object String (variable-length) String (fixed-length) Variant (with numbers) Variant (with characters) User-defined (using Type) 8 bytes 4 bytes 10 bytes + string length January 1, 100 to December 31, 9999 Any Object reference 0 to approximately 2 billion
8 bytes
4 bytes
Length of string
1 to approximately 65,400
16 bytes 22 bytes + string length (24 bytes on 64-bit systems) Number required by elements
The range of each element is the same as the range of its data type.
ColorIndex Property
Returns or sets the color of the border, font or interior, as shown in the following table. The color is specified as an index value into the current color palette, or as one of the following XlColorIndex constants: xlColorIndexAutomatic or xlColorIndexNone. Read/write Variant.
Object Border Font Interior Description The color of the border. The color of the font. The color of the interior fill. Set ColorIndex to xlColorIndexNone to specify that you don't want an interior fill. Set ColorIndex to xlColorIndexAutomatic to specify the automatic fill (for drawing objects).
expression.ColorIndex expression Required. An expression that returns one of the objects in the Applies To list.
Remarks
This property specifies a color as an index into the color palette. The following illustration shows the color-index values in the default color palette.
Example
This example sets the color of the chart area interior to red and sets the border color to blue.
With Statement
Executes a series of statements on a single object or a user-defined type. SyntaxWith object [statements] End With
This example uses the With statement to execute a series of statements on a single object. The object
MyObject
and its properties are generic names used for illustration purposes only.
With MyObject .Height = 100 ' Same as MyObject.Height = 100. .Caption = "Hello World" ' Same as MyObject.Caption = "Hello World". With .Font .Color = Red ' Same as MyObject.Font.Color = Red. .Bold = True ' Same as MyObject.Font.Bold = True. End With End With
Set Statement
Found = True ' Set Found to True. Exit For ' Exit loop. End If Next
DateDiff Function
Returns a Variant (Long) specifying the number of time intervals between two specified dates. Syntax DateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]]) The DateDiff function syntax has these named arguments:
Part interval date1, date2 firstdayofweek firstweekofyear Description Required. String expression that is the interval of time you use to calculate the difference between date1 and date2. Required; Variant (Date). Two dates you want to use in the calculation. Optional. A constant that specifies the first day of the week. If not specified, Sunday is assumed. Optional. A constant that specifies the first week of the year. If not specified, the first week is assumed to be the week in which January 1 occurs.
CStr CVar
String Variant
MsgBox Function
Displays a message in a dialog box, waits for the user to click a button, and returns an Integer indicating which button the user clicked. Syntax MsgBox(prompt[, buttons] [, title] [, helpfile, context]) The MsgBox function syntax has these named arguments:
Part Description Required. String expression displayed as the message in the dialog box. The maximum length of prompt is prompt approximately 1024 characters, depending on the width of the characters used. If prompt consists of more than one line, you can separate the lines using a carriage return character (Chr(13)), a linefeed character (Chr(10)), or carriage return linefeed character combination (Chr(13) & Chr(10)) between each line. Optional. Numeric expression that is the sum of values specifying the number and type of buttons to display, the icon buttons style to use, the identity of the default button, and the modality of the message box. If omitted, the default value for buttons is 0. title Optional. String expression displayed in the title bar of the dialog box. If you omit title, the application name is placed in the title bar. Optional. String expression that identifies the Help file to use to provide context-sensitive Help for the dialog box. If helpfile is provided, context must also be provided. Optional. Numeric expression that is the Help context number assigned to the appropriate Help topic by the Help author. If context is provided, helpfile must also be provided.
helpfile
context
Second button is default. Third button is default. Fourth button is default. Application modal; the user must respond to the message box before continuing work in the current application. System modal; all applications are suspended until the user responds to the message box. Adds Help button to the message box. Specifies the message box window as the foreground window. Text is right aligned. Specifies text should appear as right-to-left reading on Hebrew and Arabic systems.
The first group of values (0 5) describes the number and type of buttons displayed in the dialog box; the second group (16, 32, 48, 64) describes the icon style; the third group (0, 256, 512) determines which button is the default; and the fourth group (0, 4096) determines the modality of the message box. When adding numbers to create a final value for the buttons argument, use only one number from each group.
Note These constants are specified by Visual Basic for Applications. As a result, the names can be used anywhere in your code in place of the actual values.
Return Values
Constant vbOK vbCancel vbAbort vbRetry vbIgnore vbYes vbNo Value 1 2 3 4 5 6 7 Description OK Cancel Abort Retry Ignore Yes No
Remarks When both helpfile and context are provided, the user can press F1 (Windows) or HELP (Macintosh) to view the Help topic corresponding to the context. Some host applications, for example, Microsoft Excel, also automatically add a Help button to the dialog box. If the dialog box displays a Cancel button, pressing the ESC key has the same effect as clicking Cancel. If the dialog box contains a Help button, context-sensitive Help is provided for the dialog box. However, no value is returned until one of the other buttons is clicked.
Note To specify more than the first named argument, you must use MsgBox in an expression. To omit some positional arguments, you must include the corresponding comma delimiter.
Example
This example uses the MsgBox function to display a critical-error message in a dialog box with Yes and No buttons. The No button is specified as the default response. The value returned by the MsgBox function depends on the button chosen by the user. This example assumes that
DEMO.HLP
is a Help file that contains a topic with a Help context number equal to
1000
.
Dim Msg, Style, Title, Help, Ctxt, Response, MyString Msg = "Do you want to continue ?" ' Define message. Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons. Title = "MsgBox Demonstration" ' Define title. Help = "DEMO.HLP" ' Define Help file. Ctxt = 1000 ' Define topic ' context. ' Display message. Response = MsgBox(Msg, Style, Title, Help, Ctxt) If Response = vbYes Then ' User chose Yes. MyString = "Yes" ' Perform some action. Else ' User chose No. MyString = "No" ' Perform some action. End If