You are on page 1of 7

Data Type Summary

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 on 32-bit systems, 8 bytes on 64bit systems

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

Any numeric value up to the range of a Double

Same range as for variable-length String

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 myChart.ChartArea .Interior.ColorIndex = 3 .Border.ColorIndex = 5 End With

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

Assigns an object reference to a variable or property.

Example: Set maplage=Selection ie qu on dsigne que la plage slectionne est maplage


If...Then...Else Statement
Conditionally executes a group of statements, depending on the value of an expression. Syntax If condition Then [statements] [Else elsestatements] End If -----Or, you can use the block form syntax: If condition Then [statements] [ElseIf condition-n Then [elseifstatements] [Else [elsestatements]] End If

For Each...Next Statement


Repeats a group of statements for each element in an array or collection. Syntax: For Each element In group [statements] [Exit For] [statements] Next [element]

For Each MyObject In MyCollection If MyObject.Text = "Hello" Then

' Iterate through each element. ' If Text equals "Hello".

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.

Settings The interval argument has these settings:


Setting yyyy q m y d w ww h n s Description Year Quarter Month Day of year Day Weekday Week Hour Minute Second

Conversion Functions: Each function coerces an expression to a specific data type


Return Types
Return Type CBool CByte CCur CDate Boolean Byte Currency Date CLng CLngLng CLngPtr CSng Long LongLong LongPtr Single

CDbl CDec CInt

Double Decimal Integer

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

Settings The buttons argument settings are:


Constant vbOKOnly vbOKCancel vbAbortRetryIgnore vbYesNoCancel vbYesNo vbRetryCancel vbCritical vbQuestion vbExclamation vbInformation vbDefaultButton1 Value 0 1 2 3 4 5 16 32 48 64 0 Description Display OK button only. Display OK and Cancel buttons. Display Abort, Retry, and Ignore buttons. Display Yes, No, and Cancel buttons. Display Yes and No buttons. Display Retry and Cancel buttons. Display Critical Message icon. Display Warning Query icon. Display Warning Message icon. Display Information Message icon. First button is default.

vbDefaultButton2 vbDefaultButton3 vbDefaultButton4 vbApplicationModal vbSystemModal vbMsgBoxHelpButton VbMsgBoxSetForeground vbMsgBoxRight vbMsgBoxRtlReading

256 512 768 0 4096 16384 65536 524288 1048576

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

You might also like