Learning VB2005 language (basics) Lecture 06 Chapter 2 Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
Variables and Data Types This example shows one other ingredient in VB programming: comments. Comments are descriptive text that is ignored by the compiler. VB comments always start with an apostrophe (') and continue for the entire line. Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
Assignment and Initializes Visual Basic is kind enough to let you use simple data types without initializing them. Numbers are automatically initialized to 0 and strings are initialized to an empty string (""). That means the following code will succeed in VB: Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
Question..?? Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
Variable Operations Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
Shorthand assignment operators When dealing with strings, you can use the concatenation operator (&), which joins together two strings. Shorthand assignment operators Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
Line Termination Sometimes, code statements are too long to efficiently fit on a single line. In Visual Basic, you can break a code statement over multiple lines by adding (an underscore) (after Space) Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
Advanced Math To use the math operations, you invoke the methods of the Math class. These methods are shared, which means they are always available and ready to use Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
Type Conversions Converting information from one data type to another is a fairly common task. For example, you might retrieve text input for a user that contains the number you want to use for a calculation. Or, you might need to take a calculated value and transform it into text you can display in a web page. Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
The problem with conversion Conversions are of two types: Widening. convert a number into a string, or a 16-bit integer into a 32-bit integer Narrowing. may or may not succeed (converting a 32-bit integer to a 16-bit integer) Widening conversions always succeed A failed narrowing conversion will lead to an unexpected runtime error. Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
The problem with conversion (Solved) Adding an Option Strict instruction to the beginning of your code files. In this case, VB will not allow automatic or implicit data type conversions if they could cause an error or lose data. Instead, you’ll need to explicitly indicate that you want to perform a conversion. To perform an explicit data type conversion in VB, you use the CType() function. This function takes two arguments. The first specifies the variable you want to convert, and the second specifies the data type you’re converting it to. Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
Question..?? Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
Object-Based Manipulation Every type in the .NET class library includes a ToString() method Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
The String Type The following code snippet “small piece” shows several ways to manipulate a string using the methods in the String type: Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
Table 2-3 lists some useful members of the String class. P.36 Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
The DateTime and TimeSpan Types Performs three useful tasks: Extract a part of a DateTime (for example, just the year) or convert a TimeSpan to a specific representation (such as the total number of days or total number of minutes). Easily perform date and time calculations. Determine the current date and time and other information (such as the day of the week or whether the date occurs in a leap “jump” year). Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
For example, the following block of code creates a DateTime object, sets it to the current date and time. Adds a number of days. It then creates a string that indicates the year that the new date falls in (for example, 2006). Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
The next example shows how you can use a TimeSpan object to find the total number of minutes between two DateTime objects. Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
Next … To-Do list P.39 - 44 Conditional Structures Loop Structures The If ... End If Block The Select Case Block Loop Structures The For ...Next Block The For Each Block The Do ... Loop Block Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
Thanks Internet Technologies I - Lect.06 - Waleed Ibrahim Osman