Download presentation
Presentation is loading. Please wait.
1
Learning VB2005 language (basics)
Lecture 06 Chapter 2 Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
2
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
3
Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
4
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
5
Question..?? Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
6
Variable Operations Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
7
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
8
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
9
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
10
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
11
Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
12
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
13
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
14
Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
15
Question..?? Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
16
Object-Based Manipulation
Every type in the .NET class library includes a ToString() method Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
17
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
18
Table 2-3 lists some useful members of the String class. P.36
Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
19
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
20
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
21
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
22
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
23
Thanks Internet Technologies I - Lect.06 - Waleed Ibrahim Osman
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.