Home VB.NET 1 VB.NET 2 VB.NET 3 VB.NET 4 VB.NET 5 VB.NET 6 VB.NET 7 VB.NET 8 VB.NET 9 VB.NET 10 VB.NET 11 VB.NET 12 VB.NET 13 VB.NET 14 VB.NET 15 VB.NET 16 VB.NET 17 About

VB.NET 3

Code, Design and Applications


THEORY OF PROCEDURES: FUNCTIONS AND SUBROUTINES

There are two kinds of procedures: functions and subroutines (sometimes called subs). A function returns a value to the procedure that called it, whereas a sub simply executes code.

When you say SUB, it contains all your secret commands for the computer to interpret it later ALL AT ONCE.

Sub MyFirstSub()

   'CODE HERE ALL AT ONCE

End Sub

Calling Functions: Call MyFirstFunction()

At Functions, there's a return value e.g. TRUE OR FALSE, STRING OR INTEGER

Function MyFirstFunction() As Integer

  'if false return 0

  Dim Satisfy As Integer

  If Satisfy = 1 Then

    'CODE HERE FOR SATISTY

    Return 1

    Exit Function

  End If

  'CODE HERE FOR FALSE SATISFY

  Return 0 'at the end return 1

  End Function

Real Programming Application of sample 1

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

  Call PlaySound("Startup.wav", 1)

End Sub

Sub PlaySound(ByVal SoundFile As String, ByVal Volume As Integer)

  My.Computer.Audio.Play(SoundFile, Volume)

End Sub

Sample 2: Adding Two Numbers Function

First, you need to declare the variable as any datatype and then connect it to textboxes for input.

Function AddTwoNumbers(ByVal N1 As Integer, ByVal N2 As Integer) As Integer

  Return N1 + N2

End Function

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

  Dim aNumber As Integer = CInt(Textbox1.Text)

  Dim bNumber As Integer = CInt(Textbox2.Text)

  MessageBox.Show(AddTwoNumbers(aNumber, bNumber))

End Sub


FAMOUS DATA TYPES

String means any group of characters e.g. "My Name"

Integer 1 or 0 logic and no decimal e.g. 0-10,000

Boolean False or True Logic

Single Any number with decimal places

Double Double digit with Single DataType


RADIO BUTTON CONTROL

Drag and Drop the Radio Button and Button Control to the Form and Double Click the Button After configuring the Text at the Properties Window.

If RadioButton3.Checked = True Then

MsgBox("You chose a thin crust")

End If


PICTURE BOX SAMPLE CODE

PictureBox1.ImageLocation = "C:\ShellCities\Electronics Desktop\search.png"

PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage


MAKING YOUR PROGRAM REPEAT ACTIONS: FOR NEXT LOOP

The For...Next loop allows you to specify a number, and then repeat code contained within that loop for the specified number of times.

Dim i As Integer = 0

Dim NumberOfRepetitions As Integer = CInt(TextBox1.Text)

For i = 1 To NumberOfRepetitions

MessageBox.Show("This line has been repeated " & i & " times")

Next