Private Sub cmdConvertDate_Click() Dim strYear As String Dim intSlash As Integer If IsDate(txtDate) or txtDate = "2/29/00" Then '最初の日付の区切り文字を検索します。 intSlash = InStr(txtDate, "/") If intSlash > 0 Then '2 番目の日付区切り文字を検索します。 intSlash = InStr(intSlash + 1, txtDate, "/") If intSlash > 0 Then '日付から西暦を抽出します。 strYear = Mid(txtDate, intSlash + 1) If Len(strYear) = 2 Then If CInt(strYear) < 50 Then ' 50 未満の場合、年は 2000 年代になります。 strYear = "20" & strYear Else '50 以上の場合、年は 1900 年代になります。 strYear = "19" & strYear End If End If MsgBox "入力した日付 : " & txtDate MsgBox "西暦 (ここでのルール): " & strYear MsgBox "西暦 (VB のデフォルト値): " & Year(txtDate) Else MsgBox "日付は予期した形式ではありません!" End If Else MsgBox "日付は予期した形式ではありません!" End If Else MsgBox "有効な日付ではありません!" End If 'txtDate の日付を明確にします。 txtDate.Text = Left(txtDate.Text, intSlash) & strYear End
Sub