Introduction to computers, the Internet & VB .Net Tutorial 1 Introduction to computers, the Internet & VB .Net
Introduction to Visual Studio .Net and IDE Tutorial 2 Introduction to Visual Studio .Net and IDE
Start Page
Creating a New Project Select Windows Application Select Visual Basic Projects Specify project name Specify location
Design View
Solution Explorer Expanded mode Collapsed mode Form file Continue
Categorized & Alphabetic listing options Properties Window Categorized & Alphabetic listing options Property name Expanded mode Property value Collapsed mode
Using Help Contents Index Search MSDN (http://msdn.microsoft.com/)
Saving Project File > Save All Do not use File > Save or Save As To copy a project, use Windows Explorer to copy the entire project folder
Introduction to Visual Programming Tutorial 3 Introduction to Visual Programming
Opening an Existing Project Open VB .Net Click the Open Project button Open the Solution file with the sln file extention Continue
If the Form does not show in the Design window, double-click on the Form file in the Solution Explorer.
RGB Color Scheme Example: 255, 237, 169 Each number represents the amount of color of Red, Green, and Blue respectively The higher the number, the more the color. e.g. 0, 0, 255 is blue. The value of color range between 0 and 255 (00 FF in Hexadecimal) Continue
What Happens After Debug After a successful Debug run, VB .Net creates an executable (exe) file in the Bin folder of the Project.
Designing the Inventory Application. Tutorial 4 Designing the Inventory Application.
Naming Controls Instead of using generic names created by VB .Net, use unique and informative names E.g. TextBox1 vs. txtSalesAmount The txt prefix indicates it is a TextBox control “SalesAmount” tells it is something about sales amount Sentence-style capitalization. Capitalize the first letter of each word instead of a blank space Continue
Suggested Prefixes for Controls
Label and Textbox Controls Labels: Displaying information or output. Textbox: Read in input data Continue
What Happens After Debug After a successful Debug run, VB .Net creates an executable (exe) file in the Bin folder of the Project.
Introducing Code Programming Tutorial 5 Introducing Code Programming
What is Class Building blocks of a program Provided by VB .Net Framework Class Library Template definition of the methods and variables in a particular kind of object VB Windows forms inherit definitions from the System.Windows.Forms.Form class.
Object-Oriented Programming (OOP) Programming language model Organized around "objects" rather than "actions" and data rather than logic Subclass and inheritance Class 1 Class 2 Food Fruit Apple Machine Computer Sources: techtarget.com Continue
Polymorphism: Actions or behaviors that share the same essence would have a common name even though they belong to different objects. E.g., opening (action) a computer application (object) is different from opening a door in terms of operations. However, the name of the action for both objects is open since the idea is the same. ComputerApplicatoin.Open Door.Open
Structures of OOP Action Value Object.Behavior Object.Method Object.Property Object.Attribute
Val and Str Functions Val: Returns a numeric value of an argument (string value) E.g. Val(“123”) 123 Str: Returns a string value E.g. Str(123) “123”
Introducing Variables, Memory Concepts & Arithmetic Tutorial 6 Introducing Variables, Memory Concepts & Arithmetic
Variables Holds data Controls for Design Programming, Variables for Code Programming Text Property Data Variable Manipulate data w/o showing to users Store data w/o adding or using controls Hold numbers, data & time, text, and etc. Continue
One type of variable can take the same type of data. E.g. intCount = 15 (OK) intCount = “Pat” (not OK) intCount = “15” (not OK) Must be declared. E.g. Dim intCount As Integer Dim sngPrice As Single Continue
Steps of Using Variables Declare Input: Assign a value by reading in from a control or other source Process: Use or manipulate Output: Put the value to a control or other object
Example 1: Dim intTotal As Integer intTotal = Val(txtTotal.Text) intTotal = intTotal + 10 txtTotal.Text = Str(intTotal)
Example 2: Dim intTotal As Integer Dim intExtra As Integer intTotal = Val(txtTotal.Text) intExtra = 10 intTotal = intTotal + intExtra txtTotal.Text = Str(intTotal)
Example 3: Dim intTotal As Integer Dim intExtra As Integer = 10 intTotal = Val(txtTotal.Text) intTotal = intTotal + intExtra txtTotal.Text = Str(intTotal)
Data Types of Variables Memory Allocation Value Range Boolean 2 bytes True or False. Char 0 through 65535 (unsigned). Date 8 bytes 0:00:00 on January 1, 0001 through 11:59:59 PM on December 31, 9999. String Depends on platform 0 to approximately 2 billion Unicode characters. Short -32,768 through 32,767. Integer 4 bytes -2,147,483,648 through 2,147,483,647. Long -9,223,372,036,854,775,808 through 9,223,372,036,854,775,807. Single -3.4028235E+38 through -1.401298E-45 for negative values; 1.401298E-45 through 3.4028235E+38 for positive values. Double -1.79769313486231570E+308 through -4.94065645841246544E-324 for negative values; 4.94065645841246544E-324 through 1.79769313486231570E+308 for positive values. Decimal 16 bytes 0 through +/-79,228,162,514,264,337,593,543,950,335 with no decimal point; 0 through +/-7.9228162514264337593543950335 with 28 places to the right of the decimal; smallest nonzero number is +/-0.0000000000000000000000000001 (+/-1E-28).
Integer Stored as 32-bit (4-byte) integers ranging in value from -2,147,483,648 through 2,147,483,647. Provides optimal performance on a 32-bit processor, as the smaller integral types are slower to load and store from and to memory. You can convert the Integer data type to Long, Single, Double, or Decimal without encountering a System.OverflowException error.
Single Stored as IEEE 32-bit (4-byte) single-precision floating-point numbers ranging in value from -3.4028235E+38 through -1.401298E-45 for negative values and from 1.401298E-45 through 3.4028235E+38 for positive values. Single-precision numbers store an approximation of a real number. Can be converted to the Double or Decimal data type without encountering a System.OverflowException error.
String Stored as sequences of 16-bit (2-byte) numbers ranging in value from 0 through 65535 Each number represents a single Unicode character. A string can contain up to approximately 2 billion (2 ^ 31) Unicode characters The first 128 code points (0–127) of Unicode correspond to the letters and symbols on a standard U.S. keyboard The second 128 code points (128–255) represent special characters, such as Latin-based alphabet letters, accents, currency symbols, and fractions The remaining code points are used for a wide variety of symbols
Prefixes for Variables Data Type Prefix Boolean bln Integer int Byte byt Long lng Currency cur Short sht Date(time) dtm Single sng Double dbl String str
Mathematical Operation ClassAve = TotalScores / NumOfStudents Arithmetic Operators Order Operator Mathematical Operation Example 1 ( ) Parentheses 2 ^ Exponentiation CubicSpace = Length ^ 3 8 = 2 ^ 3 3 - Negation - Num1 4 * or / Multiplication Division Total_Sales = Unit_Price * Count ClassAve = TotalScores / NumOfStudents 5 \ Integer Division (DIV). The whole number portion of the answer in a division. The decimal position is dropped. CarsCanFitIn = AreaOfLot \ CarDim 10 = 215 \ 20 15 is leftover Continue
Mathematical Operation Example Order Operator Mathematical Operation Example 6 MOD Integer Remainder Division. The whole number portion of a remainder in a division. If the divider is greater than the number it is dividing, then the number become the remainder of the MOD division. BoothSpace = 3 MOD 10 3 = 3 MOD 10 7 + or - Addition Subtraction Total = Num1 + Num2 Profit = Sales - Expenses & String concatenation FullName$ = First$ & Last$
Using Debugger Demo
Introducing CheckBoxes & Message Dialogs Tutorial 8 Introducing CheckBoxes & Message Dialogs
Basic Structure of Simple Codes Declare variables for input and output controls Use appropriate data types and prefixes Input Read in assign input values to input variables Use Val conversion function for numeric input data Process Using input and other elements, calculate the result. Ouput Assign the result into the output control.
Example
Error Handling Check error Resolve error Input Process Output
Code Structure with Error Handling If [error condition] Then do something, e.g. MessageBox Else input process output End If Or
If [error condition] Then do something, e.g. MessageBox or Exit Sub End If input process output
Basic Structure If [condition] Then code(s) to be executed End If If intGrade >= 60 Then lblCourseResult.Text = “Passed” Continue
Coding with CheckBox If chkMembership.Checked Then or If (chkMembership.Checked = True) Then If (chkMembership.Checked = False) Then
Logical Operators And (AndAlso) Or Not Xor Logical Operator Meaning Example And (AndAlso) Only if both conditions are true, then the result is true. If [condition1] And [condition 2] Or (OrElse) If at least one condition is true, then the result is true If [condition1] Or [condition 2] Not Negation of the condition. If the condition is true, the result is false. If the condition is false, then the result is true. If Not [condition] Xor If one and only one of the conditions is true, then the result is true. If all conditions are either true or false, then the result is false. So, if all conditions are false, then the result is false. If all conditions are true, then the result is also false. If blnStake Xor blnBurger Then strCustomer = “Satisfied” End If If a customer is served with either a stake or a burger, she is happy. But if the customer is not served anything or both, then she is not happy. (too hungry or too full)
MessageBox Function See textbook pages 174 and 175 for details
Introducing Do While & Do Until Loops & Repetition Statements Tutorial 9 Introducing Do While & Do Until Loops & Repetition Statements
Do While Loop Do While [condition] action(s) Loop intCounter = 0 Do While (intCounter < 10) intSumOfNumbersUpto10 += intCounter intCounter += 1 Continue
Repeats the actions as long as the condition is true The condition must change, otherwise infinite loop will occur. Within the loop add code(s) to change the condition that eventually become false
Do Until Loop Do Until [condition] action(s) Loop intCounter = 0 Do Until (intCounter >= 10) intSumOfNumbersUpto10 += intCounter intCounter += 1 Continue
Repeats the actions as long as the condition is false The condition must change, otherwise infinite loop will occur. Within the loop add code(s) to change the condition that eventually become true
Coding with ListBox Remove items in the ListBox lstStudents.Items.Clear( ) Class.SubClass.Behavior or Add items to the ListBox lstStudents.Items.Add (“Name” & ControlChars.Tab & ControlChars.Tab & “Course”)
Example Dim intCounter As Integer = 1 Dim intSumOfNumbersUpto10 As Integer = 0 Do While (intCounter < 10) intSumOfNumbersUpto10 += intCounter lstNumbersUpto10.Items.Add(“Number “ & intCounter & ControlChars.Tab & intSumOfNumbersUpto10) intCounter += 1 Loop
What is a Computer? Examples? History A device capable of Performing computation Making logical decisions Faster than human Process data using computer programs
What is a computer program? A set of instructions a.k.a. application & software
Computer Organization Input devices: keyboard, mouse, scanner, microphone, digital camera, & etc. Output devices: monitor, printer, projector, device control, & etc. Memory: Primary memory, RAM. Voatile. Arithmetic & logic unit (ALU): Performs calculation, logical comparison, decision making. Continue
Central processing unit (CPU): Administrates process operations. Secondary storage: Long-term storage of applications and data. E.g. hard drive, CD/DVD drive , & etc.
Three Types of Languages Machine language: A natural language of a particular computer machine dependent. +3422221207 +4060234234 +6345335372 Continue
High-level language: More convenient for programmers. Assembly language: English-like. Translator program called assembler converts to machine language. LOAD BASEPAY ADD OVERPAY STORE GROSSPAY High-level language: More convenient for programmers. GrossPay = BasePay + OverPay
High level languages Visual Basic .Net: Evolved from Visual Basic. GUI. Object Oriented. Pascal, C, C++, C# COBOL Java HTML?, JavaScript?, VBScript?
Language Relationships Refer to http://www.erg.abdn.ac.uk/users/gorry/eg2068/course/comp.html
What is .Net A set of software technologies for connecting information, people, systems, and devices. Based on Web services—small building-block applications that can connect to each other as well as to other, larger applications over the Internet. http://www.microsoft.com/net/basics/ Continue
Object Oriented Programming Example: What if the replicater does not use OOP? Structure: Object.Property or Object.Attribute Object.Behavior or Object.Method Class: Related objects. E.g. car, wheel, hub, bolt, & etc.