需要帮助Visual Basic IsDate(),欧洲日期(dd / mm / yyyy)格式函数

时间:2012-11-13 07:13:46

标签: vb.net date datetime vb.net-2010

我是Visual Basic的新手,我需要一些我正在开发的程序的帮助。

我有3个单独的日历,月份和年份文本框,没有人接受任何其他字符然后编号。 现在我想创建一个代码,以便程序每次都检查当前日期并提醒您是否输入了已经过期的日期,例如输入D:11 M:11 Y:2012。

有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

航空代码。

Dim theYear As Integer, theMonth As Integer, theDay As Integer 
' get text from textboxes and convert to numbers 
If Not Int32.TryParse(txtYear.Text, theYear) Then 
  MsgBox "Please enter a valid year!"
  Exit Sub
End If
If Not Int32.TryParse(txtMonth.Text, theMonth) Then 
  MsgBox "Please enter a valid month!"
  Exit Sub
End If
If Not Int32.TryParse(txtDay.Text, theDay) Then 
  MsgBox "Please enter a valid day!"
  Exit Sub
End If  
' combine numbers into a Date 
Dim theDate As Date = Nothing 
Try
  theDate As New Date(theYear, theMonth, theDay) 
Catch e As Exception 
   'year is less than 1 or greater than 9999. 
  '-or- 
  'month is less than 1 or greater than 12. 
  '-or- 
  'day is less than 1 or greater than the number of days in month. 
  MsgBox "Please enter a valid date!"
  Exit Sub
End Try 
 ' check whether date is in the past 
Dim nowDate As Date = DateTime.Now
If DateTime.Compare(theDate, nowDate) < 0 Then
  MsgBox "That date has expired" 
End If 

文档链接: