1 / 35

Programmeercursus O.O.P. met VISUAL BASIC.NET

Programmeercursus O.O.P. met VISUAL BASIC.NET. Les 2. Frans Vanrillaer & John Evans. VB.NET. C#. VC++.NET. J#.NET. JScript. ……. Common Type System. Client-Side. Server-Side. Mobile-Side. .NET Interne opbouw. .NET Framework. .Net Framework. Base Class Library.

tiara
Download Presentation

Programmeercursus O.O.P. met VISUAL BASIC.NET

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programmeercursus O.O.P.met VISUAL BASIC.NET Les 2 Frans Vanrillaer & John Evans

  2. VB.NET C# VC++.NET J#.NET JScript ……. Common Type System Client-Side Server-Side Mobile-Side .NET Interne opbouw .NET Framework .Net Framework Base Class Library Common Language Runtime Windows COM+ Services Windows 2000 / NT / XP

  3. .NET Framework Base Class Library Enkele belangrijke Namespace’s System System.Collections System.Data System.Drawing System.IO System.Reflection System.Security System.Text System.Threading System.Timers System.Web System.Windows.Forms System.Xml Microsoft.CSharp Microsoft.VisualBasic

  4. We maken het ons gemakkelijk en importeren expliciet de namespace System Imports System Console.WriteLine(" " "Hello VB.NET " " " ) Functie van deze Class Classvan System • Klik ‘F5’ of L-muis klik op: Console Applicatie Automatische Code Noodzakelijk begin Keyword van een Module Naam vd Module Wordt meestal geweizigd ModuleModule1 Start naam SubMain( ) Begin Keyword van een Subroutine End Sub End Module Sluit Subroutine af Sluit Module af

  5. Imports System Module Module1 Sub Main ( ByVal args( ) As String )Dim s As String For Each s In args Console.WriteLine ( s ) Next End Sub End Module Console Applicatie Met Command-Line Argumenten Pas de code als volgt aan : Hoe laat men deze code RUNNEN ?

  6. Les Overzicht • Datatypes • Controle Structuren • Proceduren • Option Strict • Type Conversie • ByVal/ByRef • Meerdere Modules

  7. String • Date • Object Signed Unsigned Floating Point • Short • Integer • Long • Byte • Decimal • Single • Double VB.NET DataTypes Value Type Andere Char Geheel getal Boolean Komma getal Reference Type

  8. Gereserveerde Datatype Initiële waarde Stack plaats Char Byte Short Integer Long Single Double Decimal Boolean Date 0 0 0.0 False 1/1/0001 12:00:00 AM 2 1 2 4 8 4 8 16 1 8 VB.NET DataTypes Detail

  9. VB.NET DataTypes Detail Datatype Max waarde Char Byte Short Integer Long Single Double Decimal Boolean Date +255 +255 +-32.767 +-2.147.483.647 +-9.223.372.036.854.775.808 +-3,41E+38 +-1.80E+308+/-79.228.162.514.264.337.593.543.950.335 True 12/31/2999 11:59:59 PM C S D 1 #

  10. Definiëren Definiëren & Initializeren Dim i, j AsInteger Dim name As String Dim val As Boolean Dim choice AsChar Dim sal AsSingle Dim id As Integer= 10 Dim name As String= "KICIT" Dim val AsBoolean = True Dim choice AsChar= "y" Dim sal AsSingle= 3500.75 Constanten OK? Const m AsInteger= 10 Const pi AsSingle= 3.14 Const n As String= "Hi" Const ch As Char= "y" Dim i = 10, j = 10 AsInteger Dim b AsBoolean=True Dim m, k As Integer= 10 Const k AsInteger VB.NET DataTypes Gebruik Fout Juist Fout Fout

  11. VB.NET DataType: Boolean Nota: Boolean is True of False. True in NIET 1 en False NIET 0 ImportsSystem Module Module1 Sub Main( ) Dim a AsBoolean=True Dim b AsBoolean=False Console.WriteLine ( "A = " & a ) Console.WriteLine ( "Result = " & ( 4 < 3 ) ) Console.ReadLine End Sub End Module A=True Result=False

  12. VB.NET DataTypes: Operatoren • Reken operatoren : +, -, *, /, ^, \, Mod • Relatie operatoren : =, <>, <, >, <=, >= • Logische operatoren • BitwiseAnd, Or, Xor, Not, AndAlso, OrAlso • Samenvoegen : =, +=, -=, /=, *=, \=

  13. Converteren Plaatshouder Plaatshouder Plaatshouder VB.NET Oefening: Console I/O Open een nieuwe console applicatie: console01 Dim n AsString Dim a AsInteger Dim s AsSingle Console.WriteLine ( “Geef naam, leeftijd en salaris " ) n =Console.ReadLine( ) a = CInt ( Console.ReadLine( ) ) s = CSng ( Console.ReadLine( ) ) Console.WriteLine ( _ "Naam: { 0 } Leeftijd: { 1 } Salaris: { 2 }", n, a, s )

  14. Placeholders • Eenvoudige placeholders: {n}, waar n 0,1,2, ….., • Controle op Lengte: {n,w}, w is de breedte. {0,12} of {0,-8}       Positief voor rechts uitlijnen,        Negatief voor links uitlijnen. • Soort value: {n,S}: • S hoe de inhoud getoond moet worden. {0,8:f3} • C,c    Currency formaat (instelling) -afronding • D,d    Decimaal • E,e    Scientific (exponential) • F,f    Fixed point (vb. F2) -afronding • G,g    General (instelling) • N,n    Getal formaat (vb. N1) -afronding • X,x    Hexadecimaal • Breedte en Format string: {n,w:S} CChar CByte CShort CInt CLng CSng CDbl CDec CBool Cdate Cobj CStr Char Byte Short Integer Long Single Double Decimal Boolean Date Object String VB.NET Converteren

  15. VB.NET DataTypes: Beveiliging ? Dim s As Short = 400 Dim s As Short = 32768S Dim s1 As Short = 40 Dim s2 As Short = 3276 Dim a As Integer a = s1 * s2 ?

  16. VB.NET Data Type: Char Het primitive data type Char vertegenwoordigt een individueel karakter. Dim ch1 Aschar= “a”CDim n As Integer=AscW(ch1)n += 1ch1 =ChrW(n) Speciale ascii codes: Constante die staan in Microsoft.VisualBasic namespace Naam Waarde VB naamSingle quote &H27  Double quote &H22  Backslash &H5C  Null &H0 vbNullChar Alert &H7  Backspace &H8 vbBack Form feed &HC vbFormFeedLine feed &HA vbLf Naam Waarde VB naam Carriage return &HD vbCr New Line &HD + &HA VbLfCr of VbNewLineHorizontal tab &H9 vbTab Vertical tab &HB vbVerticalTab

  17. VB.NET String class is een OBJECT dat eenmaal het gecreëerd is, NIET meer kan verandert worden. Elke verandering creëert een NIEUW string-object !!! String Methods en Properties Individuele karakters uit een string kunnenvia Chars(index) benaderd worden. String.LengthString.ToUpperString.ToLower String.Substring() String.IndexOf()String.Chars() Dim str As String = "goodbye“str = str.ToUpper() str = str.ToLower() Dim l As Integer = str.LengthDim substring As String = str.Substring(4, 3)Dim n1 As Integer = str.IndexOf("bye") Dim n2 As Integer = str.IndexOf("boo")Dim s As Integer = Asc(str.Chars(2))

  18. VB.NET StringBuilder class Imports System.Text.StringBuilder 'StringBuilder Dim myBuilder As Text.StringBuilder = New Text.StringBuilder(10000) Dim rng As Random = New Random Dim bgB As Double = Now.Ticks For i As Integer = 1 To 10000 Dim c As Char = Convert.ToChar(rng.Next(65, 90)) myBuilder.Append(c) Next Dim edB As Double = Now.Ticks Disp("Ticks bij stringBuider: " + Convert.ToString(edB - bgB))

  19. VB.NET Stuctured Data Types Array Enumertion Dim balance(4) As Decimal balance(0) = 100 balance(4) = 250 Dim balance() As Decimal = _ {100, 200, 300, 400, 250} Dim balance(,) As Decimal = _ {{100, 200, 300, 400, 250} , _ {100, 200, 300, 400, 250} , _ {100, 200, 300, 400, 250} } Enum Kaarten Aas = 1 Twee = 2 ….. Boer = 11 Dame = 12 Heer = 13 End Enum Structure Structure Persoon Naam As String Vnaam As String Gdat As Date End Structure

  20. VB.NET Voorbeeld Module Module1 Enum PColor rood groen blauw End Enum Structure PiCoord Public x As Single Public y As Single Public flags() As Byte Public color As PColor End Structure Structure Rectangle Public tLeft As PCoord Public tRight As PCoord Public bLeft As PCoord Public bRight As PCoord Public fillColor As PColor End Structure Sub Main() Dim r As Rectangle r.tLeft.x = 100 r.tLeft.y = 100 r.tLeft.color = PColor.groen r.tRight.x = 300 r.tRight.y = 100 r.tRight.color = PColor.groen r.bLeft.x = 100 r.bLeft.y = 300 r.bLeft.color = PColor.groen r.bRight.x = 300 r.bRight.y = 300 r.bRight.color = PColor.groen WriteLine(“Waarde r.tLeft.x = {0} ", r.tLeft.x) WriteLine(“Waarde r.tLeft.y = {0} ", r.tLeft.y) WriteLine(“Duw <Enter> =Stop") ReadLine() End Sub End Module

  21. VB.NET Controle Structuren Beslissing Struc. Herhalings Struc. IF Select For While Do If a>b Then blablablabla End If For i = 0 To 100 blablablabla Next Do Until a>b blablablabla Loop Select Case a case 1 blablablabla case Else doedoedoe End Case While a>b blablablabla End While Do blablablabla Loop While a<b

  22. IIF IfConditieThen ... End If IfConditieThen ... Else … End If Dimi AsInteger DimresAsString i=CInt ( Console.ReadLine( )) res= IIf ( iMod2 = 0, "Even", “Oneven" ) Console.WriteLine ( res ) Cond1Cond2 Cond1Cond2 True False True False Evaluated Not Eval. Not Eval. Evaluated IfConditie1Then ... ElseIf Conditie2 … Else … End If VB.NET Beslissings Structuur IF Evaluated Ifage > 18AndAlsono < 11Then … End If Ifage > 18OrAlsono < 11Then … End If

  23. VB.NET Select Case Beslissings Structuur Select Case dagNr Case 0 dag = “Zondag" Case 1 dag = “Mon" Case 2 dag = “Tue" Case 3 dag = “Wed" End Select Select Case id Case 1, 5 To 9 grp = "Grp A" Case 10 To 15 grp = "Grp B" Case 16 grp = "Grp C" End Select Select Case stad Case “Leuven", “Tienen" state = “V-Br" Case “Namur" state = “NM" Case Else state = “Onbekend" End Select

  24. VB.NET Herhalings Structuur For … Next While For i = 0 To 10 Console.WriteLine( i ) Next i = 0 While i <= 10 Console.WriteLine( i ) i = i + 1 End While For i = 10 To 0 Step –1 Console.WriteLine( i ) Next Dim s AsString = "y" While s = "y" … s = Console.ReadLine( ) End While For I AsInteger= 10 To 0 Step –1 Console.WriteLine( i ) Next

  25. VB.NET Herhalings Structuur Do … Loop i = 0 Do While i <= 10 Console.WriteLine( i ) i += 1 Loop i = 15 Do Until i = 10 Console.WriteLine( i ) i = i + 1 Loop i = 10 Do Console.WriteLine ( i ) i -= 1 Loop While i <= 2 i = 15 Do Console.WriteLine( i ) i = i + 1 Loop Until i = 10

  26. VB.NET Herhalings Structuren Vroegtijdig Verlaten DO While For i = 0 Do While i <= 10 C.W ( i ) If i = 5 then Exit Do End If i = i + 1 Loop While i <= 10 C.W ( i ) If i = 5 then Exit While End If i = i + 1 End While For i = 0 To 10 C.W ( i ) If i = 5 then Exit For End If Next

  27. VB.NET Procedures Subroutine Function Sub Display( ) C.W ( "1.Add" ) C.W ( "2.Del" ) C.W ( "3.Disp" ) C.W ( "4.Exit" ) End Sub Function fact ( val As Integer ) As Integer Dim f As Integer = 1 Dim i As Integer For i = 1 To val f = f * i Next Return f End Function Geeft NIETS terug Geeft waarde terug

  28. VB.NET Option Strict default Beter Option Strict Off Option strict On Voorkomt RunTime fouten! Option Strict Off Dim i As Integer = 10 Dim f As Single Dim g As Single = 6.82 f = i Console.WriteLine ( f ) i = g Console.WriteLine ( i ) Wat indien Strict On ?

  29. VB.NET default Call ByVal ByRef Module Module1 Sub Main() Dim num As Integer = 1 funcv(num) controle.WriteLine(“num = {0}”, num) funcr(num) controle.WriteLine(“num = {0}”, num) End Sub Sub funcv(num As Integer) num += 10 Controle.WriteLine( _ “num = {0}”, num) End Sub Sub funcr(ByRef num As Integer) num += 10 Controle.WriteLine( _ “num = {0}”, num) End Sub

  30. VB.NET Voorbeeld Module Module1 Structure Card Public naam As String Public pcid As Integer End Structure Sub Main() Dim i As Integer = 7, j As Integer = 3 WriteLine(“Waarde i is {0} en j is {1} ", i, j) i = j j = 2 WriteLine(“Nieuw i is {0} en j is {1} ", i, j) Dim c1 As Card, c2 As Card c1.name = "Video card“ c1.pcid = 0 c2.name = "Audio card“ c2.pcid = 6 WriteLine( _ “Waarde c1.naam is {0} en c1.pcid is {1} ", _ c1.naam, c1.pcid) WriteLine( _ “Nieuw c2.naam is {0} an c2.pcid is {1} ", _ c2.naam, c2.pcid) c1 = c2 c2.naam = "Joe“ c2.pcid = 123 WriteLine(“Waarde c1.naam is {0} en c1.pcid is {1} ", _ c1.naam, c1.pcid) WriteLine(“Nieuw c2.naam is {0} en c2.pcid is {1} ", _ c2.naam, c2.pcid) Dim a1() As Integer = {1, 2, 3, 4, 5} Dim a2() As Integer = {6, 7, 8, 9, 0} WriteLine(“Waarde a1(3) is {0} en a2(3) is {1} ", _ a1(3), a2(3)) a1 = a2 a1(3) = -1 WriteLine(“Nieuw a1(3) is {0} en a2(3) is {1} ", _ a1(3), a2(3)) WriteLine(“Duw <Enter> = Stop") ReadLine() End Sub End Module

  31. VB.NET Multiple Modules Scope Module Module1 Dim i As Integer = 20 Sub Main( ) Dim i As Integer = 10 Console.WriteLine ( i ) Console.WriteLine ( Module1.i ) End Sub End Module

  32. VB.NET Oefenen ! MinMax.vb Maak een programma dat voor alle data types, hun min. en max. waarde op het scherm zet. Nota: gebruik de MinValue- en MaxValue propertie WoordGetal.vb Een getal wordt als command lijn argument mee gegeven. Schrijf een programma dat dit getal in woorden toont. Nota: 256 als twee, vijf, zes Oplopend.vb Schrijf een programma dat vier cijfers accepteert en deze dan in oplopende volgorde toont.

  33. VB.NET Oefenen ! SomEven Schrijf een console applicatie, die de som maakt van even getallentussen 1 en 99. Gebruik een For/Next loop. Declareer de variabelen sum en count. Vraagje Met welk statement kan men een While loop verlaten? Tafels Maak een console applicatie, die de tafel van 1 to 5 toont. De tafels staan naast elkaar, netjes geformateerd. Pythagoras Driehoeken Maak een console applicatie, die de afmetingen(zijde1, zijde2, schuineZ)van alle driehoeken toont, die voldoen aan volgende formule: het kwadraat van de schuine zijde is gelijk aan de som van de kwadraten van de 2 andere zijden, bij komende voorwaarde de lengte van de schuine zijde mag niet groter zijn dan 30.

  34. VB.NET Oefening Enigma Deze appl. versleutelt een gegeven woord of zin en ontsleutelt ze. In de gecodeerde string zit de sleutel vervat om hem te decoderen: MIDDENBLOK: het gegeven woord of zin VERHOGINGSFACTOR: de ascicode van elk karakter van het middenblok wordt verhoogd met een randgetal tussen 16 en 35 BLOK1: de gecodeerde string wordt vooraf gegaan door een blok van 10 random karakters indien 5de karakter BLOK1 = X dan zit de verhogingsfactor vervat in de eerste 2 karakters van BLOK1 indien 5de karakter BLOK1 = B dan zit de verhogingsfactor vervat in de eerste 2 karakters van BLOK2 BLOK2: de gecodeerde string wordt achteraf gegaan door een blok van 10 random karakters REVERSE: indien laatste karakter van BLOK2 = ascicode(X) + verhogingsfactor dan MIDDENBLOK is gereversed REVERSE: indien laatste karakter van BLOK2 = ascicode(B) + verhogingsfactor dan MIDDENBLOK is niet gereversed

  35. VB.NET Volgende Les OOP UML Classes Objecten

More Related