|
||||||||||
|
| ||||||||||
|
||||||||||
|
Visual Basic | Delphi | C++ | Java Data Types
Variants can contain almost any data type. Conversion between different variant types is noramally automatic. However, this usage leads to poorly designed applications. Using variants in loops is about 6 times slower than integers. Basically, Variants should never be used. Unfortunately, many functions require variants :( Always use Option Explicit to require that all variables are defined. There is no way to initialize variables when they are declared. Dim flag As Boolean flag = false Const EM_LINESCROLL = &HB6 [Public | Private] Const constname [As type] = expression Important Constants
VisualBasic 3.0 VisualBasic 6.0
RED vbRed
KEY_RIGHT vbKeyRight
ESC$ = Chr$(KEY_ESCAPE) ESC$ = Chr$(vbKeyEscape)
cr$ = Chr$(KEY_RETURN) cr$ = Chr$(vbKeyReturn)
As you can see the constant names are now different in VB 6.0 (big supprise)
Be careful working with constants. Short integers must be less than 32K.
l& = 30000 + 30000 'fails because it tries to compute a short int
' and then converts that to a long int
i& = 30000& + 30000& 'works because the constants are long ints
This would also fail if 2 integer variables were being added.
The following Dim iA, iB, iC as Integerdeclares 2 Variants and 1 Integer. In Pascal, it would be 3 Integers. If you want 3 integers, use Dim iA as Integer, iB as Integer, iC as Integer Hex Constants - &HA5A5 'Short --- &H0B00C004& 'Long The AddressOf operator is not available in most versions of VBA (VisualBasic for Applications). Specifically, it is not available in MS Access 97. Without this operator, there is no way to call windows API functions which require a pointer to a function. Delphi is not case-sensitive.
var
X, Y, Z: real;
I, J, K: Integer;
I : Integer = 7; // Initialization only works with global variables
const
fileName = 'test.ini';
Hex Constants - $a000 To place a single quote in a string, use 2 consecutive single quotes. 'You can''t stop'String names can not contain a dollar sign. The variable types Integer (signed) and Cardinal (unsigned) can be either 16 or 32 bits, depending on the compiler. In Delphi, the string variable type can declare either a long (AnsiString) or short (ShortString) string depending on a compiler flag. Real valued constants are always of type extended Hex Constants - \x008 Most variables are allocated on the stack. To allocate variables on the heap, use new. Any time new is used to allocate memory, delete must be called before the program exits. Otherwise, the program will leak memory (make it unavailable for other programs). Arrays must be deallocated using delete[]. When declaring a variable,
To cause the compiler to treat a variable as another type, or to convert from one type to another, use the cast operator. a = (float)i;
Escape Sequences \a Bell (alert) \b Backspace \f Formfeed \n New line \r Carriage return \t Horizontal tab \v Vertical tab \' Single quotation mark \" Double quotation mark \\ Backslash (Warning: Required in DOS file paths) \? Question mark \ooo Octal constant \xhhh Hexadecimal constant #define EM_LINESCROLL 0x00B6 long i = 0; Java is similar to C++ but without pointers. Variables can be initialized when they are defined. int n=0; int j=n; // Can initialize to the value of a variable String FileName="autoexec.bat"; // Note that String must be capitalized char SingleCharacter = 'a' ; // In Java, 'a' is 16 bits, in C it is 8 bits \n = New line works in some Java programs but is a problem using awt(Abstract Windowing Toolkit). |
| Copyright © Netcore2K.net. All rights reserved. |
Contact Us |