Week 1 – 3 Recap <ul><li>Useful links/info: </li></ul><ul><li>TPITVB.blogspot.com </li></ul>
VB.NET Week 1 <ul><li>Outline: </li></ul><ul><li>Introduction </li></ul><ul><li>Simple walk through </li></ul><ul><li>Codi...
Coding Conventions <ul><li>All keywords – Start with Capital </li></ul><ul><li>Example:  Dim  As  Integer  String  Boolean...
VB.NET Week 2 <ul><li>Outline: </li></ul><ul><li>Variables </li></ul><ul><li>Strings </li></ul><ul><li>Operators </li></ul...
Variables - Declaring <ul><li>Declare a variable using the  Dim  and  As  keywords: </li></ul><ul><ul><li>Dim  sumOfNumber...
Variables - Declaring <ul><li>Data Type Summary </li></ul>Single: single-precision decimal (floating point) Double: double...
Java <ul><li>8 primitive types:  </li></ul><ul><ul><li>b yte </li></ul></ul><ul><ul><li>s hort </li></ul></ul><ul><ul><li>...
Variables - assigning <ul><li>Assign a value to your variable with the  =  sign, which is sometimes called the  assignment...
Variables - assigning <ul><li>Declaring and Assigning Variables with a Default Value  </li></ul><ul><ul><li>Dim sumOf Numb...
Arithmetics Operators Division / Multiplication * Subtraction - Addition +
Other Arithmetic Operators <ul><li>^   to the power of </li></ul><ul><li>mod remainder after division  (Java:%) </li></ul>...
Do not have these operators <ul><li>Java </li></ul><ul><li>++ </li></ul><ul><li>- - </li></ul>
Comparison Operators Comparison operators are used to in condition  Eg  If  (condition) doSomthing 4 <> 4 (false) 4 <> 5 (...
Comparison Operators 4 < 4 (false) 4 < 5 (true) 5 < 4 (false) < (less than) 4 > 4 (false) 4 > 5 (false) 5 > 4 (true) > (gr...
Comparison Operators 4 <= 4 (true) 4 <= 5 (true) 5 <= 4 (false) <= (less than or equal to) 4 >= 4 (true) 4 >= 5 (false) 5 ...
Conversion from String to other types Use CType if you are not sure the name of the conversion function Example: to conver...
Type Conversion examples <ul><li>Dim inputString As String = TextBox1.Text </li></ul><ul><li>Dim x As Integer  </li></ul><...
Maths Functions <ul><li>Math.Sqrt(n):  Return the square root of n. </li></ul><ul><li>Math.Abs(n): Return the absolute val...
Class  vs  Local  variables <ul><li>Public Class Form1 </li></ul><ul><li>Dim x As Integer = 0 ' Class variables. </li></ul...
VB.NET lesson week  <ul><li>Get Input from User </li></ul><ul><li>If Then Else, Else If </li></ul><ul><li>Select Case </li...
Get Input from User Dim name As String name =  InputBox (&quot;Enter your name:&quot;) MsgBox (&quot;Your name is &quot; &...
If Then Else, Else If <ul><li>Syntax </li></ul><ul><li>If  condition  Then </li></ul><ul><li>: </li></ul><ul><li>End If </...
More than one condition <ul><li>And condition1  And  condition2 </li></ul><ul><li>AndAlso  condition1  AndAlso  condition2...
More than one condition <ul><li>Or condition1  Or  condition2 </li></ul><ul><li>OrElse  condition1  OrElse  condition2 </l...
Short cut If and Assignment <ul><li>IIf  I mmediate  If </li></ul><ul><li>x = IIf( i > 0, 1, 0) </li></ul><ul><li>Same As ...
Select Case <ul><li>Syntax </li></ul><ul><li>Select  Case  variable </li></ul><ul><li>Case  condition1 </li></ul><ul><li>:...
Select Case Conditions <ul><li>Case  &quot;red&quot;, &quot;white&quot;, &quot;green&quot;  ' A few together . </li></ul><...
Java <ul><li>if (condition) { </li></ul><ul><li>: </li></ul><ul><li>}  else  if (condition 2) { </li></ul><ul><li>} else {...
End of lessons
Upcoming SlideShare
Loading in …5
×

Vb.Net 01 To 03 Summary Upload

1,196 views

Published on

Vb.Net 01 To 03 Summary Upload

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,196
On SlideShare
0
From Embeds
0
Number of Embeds
31
Actions
Shares
0
Downloads
33
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Vb.Net 01 To 03 Summary Upload

  1. 1. Week 1 – 3 Recap <ul><li>Useful links/info: </li></ul><ul><li>TPITVB.blogspot.com </li></ul>
  2. 2. VB.NET Week 1 <ul><li>Outline: </li></ul><ul><li>Introduction </li></ul><ul><li>Simple walk through </li></ul><ul><li>Coding Conventions </li></ul>
  3. 3. Coding Conventions <ul><li>All keywords – Start with Capital </li></ul><ul><li>Example: Dim As Integer String Boolean </li></ul><ul><li>If Then Else ElseIf End If </li></ul><ul><li>Select Case Case End Select </li></ul><ul><li>All variable name – Start with small letter </li></ul><ul><li>Example: i x y nameOfVariable existingString </li></ul><ul><li>total sumOfNumber </li></ul>
  4. 4. VB.NET Week 2 <ul><li>Outline: </li></ul><ul><li>Variables </li></ul><ul><li>Strings </li></ul><ul><li>Operators </li></ul><ul><li>Maths helper functions </li></ul><ul><li>Application: Create a Calculator for addition </li></ul>
  5. 5. Variables - Declaring <ul><li>Declare a variable using the Dim and As keywords: </li></ul><ul><ul><li>Dim sumOfNumber As Integer </li></ul></ul><ul><ul><li>Name of variable: sumOfNumber </li></ul></ul><ul><ul><li>Type: Integer </li></ul></ul><ul><li>(Dim: Short for dimension) </li></ul>
  6. 6. Variables - Declaring <ul><li>Data Type Summary </li></ul>Single: single-precision decimal (floating point) Double: double-precision decimal True, False Boolean 8 bytes to store date and time Date 8 bytes to store decimals (others: Single, Decimal) Double 4 bytes to store whole number (others: Short, Long) Integer word or sentence (for just one character: Char) String
  7. 7. Java <ul><li>8 primitive types: </li></ul><ul><ul><li>b yte </li></ul></ul><ul><ul><li>s hort </li></ul></ul><ul><ul><li>i nt </li></ul></ul><ul><ul><li>l ong </li></ul></ul><ul><ul><li>f loat </li></ul></ul><ul><ul><li>d ouble </li></ul></ul><ul><ul><li>b oolean </li></ul></ul><ul><ul><li>c har </li></ul></ul><ul><li>S tring – not primitive type </li></ul>
  8. 8. Variables - assigning <ul><li>Assign a value to your variable with the = sign, which is sometimes called the assignment operator </li></ul><ul><ul><li>sumOfNumber = 42 </li></ul></ul><ul><ul><li>This line of code takes the value 42 and stores it in the previously declared variable named sumOfNumber </li></ul></ul><ul><ul><li>The equals sign is not actually an equals sign. </li></ul></ul><ul><ul><li>The = sign here means assign a value of . </li></ul></ul>
  9. 9. Variables - assigning <ul><li>Declaring and Assigning Variables with a Default Value </li></ul><ul><ul><li>Dim sumOf Number As Integer = 0 </li></ul></ul><ul><ul><li>Dim nameOfPerson As String = &quot;None&quot; </li></ul></ul>
  10. 10. Arithmetics Operators Division / Multiplication * Subtraction - Addition +
  11. 11. Other Arithmetic Operators <ul><li>^ to the power of </li></ul><ul><li>mod remainder after division (Java:%) </li></ul><ul><li> division but return only integer portion </li></ul><ul><li>Short cut: </li></ul><ul><li>+= x += y same as x = x + y </li></ul><ul><li>-= x -= y same as x = x - y </li></ul><ul><li>*= x *= y same as x = x * y </li></ul><ul><li>/= x /= y same as x = x / y </li></ul>
  12. 12. Do not have these operators <ul><li>Java </li></ul><ul><li>++ </li></ul><ul><li>- - </li></ul>
  13. 13. Comparison Operators Comparison operators are used to in condition Eg If (condition) doSomthing 4 <> 4 (false) 4 <> 5 (true) 5 <> 4 (true) <> (not equal to) 4 = 4 (true) 4 = 5 (false) 5 = 4 (false) = (equals) Examples Operator
  14. 14. Comparison Operators 4 < 4 (false) 4 < 5 (true) 5 < 4 (false) < (less than) 4 > 4 (false) 4 > 5 (false) 5 > 4 (true) > (greater than) Examples Operator
  15. 15. Comparison Operators 4 <= 4 (true) 4 <= 5 (true) 5 <= 4 (false) <= (less than or equal to) 4 >= 4 (true) 4 >= 5 (false) 5 >= 4 (true) >= (greater than or equal to) Examples Operator
  16. 16. Conversion from String to other types Use CType if you are not sure the name of the conversion function Example: to convert to Boolean CType(variableName, Boolean)
  17. 17. Type Conversion examples <ul><li>Dim inputString As String = TextBox1.Text </li></ul><ul><li>Dim x As Integer </li></ul><ul><li>x = CInt (inputString) ' Convert to Integer. </li></ul><ul><li>Dim y As Integer = 8 </li></ul><ul><li>Textbox1.Text = CStr (y) ' Convert to String. </li></ul>c i n t c s t r
  18. 18. Maths Functions <ul><li>Math.Sqrt(n): Return the square root of n. </li></ul><ul><li>Math.Abs(n): Return the absolute value of n. </li></ul><ul><li>Math.Sign(n): Return the sign of n ( -1, 0 or +1 ). </li></ul><ul><li>Example: </li></ul><ul><li> Dim x As Integer </li></ul><ul><li> Dim y As Integer = 25 </li></ul><ul><li> TextBox1.Text = Math.Sqrt( y ) </li></ul><ul><li>‘ MsgBox( &quot;Sq root of 25 is &quot; & CStr(x) ) </li></ul>
  19. 19. Class vs Local variables <ul><li>Public Class Form1 </li></ul><ul><li>Dim x As Integer = 0 ' Class variables. </li></ul><ul><li>Dim name As String = &quot;&quot; </li></ul><ul><li>Sub Button0_Click … </li></ul><ul><li>Dim y As Integer = 9 ' Local sub variables. </li></ul><ul><li>End Sub </li></ul><ul><li>: </li></ul><ul><li>End Class </li></ul>x = 5 ' OK or Not? y = 5 ' OK or Not? x = 5 ' OK or Not? y = 5 ' OK or Not?
  20. 20. VB.NET lesson week <ul><li>Get Input from User </li></ul><ul><li>If Then Else, Else If </li></ul><ul><li>Select Case </li></ul><ul><li>Add condition checking into Simple Calculator </li></ul>
  21. 21. Get Input from User Dim name As String name = InputBox (&quot;Enter your name:&quot;) MsgBox (&quot;Your name is &quot; & name)
  22. 22. If Then Else, Else If <ul><li>Syntax </li></ul><ul><li>If condition Then </li></ul><ul><li>: </li></ul><ul><li>End If </li></ul>Else : ElseIf condition2 Then ' Can repeat for : ' more conditions Example If name <> &quot;&quot; Then MsgBox(name) End If Example If name <> &quot;&quot; Then MsgBox(name) Else MsgBox(&quot;Empty&quot;) End If Example If name = &quot;&quot; Then MsgBox(&quot;Empty&quot;) ElseIf name = &quot;me&quot; Then MsgBox(&quot;Me&quot;) Else MsgBox(name) End If
  23. 23. More than one condition <ul><li>And condition1 And condition2 </li></ul><ul><li>AndAlso condition1 AndAlso condition2 </li></ul><ul><li>Recommended - Short-circuit And </li></ul><ul><li>Eg If i > 0 AndAlso j <> 5 Then </li></ul>Once i > 0 is false, no need to check j <> 5
  24. 24. More than one condition <ul><li>Or condition1 Or condition2 </li></ul><ul><li>OrElse condition1 OrElse condition2 </li></ul><ul><li>Recommended - Short-circuit Or </li></ul><ul><li>Eg If i > 0 OrAlso j <> 5 Then </li></ul>Once i > 0 is true, no need to check j <> 5
  25. 25. Short cut If and Assignment <ul><li>IIf I mmediate If </li></ul><ul><li>x = IIf( i > 0, 1, 0) </li></ul><ul><li>Same As </li></ul><ul><li>If i > 0 Then </li></ul><ul><li>x = 1 </li></ul><ul><li>Else </li></ul><ul><li>x = 0 </li></ul><ul><li>End If </li></ul>
  26. 26. Select Case <ul><li>Syntax </li></ul><ul><li>Select Case variable </li></ul><ul><li>Case condition1 </li></ul><ul><li>: </li></ul><ul><li>Case condition2 </li></ul><ul><li>: </li></ul><ul><li>Case Else </li></ul><ul><li>: </li></ul><ul><li>End Select </li></ul>Example Select Case name Case &quot;&quot; MsgBox(&quot;Empty&quot;) Case &quot;Me&quot; MsgBox(&quot;me&quot;) Case Else MsgBox(name) End Select
  27. 27. Select Case Conditions <ul><li>Case &quot;red&quot;, &quot;white&quot;, &quot;green&quot; ' A few together . </li></ul><ul><li>Case 1 To 10 ' A range using </li></ul><ul><li> ' keyword To . </li></ul><ul><li>Case Is > 9 ' A range using </li></ul><ul><li> ' keyword Is . </li></ul>
  28. 28. Java <ul><li>if (condition) { </li></ul><ul><li>: </li></ul><ul><li>} else if (condition 2) { </li></ul><ul><li>} else { </li></ul><ul><li>: </li></ul><ul><li>} </li></ul>switch variable { case 1: : break; case 2: : break; default: : }
  29. 29. End of lessons

×