Created by Alia Al-Abdulkarim 2008 Visual Basic Vs. Java

Preview:

Citation preview

Created by Alia Al-Abdulkarim 2008

Visual Basic Vs. Java

Created by Alia Al-Abdulkarim 2008

Variables

Dim a As Double = 3.0

Dim b As Double = 4.0

Created by Alia Al-Abdulkarim 2008

Loops

While Loop

While (i <> limit)

sum += i

i+=1

End While

Created by Alia Al-Abdulkarim 2008

Loops cont.

For Loop

For i = 1 To 5 Step 1

----

----

Next

Created by Alia Al-Abdulkarim 2008

Select Case

Select Case (choice)

Case 1

-----

Case 2

-----

Case 3

-----

Case Else

-----

End Select

Created by Alia Al-Abdulkarim 2008

Visual Basic

Visual Basic Functions and Subs

Scopes

Events

Created by Alia Al-Abdulkarim 2008

Functions and Subs

FunctionPiece of code that is executed upon a function call.

Always returns a value

May receive parameters

SubSame as function, but it doesn’t return a value

Created by Alia Al-Abdulkarim 2008

Functions and Subs cont.

Function function-name (ByVal Para1 As data-type, ……..) As data-type

--------

--------

--------

Return variable

End Function

Created by Alia Al-Abdulkarim 2008

Functions and Subs Cont.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Function function-name (ByVal Para1 As data-type, ……..) As data-type------------------------Return variable

End Function

End Sub

Functions’ Definitions Can Not Be Nested

Created by Alia Al-Abdulkarim 2008

Scopes

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim A As Integer

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

A = 10End Sub

Variable Declaration isn’t visible here

Created by Alia Al-Abdulkarim 2008

Events

When do we use them?Example

• When I want the value in the textbox printed on a label after the button is clicked, I create an Event that reads from the textbox and writes on a label

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim var As String var = TextBox1.Text Label1.Text = var End Sub

Created by Alia Al-Abdulkarim 2008

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim a As Integer = 0

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

TextBox1.Text = a

End Sub

Quiz: What is the Problem?

Variable Declaration isn’t visible here

Recommended