masyanto

kode otomatis vbnet

Nov 21st, 2020 (edited)
738
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  Public Sub Nomer_SK()
  2.         Try
  3.             conn.Open()
  4.             sstr = "Select * from tblsk where no_sk in (select max(no_sk) from tblsk) "
  5.             cmd = New MySqlCommand(sstr, conn)
  6.             Dim hitung As String
  7.             Dim urutan As String
  8.  
  9.             dr = cmd.ExecuteReader
  10.             dr.Read()
  11.             If Not dr.HasRows Then
  12.                 urutan = "SK/" & Format(Now, "yyMMdd") & "/" & "001" ' jika data belum ada,contohnya (SK/201122/001)
  13.             Else
  14.                 urutan = Microsoft.VisualBasic.Right(dr.GetString(0), 3)
  15.                 If Microsoft.VisualBasic.Left(dr.GetString(0), 10) <> "SK/" & Format(Now, "yyMMdd") & "/" Then ' jika sdh berganti hari menjadi (SK/201123/001)
  16.                     urutan = "SK/" & Format(Now, "yyMMdd") & "/" & "001"
  17.                 Else
  18.                     hitung = Microsoft.VisualBasic.Right(dr.GetString(0), 3) + 1 ' disini "001" + 1
  19.                     urutan = "SK/" & Format(Now, "yyMMdd") & "/" & Microsoft.VisualBasic.Right("00" & hitung, 3)
  20.                 End If
  21.             End If
  22.             conn.Close()
  23.             txtsk.Text = urutan
  24.  
  25.         Catch ex As Exception
  26.             MsgBox(ex.ToString)
  27.         End Try
  28.  
  29.     End Sub
RAW Paste Data