型変換

ページ名:型変換

''' <summary>
''' 型変換
''' </summary>
''' <remarks></remarks>
Module mdlTypeConv

    Public Function pf_DoubleToInteger(wp_Double As Double) As Integer
        Dim ret As Integer = 0
        ret = CInt(wp_Double)
        Return ret
    End Function

    Public Function pf_IntegerToDouble(wp_Integer As Integer) As Double
        Dim ret As Double = 0
        ret = CDbl(wp_Integer)
        Return ret
    End Function

    Public Function pf_StringToDate(wp_String As String) As Date
        Dim ret As New Date()
        If IsDate(wp_String) Then
            ret = CDate(wp_String)
        End If
        Return ret
    End Function

    Public Function pf_StringToDouble(wp_String As String) As Double
        Dim ret As Double = 0
        If IsNumeric(wp_String) Then
            ret = CDbl(wp_String)
        End If
        Return ret
    End Function

    Public Function pf_StringToInteger(wp_String As String) As Integer
        Dim ret As Integer = 0
        If IsNumeric(wp_String) Then
            ret = CInt(wp_String)
        End If
        Return ret
    End Function

    Public Function pf_StringToBoolean(wp_String As String) As Boolean
        Dim ret As Boolean = False
        Select Case wp_String
            Case "1"
                ret = True
            Case "-1"
                ret = True
            Case "True"
                ret = True
            Case "TRUE"
                ret = True
            Case Else
        End Select
        Return ret
    End Function

    Public Function pf_TransDate10To8(wp_String As String) As String
        Dim ret As String = ""
        If IsDate(wp_String) Then
            Dim w As Date = CDate(wp_String)
            ret = w.ToString("yyyyMMdd")
        End If
        Return ret
    End Function

    Public Function pf_TransDate8To10(wp_String As String) As String
        Dim ret As String = ""
        If wp_String.Length = 8 Then
            Dim w_DateString As String = String.Format("{0}/{1}/{2}", wp_String.Substring(0, 4), wp_String.Substring(4, 2), wp_String.Substring(6))
            If IsDate(w_DateString) Then
                Dim w As Date = CDate(w_DateString)
                ret = w.ToString("yyyy/MM/dd")
            End If
        End If
        Return ret
    End Function

End Module
 

シェアボタン: このページをSNSに投稿するのに便利です。

コメント

返信元返信をやめる

※ 悪質なユーザーの書き込みは制限します。

最新を表示する

NG表示方式

NGID一覧