[Translation] Visual Basic 2005 Enhancements in Language (Eleven) No Symbol Type

xiaoxiao2021-03-06  37

Visual Basic 2005 fully supports unsigned types. These unsigned type names include: • Sbyte • Ushort • UINTEGER • ULONG is the same in addition to only storage of non-negative integers, unsigned types and general types of work. When Visual Basic calls Win32 API, the unsigned type is extremely useful when the parameters of the non-symbol type are needed. The following code demonstrates how to call Windows MessageBox API: Public Enum WindowsMessageResult As Uinteger OK = 1 Cancel = 8END ENUM

Private const mb_ok as uinteger = 0Private const MB_ICONEXCLAMATION AS uinteger = & h30private const mb_options as uinteger = MB_OK or MB_ICONEXCLAMATION

Private Declare Auto Function Win_MB LIB _ "User32.dll" Alias ​​"MessageBox" _ (Byval HWnd As Integer, Byval LPText As String, _ Byval LPCAPTION As String, BYVAL UTYPE AS UINTEGER _ AS UINTEGER

Public Function MessageThroughWindows (ByVal message As String, _ ByVal caption As String) As WindowsMessageResult Dim r As UInteger = Win_MB (0, message, caption, MB_OPTIONS) Return CType (r, WindowsMessageResult) End Function You see, Win_MB function declaration The last parameter and the return value are UINTEGER types. If you want to store values ​​that exceed the Integer range, no symbol type can save space for you. The Integer type takes up four bytes of memory and can only store positive or negative numbers from 2, 147, 483, 648. The UINTEGER type also occupies only four-byte memory, but it can store the value from zero to 4, 294, 967, 295. If there is no symbol type, you have to use long-in-eight-byte memory to store such a big value. @ Original here for netizens reference @Unsigned TypesVisual Basic 2005 has full support for unsigned types The unsigned type names are:. • SByte • UShort • UInteger • ULong The unsigned types work as regular types except the unsigned type can store only positive integers . unsigned types are most useful in Visual Basic for making Win32 API calls that take unsigned types as parameters The following code illustrates a Windows MessageBox API call:. Public Enum WindowsMessageResult As UInteger OK = 1 Cancel = 8End Enum

Private Const MB_OK As UInteger = 0Private Const MB_ICONEXCLAMATION As UInteger = & H30Private Const MB_OPTIONS As UInteger = MB_OK Or MB_ICONEXCLAMATIONPrivate Declare Auto Function Win_MB Lib _ "user32.dll" Alias ​​"MessageBox" _ (ByVal hWnd As Integer, ByVal lpText As String, _ ByVal LPCAPTION As String, Byval utype as uinteger _ as uinteger

Public Function MessageThroughWindows (ByVal message As String, _ ByVal caption As String) As WindowsMessageResult Dim r As UInteger = Win_MB (0, message, caption, MB_OPTIONS) Return CType (r, WindowsMessageResult) End FunctionNotice the last parameter and return type on the Win_MB declaration are both UInteger types.Unsigned types can also help you conserve memory if you need to store values ​​larger than an Integer. The Integer type uses four bytes of memory and can store positive and negative values ​​up to 2,147,483,648. The UInteger type also uses four .

转载请注明原文地址:https://www.9cbs.com/read-69609.html

New Post(0)