Search Tools Links Login

When Key Press =,+, - is pushed in textbox puts currentdate, adds 1 day, subtracts 1 day


This code is a input feature that shows how to take a keypress on a textbox and either add, subtract or set current date. + key will add 1 day, - will subtract ond day, and = sets current date. This helps with getting dates from users.

Original Author: William McKown

Assumptions

Just open a new project, add a text box and paste code. Enjoy

Code

Private Sub Form_Load()
Text1 = Date
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
  Case Is = 61
   KeyAscii = 0
   Text1 = Date
  Case Is = 43
   KeyAscii = 0
    If Text1 = "" Then
    Text1 = DateAdd("d", 1, Date)
   Else
    Text1 = DateAdd("d", 1, Text1)
    End If
  Case Is = 45
   KeyAscii = 0
   If Text1 = "" Then
    Text1 = DateAdd("d", -1, Date)
   Else
    Text1 = DateAdd("d", -1, Text1)
   End If
End Select
End Sub

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 105 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.