or: Dim obj As MyClass obj = New

2.7 Parameters and Arguments The terms parameter and argument are often used interchangeably, although they have entirely different meanings. Let us illustrate with an example. Consider the following function, which replicates a string a given number of times: Function RepeatString(ByVal sInput As String, ByVal iCount As Integer) _ As String Dim i As Integer For i = 1 To iCount RepeatString = RepeatString & sInput Next End Function The variables sInput and iCount are the parameters of this function. Note that each parameter has an associated data type. Now, when we call this function, we must replace the parameters by variables, constants, or literals, as in: s = RepeatString(“Donna”, 4) The items that we use in place of the parameters are called arguments. 2.7.1 Passing Arguments Arguments can be passed to a function in one of two ways: by value or by reference. Incidentally, argument passing is often called parameter passing, although it is the arguments and not the parameters that are being passed. The declaration of RepeatString given earlier contains the keyword ByVal in front of each parameter. This specifies that arguments are passed by value to this function. Passing by value means that the actual value of the argument is passed to the function. This is relevant when an argument is a variable. For instance, consider the following code: Sub Inc(ByVal x As Integer) x = x + 1 End Sub Dim iAge As Integer = 20 Inc(iAge) Msgbox(iAge) The final line: Msgbox(iAge) actually displays the number 20. In other words, the line: Inc(iAge) does nothing. The reason is that the argument iAge is passed to the procedure Inc by value. Since only the value (in this case 20) is passed, that value is assigned to a local variable named x within the procedure. This local variable is increased to 21, but once the procedure ends, the local variable is destroyed. The variable iAge is not passed to the procedure, so its value is not changed.
Note: If you are looking for cheap and inexpensive provider to host and run your tomcat application check Actions tomcat hosting services

Posted in vb

or: Dim obj As MyClass obj = New

As a result, VB’s Intellisense cannot help us with member syntax. More importantly, we pay a large performance penalty because VB cannot bind any of the classes properties or methods at compile time it must wait until runtime. This is referred to as late binding. In summary, explicit object-variable declarations allow for early binding and thus are much more efficient than generic declarations, which use late binding. Hence, explicit object-variable declarations should be used whenever possible. 2.6 The Collection Object VB .NET implements a special object called the Collection object that acts as a container for objects of all types. In fact, Collection objects can hold other objects, as well as nonobject data. In some ways, the Collection object is an object-oriented version of the Visual Basic array. It supports the following four methods: Add Adds an item to the collection. Along with the data itself, you can specify a key value by which the member can be referenced. Count Returns the number of items in the collection. Item Retrieves a member from the collection either by its index (or ordinal position in the collection) or by its key (assuming that a key was provided when the item was added to the collection). Remove Deletes a member from the collection using the member’s index or key. For example, the following code defines a collection object named colStates to hold information about U.S. states and then adds two members to it, using the state’s two-letter abbreviation as a key: Dim colStates As New Collection colStates.Add(“New York”, “NY”) colStates.Add(“Michigan”, “MI”) Like members of an array, the members of a collection can be iterated using the ForEach…Next construct. Also like arrays, collection members are accessible by their index value, although the lower bound of a collection object’s index is always 1. Arrays and collections each have advantages and disadvantages. Some of the advantages of collections over arrays are: New collection members can be inserted before or after an existing member in index order. Moreover, indexes are maintained automatically by VB, so we don’t need to adjust the indexes manually. Collection members can be referenced by key value. This feature makes collections similar to associative arrays (which are used by languages such as Perl). Note that when deleting collection members by index, it is important to iterate though the indexes in reverse order because member deletion changes the indexes of other members.
Note: If you are looking for cheap and inexpensive provider to host and run your tomcat application check Actions tomcat hosting services

Posted in vb

or: Dim obj As MyClass obj = New

or: Dim obj As MyClass obj = New MyClass( ) VB .NET also provides a shortcut that does not mention the constructor explicitly: Dim obj As New MyClass( ) (In earlier versions of VB, we use the Set statement, which is no longer supported.) 2.5.1 Late Binding Versus Early Binding The object-variable declaration: Dim obj As Class1 explicitly mentions the class from which the object will be created (in this case it is Class1). Because of this, VB can obtain and display information about the class members, as we can see in VB’s Intellisense, shown in Figure 2-1. Figure 2-1. Intellisense showing member list As you know, Intellisense also shows the signature of a method, as shown in Figure 2-2. Figure 2-2. Intellisense showing method signature Of course, Intellisense is very helpful during program development. However, more important is that the previous object-variable declaration allows VB to bind the object’s methods to actual function addresses at compile time. This is known as early binding. An alternative to using a declaration that specifically mentions that class is a generic object-variable declaration that uses the AsObject syntax: Dim obj As Object While it is true that obj can hold a reference to any object, we pay a major penalty for this privilege. VB can no longer get information about the class and its members because it does not know which class the object obj belongs to!
Note: If you are looking for cheap and inexpensive provider to host and run your tomcat application check Actions tomcat hosting services

Posted in vb

T arr:{0,1,…,5} has size 6. The two-dimensional array:

Dim MyArray(100) As Integer Dim i As Integer, iNext As Integer iNext = 0 Do While (Some condition) If (some condition here) Then ‘ Add element to array If ubound(MyArray) < iNext Then ReDim Preserve MyArray(iNext + 100) End If MyArray(iNext) = (whatever) iNext = iNext + 1 End If Loop The key issue here is to decide how much to increase the size of the array each time resizing is necessary. If we want to avoid using any extra space, we could increase the size of the array by 1 each time: ReDim Preserve MyArray(iNext + 1) But this would be very inefficient. Alternatively, we could kick up the size by 1,000: ReDim Preserve MyArray(iNext + 1000) But this uses a lot of extra space. Sometimes experimentation is required to find the right compromise between saving space and saving time. 2.5 Object Variables and Their Binding In VB .NET, classes and their objects are everywhere. Of course, there are the classes and objects that we create in our own applications. There are also the classes in the .NET Framework Class Library. In addition, many applications take advantage of the objects that are exposed by other applications, such as ActiveX Data Objects (ADO), Microsoft Word, Excel, Access, various scripting applications, and more. The point is that for each object we want to manipulate, we will need to declare a variable of that class type. For instance, if we create a class named CPerson, then in order to instantiate a CPerson object, we must declare a variable: Dim APerson As CPerson Similarly, if we decide to use the ADO Recordset object, we will need to declare a variable of type ADO.Recordset: Dim rs As ADO.Recordset Even though object variables are declared in the same manner as nonobject variables, there are some significant differences. In particular, the declaration: Dim obj As MyClass does not create an object variable it only binds a variable name with a class name. To actually construct an object and set the variable to refer to that object, we need to call the constructor of the class. This function, discussed in detail in Chapter 3, is responsible for creating objects of the class. Constructors are called using the New keyword, as in: Dim obj As MyClass = New Myclass( )
Note: If you are looking for cheap and quality provider to host and run your java application check Astra java hosting services

Posted in vb

T arr:{0,1,…,5} has size 6. The two-dimensional array:

Multidimensional arrays are declared similarly. For instance, the following example declares and initializes a two-dimensional array: Dim X(,) As Integer = {{1, 2, 3}, {4, 5, 6}} and the following code displays the contents of the array: Debug.Write(X(0, 0)) Debug.Write(X(0, 1)) Debug.Writeline(X(0, 2)) Debug.Write(X(1, 0)) Debug.Write(X(1, 1)) Debug.Write(X(1, 2)) 123 456 In VB .NET, all arrays are dynamic: there is no such thing as a fixed-size array. The declared size should be thought of simply as the initial size of the array, which is subject to change using the ReDim statement. Note, however, that the dimension of an array cannot be changed. Moreover, unlike with VB 6, the ReDim statement cannot be used for array declaration, but can be used only for array redimensioning. All arrays must be declared initially using a Dim (or equivalent) statement. 2.4.4.1 Redimensioning arrays The ReDim statement is used to change the size of an array. This is referred to as redimensioning –a term no doubt invented by someone who didn’t know the difference between the dimension of an array and the size of an array! In any case, redimensioning changes the size of the array, not its dimension. In fact, as we have already mentioned, the dimension of an array cannot be changed. The UBound function returns the upper limit of an array coordinate. Its syntax is: UBound(MyArray, CoordinateIndex) where CoordinateIndex is the index of the coordinate for which we want the upper bound. Here is an example of array redimensioning: Dim MyArray(10, 10) As Integer Msgbox(UBound(MyArray, 2)) ReDim MyArray(15, 20) Msgbox(UBound(MyArray, 2)) ‘ Displays 10 ‘ Displays 20 When an array is redimensioned using the ReDim statement without qualification, all data in the array is lost; that is, the array is reinitialized. However, the Preserve keyword, when used with ReDim, redimensions the array while retaining all current values. Note that when using the Preserve keyword, only the last coordinate of an array can be changed. Thus, referring to the array defined earlier, the following code generates an error: ReDim Preserve MyArray(50, 20) You will probably not be surprised to learn that redimensioning an array is a time-intensive process. Hence, when redimensioning, we face the ubiquitous dichotomy between saving space and saving time. For instance, consider the code segment used to populate an array:
Note: If you are looking for cheap and quality provider to host and run your java application check Astra java hosting services

Posted in vb

T arr:{0,1,…,5} has size 6. The two-dimensional array:

T arr:{0,1,…,5} has size 6. The two-dimensional array: arr:{0,1,…,5}x{0,1,…,8} T has size 6×9. The three-dimensional array: arr:{0,1,…,5}x{0,1,…,8}x{0,1} T has size 6x9x2. 2.4.4 Arrays in VB .NET In VB .NET, all arrays have lower bound 0. This is a change from earlier versions of VB, where we could choose the lower bound of an array. The following examples show various ways to declare a one-dimensional array: ‘ Implicit constructor: No initial size and no initialization Dim Days( ) As Integer ‘ Explicit constructor: No initial size and no initialization Dim Days() As Integer = New Integer( ) {} ‘ Implicit constructor: Initial size but no initialization Dim Days(6) As Integer ‘ Explicit constructor: Initial size but no initialization Dim Days( ) As Integer = New Integer(6) {} ‘ Implicit constructor: Initial size implied by initialization Dim Days( ) As Integer = {1, 2, 3, 4, 5, 6, 7} ‘ Explicit constructor, Initial size and initialization Dim Days( ) As Integer = New Integer(6) {1, 2, 3, 4, 5, 6, 7} Note that an array declaration can: Call the array’s constructor implicitly or explicitly. (The constructor is the function that VB .NET uses to create the array.) Specify an initial size for each dimension or leave the initial size unspecified. Initialize the elements of the array or not. It is important to note that in the declaration: Dim ArrayName(X) As ArrayType the number X is the upper bound of the array. Thus, the array elements are ArrayName(0) through ArrayName(X), and the array has X+1 elements.
Note: If you are looking for cheap and quality provider to host and run your java application check Astra java hosting services

Posted in vb

For a reference to the object-oriented terminology, see

representation of that date, in the date format defined by the regional settings of the host computer. For a numeric expression, the return value is a string representing the number. CType A general-purpose conversion function, CType has the following syntax: CType(expression, typename) where expression is an expression or variable, and typename is the data type to which it will be converted. The function supports conversions to and from the standard data types, as well as to and from object data types, structures, and interfaces. 2.4 Arrays The array data type is a fundamental data type in most languages, including Visual Basic. An array is used to store a collection of similar data types or objects. Many authors of programming books misuse the terms associated with arrays, so let’s begin by establishing the correct terminology. In fact, if you will indulge us, we would like to begin with a formal definition of the term array. 2.4.1 Definition of Array Let S1, S2 …, SN be finite sets, and let T be a data type (such as Integer). Then an array of type T is a function: arr:S1 x S2 x … x SN T where S1 x S2 x … x SN is the Cartesian product of the sets S1, S2 …, SN. (This is the set of all n-tuples whose coordinates come from the sets Si.) For arrays in VB .NET (and the other languages that implement the Common Language Runtime), the sets Si must have the form: Si={0,1,…,Ki} In other words, each set Si is a finite set of consecutive integers starting with 0. Each position in the Cartesian product is referred to as a coordinate of the array. For each coordinate, the integer Ki is called the upper bound of the coordinate. The lower bound is 0 for all arrays in VB .NET. 2.4.2 Dimension of an Array The number N of coordinates in the domain of the function arr is called the dimension (or sometimes rank) of the array. Thus, every array has a dimension (note the singular); it is not correct to refer to the dimensions of an array (note the plural). An array of dimension 1 is called a one-dimensional array, an array of dimension 2 is called a two-dimensional array, and so on. 2.4.3 Size of an Array Along with a dimension, every array has a size. For instance, the one-dimensional array:
Note: If you are looking for best hosting provider to host and run your tomcat application check Astra tomcat hosting services

Posted in vb

For a reference to the object-oriented terminology, see

Converts any numeric expression in the range 0 to 255 to Byte, while rounding any fractional part. CChar Takes a string argument and returns the first character of the string as a Char data type. CDate Converts any valid representation of a date or time to Date. CDbl Converts any expression that can be evaluated to a number in the range of a Double to Double. CDec Converts any expression that can be evaluated to a number in the range of a Decimal to Decimal. CInt Converts any numeric expression in the range of Integer (-2,147,483,648 to 2,147,483,647) to Integer, while rounding any fractional part. CLng Converts any expression that can be evaluated to a number in the range of a Long to Long, while rounding any fractional part. CObj Converts any expression that can be interpreted as an object to Object. For instance, the code: Dim obj As Object obj = CObj(“test”) casts the string “test” to type Object and places it in the Object variable obj. CShort Converts any numeric expression in the range -32,768 to 32,767 to Short, while rounding any fractional part. CSng Converts any expression that can be evaluated to a number in the range of a Single to Single. If the numeric expression is outside the range of a Single, an error occurs. CStr If the expression input to CStr is Boolean, the function returns one of the strings “True” or “False.” For an expression that can be interpreted as a date, the return value is a string
Note: If you are looking for best hosting provider to host and run your tomcat application check Astra tomcat hosting services

Posted in vb

For a reference to the object-oriented terminology, see

For a reference to the object-oriented terminology, see Chapter 3. 2.3.4 Data Type Conversion The process of converting a value of one data type to another is called conversion or casting. A cast operator can be applied to a literal value or to a variable of a given type. For instance, we have: Dim lng As Long Dim int As Integer = 6 ‘ Cast an Integer variable to a Long lng = CLng(Int) ‘ Cast a literal integer to a Long lng = CLng(12) A cast can be widening or narrowing. A widening cast is one in which the conversion is to a target data type that can accommodate all values in the source data type, such as casting from Short to Integer or Integer to Double. In such a case, no data is ever lost, and the cast will not generate an error. A narrowing cast is one in which the target data type cannot accommodate all values in the source data type. In this case, data may be lost, and the cast may not succeed. Under VB .NET, conversions are made in two ways: implicitly and explicitly. An implicit conversion is done by the compiler when circumstances warrant it (and if it is legal). For instance, if we write: Dim lng As Long lng = 54 then the compiler casts the Integer 54 as a Long. The type of implicit conversion that the compiler will do depends in part on the setting of the Option Strict value. For instance, if OptionStrict is On, only widening casts can be implicit; so then the following code: Dim b As Boolean b = “True” generates a type conversion error, whereas if we add the line: Option Strict Off to the beginning of the module, then the previous code executes without error. Explicit conversion requires explicitly calling a conversion function (or cast operator). The type conversion functions supported by VB .NET all have the form: Cname(expression) where expression is an expression that is in the range of the target data type. Specifically, we have the following conversion functions: CBool Converts any valid String or numeric expression to Boolean. When a numeric value is converted to Boolean, any nonzero value is converted to True, and zero is converted to False. CByte
Note: If you are looking for best hosting provider to host and run your tomcat application check Astra tomcat hosting services

Posted in vb

obj.GetType returns a Type object. In turn, the

The simplest and most common use of structures is to encapsulate related variables. For instance, we might define a structure as follows: Structure strPerson Public Name As String Public Address As String Public City As String Public State As String Public Zip As String Public Age As Short End Structure To define a variable of type strPerson, we write (as usual): Dim APerson As strPerson To access a member of a structure, we use the dot syntax, as in: APerson.Name = “Beethoven” Note that structure members can be other structures or other objects. Structures can also be passed as arguments to functions, or as the return type of a function. As mentioned, structures are similar to classes. For instance, consider the following structure: Structure strTest ‘ A public nonmethod member Public Name As String ‘ A private member variable Private msProperty As String ‘ A public method member Public Sub AMethod( ) Msgbox(“Structure method. Property is: ” & msProperty) End Sub ‘ A public property member Public Property AProperty( ) As String Get AProperty = msProperty End Get Set msProperty = Value End Set End Property End Structure Now we can set the structure’s property and invoke its method as follows: Dim str As strTest str.AProperty = “Donna” str.AMethod( ) Although structures are similar to classes, they do not support the following class features: Structures cannot explicitly inherit, nor can they be inherited. All constructors for a structure must be parameterized. Structures cannot define destructors. Member declarations cannot include initializers nor can they use the AsNew syntax or specify an initial array size.
Note: If you are looking for good and high quality web space to host and run your java application check Vision java hosting services

Posted in vb