VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



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

by William McKown (1 Submission)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 5.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

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.

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

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

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

Download this snippet    Add to My Saved Code

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

No comments have been posted about When Key Press =,+, is pushed in textbox puts currentdate, adds 1 day, subtracts 1 day. Why not be the first to post a comment about When Key Press =,+, is pushed in textbox puts currentdate, adds 1 day, subtracts 1 day.

Post your comment

Subject:
Message:
0/1000 characters