RSS

Kumpulan Fungsi Manipulasi String Vb.net

Imports MySql.Data.MySqlClient
Imports System.IO

Module modFungsi
    Public result As String
    Public cmd As New MySqlCommand
    Public cmd2 As New MySqlCommand

    Public Sub DeleteFile(namaFile As String)
        Try
            If File.Exists(namaFile) Then
                File.Delete(namaFile)
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Public Sub LogValidasi(Lv As ListView, kode As String, nama As String, err As String)
        Dim ls As New ListViewItem()
        ls.SubItems.Add(kode)
        ls.SubItems.Add(nama)
        ls.SubItems.Add(err)
        Lv.Items.Add(ls)
    End Sub
    Public Sub SimpanValidasi(id As String, kode As String, nama As String, err As String)

        Dim strSql As String
        strSql = "INSERT INTO temp_slik_error SET " & _
                 "temp_id = '" & id & "', temp_kode  = '" & kode & _
                 "', temp_nama = '" & nama & "', temp_error = '" & err & "'"
        Try
            With cmd2
                .Connection = conn
                .CommandTimeout = 0
                .CommandText = strSql

                'execute the data
            End With
            result = cmd2.ExecuteNonQuery

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Function TimeDifCalc(d1 As DateTime, d2 As DateTime)
        d1 = DateTime.Parse(d1)
        d2 = DateTime.Parse(d2)
        Dim difference As TimeSpan = d2 - d1
        'round down total hours to integer'
        Dim hours = Math.Floor(difference.TotalHours)
        Dim minutes = Math.Abs(difference.Minutes)
        Dim seconds = difference.Seconds
        Dim timeleft As String = Format(hours, "00") + " h " + Format(minutes, "00") + " m " + Format(seconds, "00") + " s "
        If Int(seconds) < 0 Then
            timeleft = "00 h 00 m 00 s (Time Out)"
        End If
        Return timeleft

    End Function
    Function LastDayOfMonth(aDate As DateTime) As Date
        Return New DateTime(aDate.Year, _
                            aDate.Month, _
                            DateTime.DaysInMonth(aDate.Year, aDate.Month))
    End Function

    Sub PesanHapus()
        MsgBox("Data telah dihapus", MsgBoxStyle.Information, Application.ProductName)
    End Sub
    Sub PesanSimpan()
        MsgBox("Data telah disimpan", MsgBoxStyle.Information, Application.ProductName)
    End Sub
    Function strReplace(str As String, vOld As String, vNew As String)
        str = str.Replace(vOld, vNew)
        Return str
    End Function
    Function strReplaceKolek(str As String)
        On Error Resume Next
        str = str.Replace("L", "1")
        str = str.Replace("KL", "3")
        str = str.Replace("D", "4")
        str = str.Replace("M", "5")
        Return str
    End Function
    Function strReplaceBadan(str As String)
        On Error Resume Next
        str = str.Replace("PT", "")
        str = str.Replace("KOPERASI", "")
        str = str.Replace("CV", "")
        str = str.Replace("UD", "")
        str = str.Replace(".", "")
        str = str.Replace("-", "")
        Return str
    End Function
    Function strReplaceSlik(str As String)
        On Error Resume Next
        If Len(str) > 0 Then
            str = str.Replace(".", "")
            str = str.Replace(",", "")
            str = str.Replace(":", "")
            str = str.Replace(";", "")
            str = str.Replace("-", "")
            str = str.Replace("/", "")
            str = str.Replace("\", "")
            str = str.Replace("?", "")
            str = str.Replace("+", "")
            str = str.Replace("_", "")
            str = str.Replace("  ", "")
            str = str.Replace("   ", "")
            str = str.Replace("'", "")
            str = str.Replace("*", "")
            str = str.Replace("**", "")
            str = str.Replace("***", "")
            str = str.Replace("****", "")
        End If
        Return str
    End Function
    Function tbPersen(oText As TextBox)
        oText.Text = fDesimal(oText.Text)
        oText.Select(oText.Text.Length, 0)
        Return oText.Text
    End Function
    Function tbRupiah(oText As TextBox)
        oText.Text = fRupiah(oText.Text)
        oText.Select(oText.Text.Length, 0)
        Return oText.Text
    End Function
    Function fDbDesimal(byText As String)
        Dim angka As String
        angka = Replace(byText, ",", ".")
        Return angka
    End Function
    Function fDesimal(byText As Decimal)
        Dim angka As String
        angka = Format(byText, "#,##0.#0")
        Return angka
    End Function
    Function fInteger(ByVal byText As Integer)
        Dim angka As Integer
        angka = Convert.ToInt32(angka)
        Return angka
    End Function
    Function fRupiah(byText As Double)
        Dim angka As String
        angka = Format(byText, "#,##0")
        Return angka
    End Function
    Function fDbRupiah(byText As String)
        Dim angka As String
        angka = Replace(byText, ".", "")
        Return angka
    End Function
    Function FormatTglDb(ByVal byText As Date)
        Dim tanggal As String
        tanggal = Format(byText, "yyyy-MM-dd")
        Return tanggal
    End Function
    Function FormatTgl(byText As Date)
        Dim tanggal As String
        tanggal = Format(byText, "dd-MM-yyyy")
        Return tanggal
    End Function
    Public Sub ClearTB(frm As Form)

        For Each Control In frm.Controls
            If TypeOf Control Is TextBox Then Control.Text = ""
            If TypeOf Control Is ComboBox Then Control.text = ""
            If TypeOf Control Is Date Then Control.value = Now
        Next Control

    End Sub
    Function sLeft(ByVal Str As String, ByVal Len1 As Integer)
        Str = Left(Str, Len1)
        Return Str
    End Function
    Function sMid(ByVal Val As String, ByVal Len As Integer)
        Return Val.Substring(Val.Length / 2 - Len / 2, Len)
    End Function

    Function sRight(ByVal Val As String, ByVal Len As Integer)
        Return Val.Substring(Val.Length - Len, Len)
    End Function
    'Fungsi split string
    'Tanggal : 13-08-2016
    Function SplitText(ByVal text As String, ByVal limiter As String, ByVal ke As Integer)
        On Error Resume Next
        Return Split(text, Trim(limiter))(ke)
    End Function
End Module


  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comments:

Posting Komentar