Pertemuan 3
Pengaturan Dasar aplikasi & Penggunaan Variabel Menggunakan VB.NET,
Hallo, jumpa lagi dengan saya... J
Di postingan kali ini saya memberikan contoh dari 2 judul di atas..
1. aplikasi diatas akan menghasilkan output yang berasal dari input dan di tambah hello saan di tekan tombol show greeting
di bawah ini codingnya
Public Class Form1
Private Sub btnShowGreeting_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowGreeting.Click
lblGreeting.Text = "Hello " & txtUserName.Text
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Form2.Show()
Me.Hide()
Form2.Focus()
End Sub
End Class
Private Sub btnShowGreeting_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowGreeting.Click
lblGreeting.Text = "Hello " & txtUserName.Text
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Form2.Show()
Me.Hide()
Form2.Focus()
End Sub
End Class
2. Selanjutnya aplikasi untuk menunjukan tanggal dari inputan yang telah dimasukan dan dengan menggunakan focus method dan tab order jika menggunakan focus method maka si kursor akan langsung mengarah ke arah yang yang sudah di deklarasikan dahulu
contoh : focus pada textbox "enter the year" maka saat pertama masuk maka kursor akan berada pada textbox "enter the year" dahulu
untuk codingnya
Public Class Form2
Private Sub btnShowDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowDate.Click
lblDateString.Text = txtDayOfWeek.Text & ", " & txtMonth.Text & " " & txtDayOfMonth.Text & ", " & txtYear.Text
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtDayOfWeek.Clear()
txtMonth.Clear()
txtDayOfMonth.Clear()
txtYear.Clear()
lblDateString.Text = String.Empty
txtDayOfWeek.Focus()
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
Form3.Show()
Form3.Focus()
End Sub
End Class
Private Sub btnShowDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowDate.Click
lblDateString.Text = txtDayOfWeek.Text & ", " & txtMonth.Text & " " & txtDayOfMonth.Text & ", " & txtYear.Text
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtDayOfWeek.Clear()
txtMonth.Clear()
txtDayOfMonth.Clear()
txtYear.Clear()
lblDateString.Text = String.Empty
txtDayOfWeek.Focus()
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
Form3.Show()
Form3.Focus()
End Sub
End Class
Setting Access Keys
1. Select the Show Date button (btnShowDate) and change its text to read Show &Date. This assigns a+D as the button’s access key.
2. Select the Clear button (btnClear) and change its text to read Clea&r. This assigns a+R as the button’s access key.
3. Select the Exit button (btnExit) and change its text to read E&xit. This assigns alt+X as the button’s access key.
4. Select the form, and then select the AcceptButton property in the Properties window. Click the downarrow button ( ) to display the drop-down list of buttons. Select btnShowDate from the list.
5. With the form still selected, select the CancelButton property in the Properties window. Click the down-arrow button ( ) to display the drop-down list of buttons. Select btnExit from the list.
Penggunaan variabel
Deklarasi Variabel
Variabel yakni objek yang dapat menerima pemasukan nilai-nilai tertentu. Dalam bahasa pemrograman fungsi variabel penting sekali untuk menampung nilai dan mengalokasikan untuk keperluan tertentu.
Di Visual Basic .NET cara untuk mendeklarasikan variabel sangat mudah, yakni dengan menggunakan perintah Dim. Contoh mendeklarasikan variabel di Visual Basic .NET yaitu:
Dim NamaVariabel As tipe data
Contoh:
Dim Nama As String
Dim Jurusan As String
Dim Nilai As String
Pemberian Nilai pada Variabel
Nama ="Ahmad Ali"
Jurusan ="Sistem Informasi"
Nilai1 =100
Kata Dim yakni kata yang digunakan untuk mendeklarasikan nama variabel. Ketika perintah Dim dieksekusi oleh compiler maka perintah Dim tersebut meminta tempat di memori untuk menyimpan data-data yang akan dialokasikan pada variabel tersebut.
Variabel Lokal dan Variabel Member
Variabel Lokal yakni variabel yang dideklarasikan didalam prosedur atau event. Sementara variabel member yakni tipe data dari Visual Basic. Artinya variabel ini dideklarasikan pada level modul, didalam sebuah class, struktur atau modul. Akan tetapi, tidak dideklarasikan didalam prosedur yang terdapat didalamnya. Perbedaan variabel lokal dan member yaitu:
"Variabel loakal hanya berlaku didalam prosedur saja atau tidak bisa diakses diluar prosedur. Sementara variabel member berlaku di semua prosedur"
Tipe Data
Tipe data dalam bahasa pemrograman yang menjelaskan bahwa apa jenis data yang dapat ditampung variabel. Ketika kita mendeklarasikan variabel, kita harus memberitahu kompiler mengenai jenis data variabel yang dapat ditampung variabel.
penamaan variabel
contoh aplikasi
Public Class Form3
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtFirstName.Clear()
txtLastName.Clear()
lblFullName.Text = String.Empty
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowName.Click
Dim strFullName As String
strFullName = txtFirstName.Text & " " & txtLastName.Text
lblFullName.text = strFullName
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtFirstName.Clear()
txtLastName.Clear()
lblFullName.Text = String.Empty
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowName.Click
Dim strFullName As String
strFullName = txtFirstName.Text & " " & txtLastName.Text
lblFullName.text = strFullName
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
Calculation
Contoh aplikasi
Public Class Form4
Dim intA As Integer
Dim intB As Integer
Dim intC As Integer
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Number.Click
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles btnClear.Click
tbA.Text = String.Empty
tbB.Text = String.Empty
tbOperasi.Text = String.Empty
lblResult.Text = String.Empty
End Sub
Private Sub Form4_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnTambah.Click
intA = tbA.Text
intB = tbB.Text
intC = intA + intB
lblResult.Text = intC
tbOperasi.Text = btnTambah.Text
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btnKurang.Click
intA = tbA.Text
intB = tbB.Text
intC = intA - intB
lblResult.Text = intC
tbOperasi.Text = btnTambah.Text
End Sub
Private Sub btnKali_Click(sender As Object, e As EventArgs) Handles btnKali.Click
intA = tbA.Text
intB = tbB.Text
intC = intA * intB
lblResult.Text = intC
tbOperasi.Text = btnTambah.Text
End Sub
Private Sub btnAkar_Click(sender As Object, e As EventArgs) Handles btnAkar.Click
intA = tbA.Text
intB = tbB.Text
intC = intA ^ intB
lblResult.Text = intC
tbOperasi.Text = btnTambah.Text
End Sub
Private Sub btnBagiint_Click(sender As Object, e As EventArgs) Handles btnBagiint.Click
intA = tbA.Text
intB = tbB.Text
intC = intA / intB
lblResult.Text = intC
tbOperasi.Text = btnTambah.Text
End Sub
Private Sub btnBagifloat_Click(sender As Object, e As EventArgs) Handles btnBagifloat.Click
intA = tbA.Text
intB = tbB.Text
intC = intA \ intB
lblResult.Text = intC
tbOperasi.Text = btnTambah.Text
End Sub
Private Sub btnMod_Click(sender As Object, e As EventArgs) Handles btnMod.Click
intA = tbA.Text
intB = tbB.Text
intC = intA Mod intB
lblResult.Text = intC
tbOperasi.Text = btnTambah.Text
End Sub
End Class
Dim intA As Integer
Dim intB As Integer
Dim intC As Integer
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Number.Click
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles btnClear.Click
tbA.Text = String.Empty
tbB.Text = String.Empty
tbOperasi.Text = String.Empty
lblResult.Text = String.Empty
End Sub
Private Sub Form4_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnTambah.Click
intA = tbA.Text
intB = tbB.Text
intC = intA + intB
lblResult.Text = intC
tbOperasi.Text = btnTambah.Text
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btnKurang.Click
intA = tbA.Text
intB = tbB.Text
intC = intA - intB
lblResult.Text = intC
tbOperasi.Text = btnTambah.Text
End Sub
Private Sub btnKali_Click(sender As Object, e As EventArgs) Handles btnKali.Click
intA = tbA.Text
intB = tbB.Text
intC = intA * intB
lblResult.Text = intC
tbOperasi.Text = btnTambah.Text
End Sub
Private Sub btnAkar_Click(sender As Object, e As EventArgs) Handles btnAkar.Click
intA = tbA.Text
intB = tbB.Text
intC = intA ^ intB
lblResult.Text = intC
tbOperasi.Text = btnTambah.Text
End Sub
Private Sub btnBagiint_Click(sender As Object, e As EventArgs) Handles btnBagiint.Click
intA = tbA.Text
intB = tbB.Text
intC = intA / intB
lblResult.Text = intC
tbOperasi.Text = btnTambah.Text
End Sub
Private Sub btnBagifloat_Click(sender As Object, e As EventArgs) Handles btnBagifloat.Click
intA = tbA.Text
intB = tbB.Text
intC = intA \ intB
lblResult.Text = intC
tbOperasi.Text = btnTambah.Text
End Sub
Private Sub btnMod_Click(sender As Object, e As EventArgs) Handles btnMod.Click
intA = tbA.Text
intB = tbB.Text
intC = intA Mod intB
lblResult.Text = intC
tbOperasi.Text = btnTambah.Text
End Sub
End Class
format penomoran
waktu & tanggal
Metode konversi
Sekian dulu untuk postingan kali ini trimakasih..
Comments
Post a Comment