Fungsi Cek Koma dengan VB.Net

Pelajaran pertama tentang bikin fungsi dari mas Hendra. Ini fungsi udah dibikin sekitar 6 bulan yg lalu baru pengen aq publish sekarang hehehe…

Okeh deh ini source code functionnya :

 Public Function cek_koma(ByVal stringku As String) As Boolean
 Dim panjang As Integer = 0
 Dim jumlah As Integer = 0
 Dim cetak1 As Boolean = True
 Dim cetak2 As Boolean = True
 Dim cetak3 As Boolean = False
 Dim cetak4 As Boolean = False
 Dim i As Integer = 0

 panjang = Len(stringku)

 If stringku(0) = "0" And stringku(1) <> "," Then
 cetak1 = False
 Else
 cetak1 = True
 End If

 For i = 0 To panjang - 1
 If stringku(0) = "," Then
 cetak2 = False
 Else
 cetak2 = True
 End If
 Next
 For i = 0 To panjang - 1
 If stringku(i) = "," Then
 jumlah += 1
 End If
 Next
 If jumlah < 2 Then
 cetak3 = True
 Else
 cetak3 = False
 End If
 If cetak1 = True And cetak2 = True And cetak3 = True Then
 cetak4 = True
 Else
 cetak4 = False
 End If
 Return cetak4
 End Function&#91;/sourcecode&#93;

<span id="more-241"></span>

Tinggal kita pasang aja dihalaman web kayak gini nih :

<a href="https://ayusa.files.wordpress.com/2008/11/koma.jpg"><img class="alignnone size-full wp-image-246" title="koma" src="https://ayusa.files.wordpress.com/2008/11/koma.jpg" alt="koma" width="359" height="235" /></a>

Dan jangan lupa masukkan source codenya di button_click

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim MyFunction As MyFunction = New MyFunction
        If MyFunction.cek_koma(Me.TextBox1.Text) = False Then
            MsgBox("Invalid number")
        Else
            MsgBox("Right Number")
        End If
    End Sub

Dan ini hasilnya :koma2

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: