Get Statement VB.NET

Syntax

Program code to be executed when the Property Get procedure is called

Description
Defines a Property Get procedure that returns a property value to the caller

Rules at a Glance

  • The Get statement can only be used within a Property...End Property construct.
  • The property value can be returned either by using the Return statement or by assigning the value to a variable whose name is the same as the property. For example:
  • The value returned by a property is usually the value of a variable that's Private to the class. This protects the property value from accidental modification.

VB .NET/VB 6 Differences
The Property Get statement in VB 6 corresponds to the Get statement in VB .NET. Though the purpose and basic operation of the two constructs is identical, the syntax of the VB .NET construct is vastly simplified and more intuitive

GetAllSettings Function

Class
Microsoft.VisualBasic.Interaction

Syntax
GetAllSettings(appname, section)

appname Use: Required Data Type: String

Name of the application

section Use: Required Data Type: String

Relative path from appname to the key containing the settings to retrieve

Return Value
An object containing a two-dimensional array of strings

Description
Returns the registry value entries and their corresponding values for the application

Rules at a Glance

  • GetAllSettings works exclusively with the subkeys of HKEY_CURRENT_USERSoftware VB and VBA Program Settings.
  • The elements in the first dimension of the array returned by GetAllSettings contain the value entry names.
  • The elements in the second dimension of the array returned by GetAllSettings contain the values for the respective value entries.
  • The two-dimensional array returned by GetAllSettings is based at 0 (as are all arrays) so the first value entry name is referenced using (0,0).
  • A call to GetAllSettings will return only the value entry names and data belonging to the final registry key specified by the section argument. If that key itself has one or more subkeys, their data will not be retrieved by the function.
  • If either appname or section do not exist, GetAllSettings will return an uninitialized Object.

Programming Tips and Gotchas

  • GetAllSettings is a function that was developed to retrieve data from initialization files in 16-bit environments and to retrieve data from the registry under Windows 9x and Windows NT. The language of the documentation, however, reflects the language of initialization files. The arguments labeled appname and section are in fact registry keys; the argument labeled key is in fact a registry value entry.
  • The built-in registry-manipulation functions allow you to create professional 32-bit applications that use the registry for holding application-specific data, in the same way that .INI files were used in the 16-bit environment. You can, for example, store information about the user's desktop settings (i.e., the size and position for forms) the last time the program was run.
  • Because the built-in registry functions in VB only create string-type registry keys, GetSetting and GetAllSettings return string values. Therefore, before you use numeric values returned from the registry, you should explicitly convert the value to a numeric data type.
  • GetAllSettings, SaveSettings, and GetSetting allow you direct access to only a limited section of the windows registry, that being a special branch created for your application (HKEY_CURRENT_USERSoftware VB and VBA Program Settings). You cannot access or change other registry settings without using the Win32 API.
  • Use the code Application.ExecutablePath to pass your application's name to the GetAllSetting function.
  • Only those settings that were created using either the Win32 API or the SaveSetting function will be returned. In other words, a VB application does not have a registry entry unless you have created one explicitly.
  • If the key read by GetAllSettings has a default value, that value will not be retrieved by the function. If you want to store and retrieve default values, you must call the Win32 API directly.
  • Because GetAllSettings returns an uninitialized Object when either appname or section do not exist, if you subsequently try to perform a UBound or LBound function on the object, a "Type Mismatch" error will be generated. You can test the validity of the returned value, as follows:
  • Because GetAllSetting retrieves data from the user branch of the registry, and the physical file that forms the user branch of the registry may change (depending, of course, on who the user is and, in the case of Windows 9x systems, whether the system is configured to support multiple users), never assume that an application has already written data to the registry. In other words, even if you're sure that your application's installation routine or the application itself has successfully stored values in the registry, never assume that a particular value entry exists, and always be prepared to substitute a default value if it does not.
  • Rather than rely on the relatively underpowered registry-access functionality available in Visual Basic, we highly recommend that you instead use the Registry and RegistryKey classes available in the BCL's Microsoft.Win32 namespace.

GetAllSettings Function

Class
Microsoft.VisualBasic.Interaction

Syntax
GetAllSettings(appname, section)

appname Use: Required Data Type: String

Name of the application

section Use: Required Data Type: String

Relative path from appname to the key containing the settings to retrieve

Return Value
An object containing a two-dimensional array of strings

Description
Returns the registry value entries and their corresponding values for the application

Rules at a Glance

  • GetAllSettings works exclusively with the subkeys of HKEY_CURRENT_USERSoftware VBand VBA Program Settings.
  • The elements in the first dimension of the array returned by GetAllSettings contain the value entry names.
  • The elements in the second dimension of the array returned by GetAllSettings contain the values for the respective value entries.
  • The two-dimensional array returned by GetAllSettings is based at 0 (as are all arrays) so the first value entry name is referenced using (0,0).
  • A call to GetAllSettings will return only the value entry names and data belonging to the final registry key specified by the section argument. If that key itself has one or more subkeys, their data will not be retrieved by the function.
  • If either appname or section do not exist, GetAllSettings will return an uninitialized Object.

Programming Tips and Gotchas

  • GetAllSettings is a function that was developed to retrieve data from initialization files in 16-bit environments and to retrieve data from the registry under Windows 9x and Windows NT. The language of the documentation, however, reflects the language of initialization files. The arguments labeled appname and section are in fact registry keys; the argument labeled key is in fact a registry value entry.
  • The built-in registry-manipulation functions allow you to create professional 32-bit applications that use the registry for holding application-specific data, in the same way that .INI files were used in the 16-bit environment. You can, for example, store information about the user's desktop settings (i.e., the size and position for forms) the last time the program was run.
  • Because the built-in registry functions in VB only create string-type registry keys, GetSetting and GetAllSettings return string values. Therefore, before you use numeric values returned from the registry, you should explicitly convert the value to a numeric data type.
  • GetAllSettings, SaveSettings, and GetSetting allow you direct access to only a limited section of the windows registry, that being a special branch created for your application (HKEY_CURRENT_USERSoftware VB and VBA Program Settings). You cannot access or change other registry settings without using the Win32 API.
  • Use the code Application.ExecutablePath to pass your application's name to the GetAllSetting function.
  • Only those settings that were created using either the Win32 API or the SaveSetting function will be returned. In other words, a VB application does not have a registry entry unless you have created one explicitly.
  • If the key read by GetAllSettings has a default value, that value will not be retrieved by the function. If you want to store and retrieve default values, you must call the Win32 API directly.
  • Because GetAllSettings returns an uninitialized Object when either appname or section do not exist, if you subsequently try to perform a UBound or LBound function on the object, a "Type Mismatch" error will be generated. You can test the validity of the returned value, as follows:
  • Because GetAllSetting retrieves data from the user branch of the registry, and the physical file that forms the user branch of the registry may change (depending, of course, on who the user is and, in the case of Windows 9x systems, whether the system is configured to support multiple users), never assume that an application has already written data to the registry. In other words, even if you're sure that your application's installation routine or the application itself has successfully stored values in the registry, never assume that a particular value entry exists, and always be prepared to substitute a default value if it does not.
  • Rather than rely on the relatively underpowered registry-access functionality available in Visual Basic, we highly recommend that you instead use the Registry and RegistryKey classes available in the BCL's Microsoft.Win32 namespace.

GetAttr Function

Class
Microsoft. VisualBasic.FileSystem
Yes

Syntax
GetAttr(pathname)

pathname Use: Required Data Type: String

Filename and an optional pathname

Return Value
An integer representing the sum of the following constants or members of the FileAttribute enumeration, which reflect the attributes set for the file:

TABLE

Return Value

Description
Determines which attributes have been set for a file or directory

Rules at a Glance

  • pathname may optionally include a directory name and a drive letter, including a network drive. pathname can also follow the UNC format of //machine_name/drive.
  • You can check if a particular attribute has been set by performing a bitwise comparison of the GetAttr return value and the value of the attribute constant using the And operator. A nonzero result means that the particular attribute has been set; conversely, a zero value indicates that the attribute has not been set. For example:

Programming Tips and Gotchas
If pathname is invalid, a FileNotFoundException exception is generated.

Class
Microsoft.VisualBasic.Strings

Syntax
GetChar(str, index)

str Use: Required Data Type: String

The string from which to extract a character

index Use: Required Data Type: Integer

Position of character (1-based)

Return Value
A Char containing the character at position index

Description
Returns the character that is at position index within a given string

Rules at a Glance

  • The first character in str is at index 1.
  • If index exceeds the number of character positions in str, an error is generated.

VB .NET/VB 6 Differences
The GetChar function is new to VB .NET.

GetObject Function

Class
Microsoft. VisualBasic.Interaction

Syntax
GetObject([pathname] [, class])

pathname Use: Optional Data Type: String

The full path and name of the file containing the COM (or ActiveX) object.

class Use: Optional Data Type: String

The class of the object. The class argument has these parts:

Appname Use: Required Data Type: String

The name of the application.

Objecttype Use: Required Data Type: String

The class of object to create, delimited from Appname by using a point (.). For example,

Appname.Objecttype

Return Value
Returns a reference to an ActiveX object

Description
Accesses an ActiveX server held within a specified file

Rules at a Glance

  • Although both pathname and class are optional, at least one parameter must be supplied.
  • In situations where you cannot create a project-level reference to an ActiveX object, you can use the GetObject function to assign an object reference from an external ActiveX object to an object variable.
  • GetObject is used when there is a current instance of the ActiveX object; to create the instance, use the CreateObject function.
  • If you specify pathname as a zero-length string, GetObject will return a new instance of the object—unless the object is registered as single instance, in which case the current instance will be returned.
  • If you omit the pathname, the current instance of the object will be returned.
  • An error is generated if pathname is not specified and no current instance of the object can be found.
  • The object variable you will use within your program to hold a reference to the ActiveX object is dimensioned as type Object. This causes the object to be late bound; that is, your program knows nothing of the type of object nor its interface until the object has been instantiated within your program:
  • Dim myObject As Object myObject = GetObject("C:OtherAppLibrary.lib")
  • The details of how you create different objects and classes are determined by how the server has been written, and you'll need to read the documentation available for the server to determine what you need to do to reference a particular part of the object. There are basically three ways in which you can access an ActiveX object:
  • The overall object library. This is the highest level and will give you access to all public sections of the library and all its public classes:
  • A section of the object library. To access a particular section of the library, use an exclamation mark (!) after the filename, followed by the name of the section:
A class within the object library. To access a class within the library, use the optional Class parameter: Programming Tips and Gotchas
  • Pay special attention to objects registered as single instance. As their type suggests, there can only ever be one instance of the object created at any one time. Calling CreateObject against a single-instance object more than once has no effect; you will still be returning a reference to the same object. The same is true of using GetObject with a pathname of ""; rather than returning a reference to a new instance, you will be obtaining a reference to the original instance of the object. In addition, you must use a pathname argument with singleinstance objects (even if this is ""); otherwise an error will be generated.
  • You can't use GetObject to obtain a reference to a class created with Visual Basic.
  • When possible, you should use early binding in your code. You can use GetObject in early binding with COM objects, as in:
  • Dim objExcel As Excel.Application
  • The following table shows when to use GetObject and when to use CreateObject:

TABLE

GetObject and when to use CreateObject

GetSetting Function

Class
Microsoft.VisualBasic.Interaction

Syntax
GetSetting(appname, section, key[, default])

appname Use: Required Data Type: String

The name of the application

section Use: Required Data Type: String

The path from the application key to the key containing the value entries

key Use: Required Data Type: String

The name of the value entry whose value is to be returned

default Use: Optional Data Type: String

The value to return if no value can be found

Return Value
A string containing the value of the specified key; default if key, section, or appname were not found.

Description
Returns a single value from a specified section of your application's entry in the
HKEY_CURRENT_USERSoftwareVB and VBA Program Settings branch of the registry.

Rules at a Glance

  • If at least one of appname, section, or key is not found in the registry, GetSetting returns default.
  • If default is omitted, it is assumed to be a zero-length string ("").
  • The function retrieves a value from a subkey of the KEY_CURRENT_USERSoftwareVB and VBA Program Settings key of the registry.
  • section need not be an immediate subkey of appname; instead, section can be a fully qualified path to a nested subkey, with each subkey separated from its parent by a backslash.

For example, a value of SettingsCoordinates for the section argument indicates that the value is to be retrieved from HKEY_CURRENT_USERSoftwareVB and VBA Program SettingsappnameSettingsCoordinates.

Programming Tips and Gotchas

  • GetSetting is a function that was developed to retrieve data from initialization files in 16-bit environments and to retrieve data from the registry under Windows 9x and Windows NT. The language of the official documentation, however, reflects the language of initialization files. The arguments labeled appname and section are in fact registry keys; the argument labeled key is in fact a registry value entry.
  • Because the built-in registry functions in VB create only string-type registry-value entries, GetSetting and GetAllSettings return string values. Therefore, before you use numeric values returned from the registry, you should explicitly convert the value to a numeric data type by using the appropriate conversion function.
  • Use the Application.ExecutablePath property to pass your application's name to the GetSetting function as the value of the appname parameter, both when reading and writing registry data.
  • The built-in registry-manipulation functions allow you to create professional 32-bit applications that use the registry for holding application-specific data, in the same way that .INI files were used in the 16-bit environment. You can, for example, store information about the user's desktop settings (i.e., the size and position of forms) the last time the program was run.
  • GetSetting, GetAllSettings, and SaveSettings allow you direct access to only a limited section of the windows registry, that being a special branch created for your application

(HKEY_CURRENT_USERSoftwareVB and VBA Program Settingsyourappname).
You cannot access or change other registry settings without resorting to the Windows API.

  • GetSetting does not allow you to retrieve the default value of a registry key. Attempting to do so produces runtime error 5, "Invalid procedure call or argument." This is not as great a limitation as it may appear, since SaveSetting also cannot write a default value to a registry key.
  • Because GetSetting retrieves data from the user branch of the registry, and the physical file that forms the user branch of the registry may change (depending, of course, on who the user is and, in the case of Windows 9x systems, whether the system is configured to support multiple users), never assume that an application has already written data to the registry. In other words, even if you're sure that your application's installation routine or the application itself has successfully stored values in the registry, always supply a meaningful value for the default argument.
  • Only those settings that were created using either the Windows API or the SaveSetting function will be returned. In other words, a VB application does not have a registry entry unless you have created one explicitly.
  • Although GetSetting writes only string data to the registry, you can use a variable of almost any data type to retrieve it. The GetSetting function automatically handles the conversion of string data to the data type of the variable to which the return value of GetSetting is assigned. The only exceptions are user-defined data types and arrays of byte data.
  • Rather than rely on the relatively underpowered registry-access functionality available in Visual Basic, we highly recommend that you instead use the Registry and RegistryKey classes available in the BCL's Microsoft.Win32 namespace.

GetTimer Function

Class
Microsoft.VisualBasic.VBMath

Syntax
GetTimer( )

Return Value
A Double indicating the number of seconds

Description
Returns the number of seconds since midnight

Programming Tips and Gotchas

  • You can use the GetTimer function as an easy method of passing a seed number to the Randomize procedure, as follows: Randomize GetTimer( )
  • The GetTimer function is ideal for measuring the time taken to execute a procedure or block of code, as the following snippet shows:

VB .NET/VB 6 Differences

  • The GetTimer function is new to VB .NET. However, it is functionally identical to the VB 6 Timer function (and VB .NET Timer property), which continues to be supported.
  • In contrast to the VB 6 Timer function, which returned a Single, the VB .NET GetTimer function and Timer property return a Double.

GoTo Statement

Syntax
GoTo label

label Use: Required Type: String literal

A subroutine name

Description
Passes execution to a specified line within a procedure

Rules at a Glance
label must be a line label

Programming Tips and Gotchas

  • GoTo can branch only to lines within the procedure where it appears.
  • It is not permitted to branch from outside a Try...Catch...Finally block to a point inside the Catch or Finally block.
  • It is also not permitted to branch from within the Catch or Finally block to a label outside the block.
  • The GoTo statement is most commonly used with the On Error statement to direct control to an error-handling routine.
  • GoTo is frequently used to control program flow within a procedure, a technique that often produces highly unreadable "spaghetti code." Accordingly, great care should be taken when using the GoTo statement.

VB .NET/VB 6 Differences
In VB 6, label could be either a line number or a label. In VB .NET, label can be only a label.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

VB.NET Topics