Thursday, December 11, 2008

DATA BINDING

Public Class Form2
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.Container

Private WithEvents textBox1 As System.Windows.Forms.TextBox
Private WithEvents button1 As System.Windows.Forms.Button

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Private Sub InitializeComponent()
Me.textBox1 = New System.Windows.Forms.TextBox()
Me.button1 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'textBox1
'
Me.textBox1.Location = New System.Drawing.Point(48, 56)
Me.textBox1.Name = "textBox1"
Me.textBox1.TabIndex = 0
Me.textBox1.Text = "textBox1"
'
'button1
'
Me.button1.Location = New System.Drawing.Point(56, 96)
Me.button1.Name = "button1"
Me.button1.TabIndex = 1
Me.button1.Text = "button1"
'
'Form2
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.button1, Me.textBox1})
Me.Name = "Form2"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click

Dim sConnection As String = _
"Provider=SQLOLEDB.1;" & _
"Password=sqlpassword;" & _
"Persist Security Info=True;" & _
"User ID=sa;" & _
"Initial Catalog=CD;" & _
"Data Source=(local)"

Dim sSQL As String
sSQL = "SELECT ArtistID, ArtistName From Artist"
Dim objConn _
As New OleDb.OleDbConnection(sConnection)
Dim objDataAdapter _
As New OleDb.OleDbDataAdapter(sSQL, objConn)
Dim objDS _
As New DataSet("Artists")
Dim objDV _
As DataView

Try
objConn.Open()
Catch myException As System.Exception
Windows.Forms.MessageBox.Show(myException.Message)
End Try

If objConn.State = ConnectionState.Open Then
Try
objDataAdapter.Fill(objDS, "Disc")
objConn.Close()
Dim objTable As DataTable
objTable = objDS.Tables("Disc")
objDV = objTable.DefaultView
textBox1.DataBindings.Add("Text", objDV, "ArtistName")
Catch myexception As Exception
Windows.Forms.MessageBox.Show(myException.Message)
End Try
End If

End Sub
End Class

LOWONGAN PEKERJAAN PART TIME JUNIOR IT (BOGOR)

GLOBAL REACH COLLEGE BOGOR sebuah institusi pendidikan internasional membuka
lowongan untuk
posisi Part Time Junior IT Lecturer untuk jurusan Computing dengan persyaratan
sebagai berikut :
- Lulusan / Mahasiswa Tingkat Akhir S1 Jurusan Ilmu Komputer
- Minimal IPK 2.75
- Umur maksimum 24 tahun
- Lebih disukai bila berdomisili di Bogor

Bagi yang berminat dapat mengirimkan CV dan Foto ke nugy@...
sebelum tanggal 21 Desember 2008.

LOWONGAN PEKERJAAN

EXECUTRAIN OF JAKARTA sebuah Lembaga Pelatihan Komputer bertaraf Internasional
membuka lowongan
untuk posisi IT Technical Trainer (Microsoft Certified Trainer) dengan
persyaratan sebagai berikut :
- Lulusan S1 Jurusan Ilmu Komputer
- Minimal IPK 2.75
- Umur maksimum 24 tahun

Para IT Technical Trainer akan dibiayai untuk menempuh ujian sertifikasi
Microsoft seperti :
MCSE (Microsoft Certified System Engineer), MCSD (Microsoft Certified Solution
Developer) atau
MCDBA(Microsoft Certified Database Administrator).
Bagi yang berminat dapat mengirimkan CV dan Foto ke nugy@...
sebelum tanggal 21 Desember 2008.

USING RADIO BUTTON

The radio button is also a very useful control in Visual Basic 2008. However, it operates differently from the check boxes. While the checkboxes work independently and allows the user to select one or more items , radio buttons are mutually exclusive, which means the user can only choose one item only out of a number of choices. Here is an example which allows the users to select one color only.

Example 1:


Dim strColor As String

Private Sub RadioButton8_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton8.CheckedChanged
strColor = "Red"
End Sub

Private Sub RadioButton7_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton7.CheckedChanged
strColor = "Green"
End Sub

Private Sub RadioYellow_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioYellow.CheckedChanged
strColor = "Yellow"
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label2.Text = strColor
End Sub

Although the user may only select one item at a time, he may make more than one selection if those items belong to different categories. For example, the user wish to choose T-shirt size and color, he needs to select one color and one size, which means one selection in each category. This is easily achieved in VB2008 by using the Groupbox control under the containers categories. After inserting the Groupbox into the form, you can proceed to insert the radio buttons into the Groupbox. Only the radio buttons inside the Groupbox are mutually exclusive, they are not mutually exclusive with the radio buttons outside the Groupbox. In Example 18.2, the users can select one color and one size of the T-shirt.

Example 2:


Dim strColor As String
Dim strSize As String

Private Sub RadioButton8_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton8.CheckedChanged
strColor = "Red"
End Sub

Private Sub RadioButton7_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton7.CheckedChanged
strColor = "Green"
End Sub

Private Sub RadioYellow_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioYellow.CheckedChanged
strColor = "Yellow"
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label2.Text = strColor
Label4.Text = strSize
End Sub


Private Sub RadioXL_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioXL.CheckedChanged
strSize = "XL"
End Sub

Private Sub RadioL_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioL.CheckedChanged
strSize = "L"
End Sub

Private Sub RadioM_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioM.CheckedChanged
strSize = "M"
End Sub

Private Sub RadioS_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioS.CheckedChanged
strSize = "S"
End Sub

USING CHECK BOX

The Check box is a very useful control in Visual Basic 2008. It allows the user to select one or more items by checking the checkbox/checkboxes concerned. For example, in the Font dialog box of any Microsoft Text editor like FrontPage, there are many checkboxes under the Effects section such as that shown in the diagram below. The user can choose underline, subscript, small caps, superscript, blink and etc. In Visual Basic, you may create a shopping cart where the user can click on checkboxes that correspond to the items they intend to buy, and the total payment can be computed at the same time as shown in Example.

Private Sub BtnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCalculate.Click
Const LX As Integer = 100
Const BN As Integer = 500
Const SD As Integer = 200
Const HD As Integer = 80
Const HM As Integer = 300
Const AM As Integer = 150
Dim sum As Integer

If CheckBox1.Checked = True Then
sum += LX
End If

If CheckBox2.Checked = True Then
sum += BN
End If

If CheckBox3.Checked = True Then
sum += SD
End If
If CheckBox4.Checked = True Then
sum += HD
End If

If CheckBox5.Checked = True Then
sum += HM
End If

If CheckBox6.Checked = True Then
sum += AM
End If
Label5.Text = sum.ToString("c")



Example2:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Const large As Integer = 10.0
Const medium As Integer = 8
Const small As Integer = 5
Dim sum As Integer

If CheckBox1.Checked = True Then
sum += large
End If

If CheckBox2.Checked = True Then
sum += medium
End If

If CheckBox3.Checked = True Then
sum += small
End If
Label5.Text = sum.ToString("c")

Example3:
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked Then
TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style Or FontStyle.Bold)
Else
TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style And Not FontStyle.Bold)

End If
End Sub

Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
If CheckBox2.Checked Then
TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style Or FontStyle.Italic)
Else
TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style And Not FontStyle.Italic)

End If
End Sub

Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
If CheckBox2.Checked Then
TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style Or FontStyle.Underline)
Else
TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style And Not FontStyle.Underline)

End If
End Sub



* The above program uses the CheckedChanged event to respond to the user selection by checking a particular checkbox, it is similar to the click event. The statement
TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style Or FontStyle.Italic)
will retain the original font type but change it to italic font style.
TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style And Not FontStyle.Italic)
will also retain the original font type but change it to regular font style. (The other statements emply the same logic)

FUNCTIONS PART V - FORMATTING DATE AND TIME

1. Formatting Date and time using predefined formats
Date and time can be formatted using predefined formats and also user-defined formats. The predefined formats of date and time are shown in Table


*) Instead of "General date", you can also use the abbreviated format "G" , i.e. Format (Now, "G"). And for "Long Time", you can use the abbreviated format "T". As for "Short Time", you may use the abbreviated format "t"

Example:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = Format(Now, "General Date")
Label2.Text = Format(Now, "Long Date")
Label3.Text = Format(Now, "short Date")
Label4.Text = Format(Now, "Long Time")
Label5.Text = Format(Now, "Short Time")
End Sub

The output is shown in the diagram below:


2. Formatting Date and time using user-defined formats
Beside using the predefined formats, you can also use the user-defined formatting functions. The general format of a user-defined for date/time is

Format (expression,style)



Example:

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

Label1.Text = Format(Now, "M")
Label2.Text = Format(Now, "MM")
Label3.Text = Format(Now, "MMM")
Label4.Text = Format(Now, "MMMM")
Label5.Text = Format(Now, "dd/MM/yyyy")
Label6.Text = Format(Now, "MMM,d,yyyy")
Label7.Text = Format(Now, "h:mm:ss tt")
Label8.Text = Format(Now, "MM/dd/yyyy h:mm:ss tt")

End Sub

The output is shown in the diagram below:

FUNCTIONS PART IV - FORMATTING FUNCTIONS

The Format function is a very powerful formatting function which can display the numeric values in various forms. There are two types of Format function, one of them is the built-in or predefined format while another one can be defined by the users.

(i) The format of the predefined Format function is

Format (n, “style argument”)

where n is a number and the list of style arguments is given in Table


Example:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button5.Click, Button4.Click, Button3.Click
Label1.Text = Format(8972.234, "General Number")
Label2.Text = Format(8972.2, "Fixed")
Label3.Text = Format(6648972.265, "Standard")
Label4.Text = Format(6648972.265, "Currency")
Label5.Text = Format(0.56324, "Percent")
End Sub

The Output window is shown below:


(ii) The format of the user-defined Format function is

Format (n, “user’s format”)

Although it is known as user-defined format, we still need to follows certain formatting styles. Examples of user-defined formatting style are listed in Table


Example

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button5.Click, Button4.Click, Button3.Click
Label1.Text = Format(8972.234, "0.0")
Label2.Text = Format(8972.2345, "0.00")
Label3.Text = Format(6648972.265, "#,##0.00")
Label4.Text = Format(6648972.265, "$#,##0.00")
Label5.Text = Format(0.56324, "0%")
End Sub

The Output window is shown below: