Category Archives: VB.NET

5th Share for Visual Basic

Next application is called comboAPP

This application shows how to use combo box and getting value from it.

Here is the interface view :

here is the source code


Public Class Form1

Private Sub cmbpil_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbpil.SelectedIndexChanged

Select Case cmbpil.SelectedIndex

Case 1 : Label3.Text = cmbpil.SelectedItem

Case 2 : Label3.Text = cmbpil.SelectedItem

Case 3 : Label3.Text = cmbpil.SelectedItem

Case 4 : Label3.Text = cmbpil.SelectedItem

Case 5 : Label3.Text = cmbpil.SelectedItem

End Select

End Sub

End Class

4th Share for Visual Basic

The 4th application

It is called aplikasi4. This application show how to use the check box in Visual Basic

This is the interface view :

here is the source code


Public Class Form1

Private Sub btproses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btproses.Click

If chk1.Checked Then

Label4.Text = "1"

Label5.Text = chk1.Text

ElseIf chk2.Checked Then

Label4.Text = "2"

Label5.Text = chk2.Text

ElseIf chk3.Checked Then

Label4.Text = "3"

Label5.Text = chk3.Text

ElseIf chk4.Checked Then

Label4.Text = "4"

Label5.Text = chk4.Text

End If

End Sub

End Class

3rd Share for Visual Basic

Keep on the third application

In this application I’d like to share you about login application. Here is just the simple one. Which is if username and password is matched with the list (already define before). So, it will show message box that success to login. On the other case, it will show message box that is wrong user name or password

Here is the interface view

here is the source code


Public Class Form1

 

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

txtpass.Text = ""

txtuser.Text = ""

txtpass.Focus()

End Sub

 

Private Sub btcancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btcancel.Click

Dim autentikasi As Boolean

autentikasi = MessageBox.Show("Apakah Anda Yakin Keluar ?", "Informasi", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

If autentikasi = True Then

Close()

Else

 

End If

End Sub

 

Private Sub btlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btlogin.Click

Dim user As String

Dim pass As String

user = "admin"

pass = "administrator"

If (user = txtuser.Text And pass = txtpass.Text) Then

MessageBox.Show("Selamat Anda Berhasil Masuk Sistem", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly)

Else

MessageBox.Show("User Name atau Password Salah", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly)

End If

End Sub

 

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

txtpass.Focus()

End Sub

End Class

2nd Share for Visual Basic

Keep on to second application

It is called Simple calc

In this application, we will learn about getting value and calculate it to be information.

This is the interface view

Here is the source code

</pre>
Public Class Form1

Private val1 As Integer

Private val2 As Integer

Function getVal1() As Integer

val1 = txtVal1.Text

Return val1

End Function

Function getVal2() As Integer

val2 = txtval2.Text

Return val2

End Function

Private Sub btplus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btplus.Click

lblhasil.Text = getVal1() + getVal2()

End Sub

Private Sub btmin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btmin.Click

lblhasil.Text = getVal1() - getVal2()

End Sub

&nbsp;

Private Sub btmulti_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btmulti.Click

lblhasil.Text = getVal1() * getVal2()

End Sub

&nbsp;

Private Sub btper_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btper.Click

lblhasil.Text = getVal1() / getVal2()

End Sub

&nbsp;

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

txtVal1.Text = ""

txtval2.Text = ""

lblhasil.Text = ""

End Sub
<pre>End Class

Starting Again with Visual Basic 2008

Visual Basic is very simple programming language. It can be learned by everyone even though from the beginning. Learning visual basic we only need serious and  patient. If we have already know about algorithm well, god willing it will be faster learning.

For the first time all we need to do is to know about the tool. Here, the tool that we’ll use is Visual Basic 2008 Express Edition. It’s free to use. We only need to download it directly form Microsoft.

Alright, Our first application is called Set_Get_Text. In this application we will learn several components : Button, MessageBox and TextBox and label. In this application we will also learn how to get text from a text box and display it through label or  Textbox even message box.

This is the interface view

this is the source code


Public Class Form1

Public nama

Public Sub getText()

nama = txtnama.Text

End Sub

Private Sub btOke_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btOke.Click

getText()

lblNama.Text = nama

End Sub

Private Sub BtMessage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtMessage.Click

getText()

MessageBox.Show("Isi TextBox = " + nama, "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information)

End Sub

End Class

Making Round Application

This application is an example for accounting in a program. It means that this is our 1st program  that is able to do program as a basic to make more complicated program. In this program you have to prepare :

-Label

Properties :

Text :Radius :

-Label

Properties :

Text :Surface :

-Label

Properties :

Text :Circumference :

-Textbox

Properties :

Name :txtradius:

-Textbox

Properties :

Name :txtsurface

-Textbox

Properties :

Name :txtcircum

-Button

Properties :

Name :btcount

Text :Count

-Button

Properties :

Name :btreset

Text :Reset

Here is the appearance :

Then,  Click twice into btcount , and type source code below :


Public Class Form1

Dim r, surface, circum As Double

Const phi = 3.14

Private Sub btcount_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btcount.Click

r = Val(CDbl(txtradius.Text))

surface = phi * r ^ 2

circum = 2 * phi * r

txtsurface.Text = surface

txtcircum.Text = circum

End Sub

Also type Click twice into btreset, and tpe source code below :


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

txtradius.Text = ""

txtsurface.Text = ""

txtcircum.Text = ""

txtradius.Focus()

End Sub

Now, you’ll need to run your program (press F5)

Making Value Converter Into Letter

  1. Create new  project
  2. Prepare the items :

Label

Properties :

Text :value

 

textbox

Properties :

name :txtvalue

 

button

Properties :

Text :convert

Name:btconvert

 

Label2

  1. Click twice into btconvert ,  Type source code below :

Public Class Form1

Dim a As Integer

Dim b As String

Private Sub btconvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btconvert.Click

a = Val(CInt(txtvalue.Text))

If a > 80 And a <= 100 Then

b = "A"

ElseIf a > 70 And a <= 80 Then

b = "B"

ElseIf a > 60 And a <= 70 Then

b = "C"

ElseIf a > 50 And a <= 60 Then

b = "D"

ElseIf a > 0 And a <= 50 Then

b = "E"

Else

b = "OUT OF RANGE"

End If

Label2.Text = b

End Sub

End Class

4.   Run the program (F5)