0

私はVisualBasicを初めて使用するので、作業中のプログラムについてサポートが必要です。

日、月、年に3つの個別のテキストボックスがあり、数字以外の文字を受け入れるものはありません。次に、コードを作成して、プログラムが現在の日付を毎回チェックし、すでに期限切れの日付を入力した場合、たとえばD:11 M:11 Y:2012を入力した場合に通知するようにします。

誰かがここで私を助けることができますか?

4

1 に答える 1

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 

ドキュメント リンク:

于 2012-11-13T13:58:00.340 に答える