Selasa, 10 Maret 2015

Fungsi Membuat Kode Otomatis

  1.  Public SQL As String
  2.  Public Proses As New ClassKoneksi
  3.  Public databelicash As DataTable
  4.  
  5.     Sub buatKode()
  6.         databelicash = Proses.ExecuteQuery("SELECT cash_kode FROM beli_cash ORDER BY cash_kode DESC")
  7.         If databelicash.Rows.Count = 0 Then
  8.             txtKodeCash.Text = "CS0001"
  9.         Else
  10.             With databelicash.Rows(0)
  11.                 txtKodeCash.Text = .Item("cash_kode")
  12.                 txtKodeCash.Focus()
  13.  
  14.             End With
  15.             txtKodeCash.Text = Val(Microsoft.VisualBasic.Mid(txtKodeCash.Text34)) + 1
  16.             If Len(txtKodeCash.Text) = 1 Then
  17.                 txtKodeCash.Text = "CS000" & txtKodeCash.Text & ""
  18.             ElseIf Len(txtKodeCash.Text) = 2 Then
  19.                 txtKodeCash.Text = "CS00" & txtKodeCash.Text & ""
  20.             ElseIf Len(txtKodeCash.Text) = 3 Then
  21.                 txtKodeCash.Text = "CS0" & txtKodeCash.Text & ""
  22.             ElseIf Len(txtKodeCash.Text) = 4 Then
  23.                 txtKodeCash.Text = "CS" & txtKodeCash.Text & ""
  24.             End If
  25.         End If
  26.     End Sub

Tidak ada komentar:

Posting Komentar