Visual Basic How to Display Date in Textbox
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS
Contact US
Thanks. We have received your request and will respond promptly.
Log In
Come Join Us!
Are you a
Computer / IT professional?
Join Tek-Tips Forums!
- Talk With Other Members
- Be Notified Of Responses
To Your Posts - Keyword Search
- One-Click Access To Your
Favorite Forums - Automated Signatures
On Your Posts - Best Of All, It's Free!
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.
Posting Guidelines
Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Students Click Here
Date in the MaskedTextBox
- Forum
- Search
- FAQs
- Links
- MVPs
Date in the MaskedTextBoxDate in the MaskedTextBox(OP) Colleagues, I tried to display a date in the MaskedTextBox control, with the mask "00/00/0000". RE: Date in the MaskedTextBoxHi, Do you mean that you could not enter from the keyboard... Skip, RE: Date in the MaskedTextBoxSeems to me that at some point before it hits the masked textbox, VB is seeing 03292020 as a number, not a string, and thus stripping off the leading 0, son perhaps you can show us how you are populating the masked textbox RE: Date in the MaskedTextBox(OP) Good day colleagues! CODE --> vb'==================================================================================================================================== Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load '==================================================================================================================================== ' Purpose : Initializes the default values for data entry boxes. ' Description : Calculates the values for the Check, Period Begins and Period Ends dates, assigns app's start dir as a working dir. ' Side effects : None. ' Notes : 1. Company- and application-specific. ' 2. Complies with .NET Framework ver. 1.1 and higher. '==================================================================================================================================== pcStartDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) pcStartDir = CharTran(pcStartDir, "bin\Debug", "", 0) & "\" Dim ldChkDate As Date = GetNextFridayDate(Today), _ ldPerEnd As Date = ldChkDate.AddDays(-6), _ ldPerBeg As Date = ldPerEnd.AddDays(-13) Me.txtSrcXMLs.Text = pcStartDir Me.txtClientID.Text = "TEST_CLIENT" Me.txtRunID.Text = "PO007010800000614A" Me.txtChkDate.Text = ldChkDate Me.txtMaskedPerBeg.Text = New DateTime(2020, 1, 1) ' ldPerBeg Me.txtChkPeriodStart.Text = ldPerBeg Me.txtChkPeriodEnd.Text = ldPerEnd End Sub '==================================================================================================================================== Here's how the form looks after loading: AHVBGA! RE: Date in the MaskedTextBoxWith Mask 00/00/0000 CODEMe.txtMaskedPerBeg.Text = Format(New DateTime(2020, 1, 1), "MM/dd/yyyy") gives me: (upper / lower case in Format makes a difference...) ---- Andy There is a great need for a sarcasm font. RE: Date in the MaskedTextBoxNeed to see code behind GetNextFridayDate RE: Date in the MaskedTextBox(OP) To strongman: per your request CODE --> vb'=================================================================================================================================== Public Function GetNextFridayDate(ByVal tdDate As Date) As Date '=================================================================================================================================== ' Purpose : Calculates the date of the next Friday. ' Description : . ' Parameters : Date as Date - mandatory. ' Returns : Next Friday's date as Date. ' Side effects : None. ' Notes : 1. Generic, complies with .NET Framework ver. 1.1 and higher. ' 2. If the tdDate parameter is blank - today's date is assumed. '=================================================================================================================================== ' Parameter's validation If IsNothing(tdDate) Then tdDate = Today Else If Not IsDate(tdDate) Then tdDate = Today End If 'Not IsDate(tdDate) End If 'IsNothing(tdDate) ' Declare and initialize the needed local memvar Dim ldFriday As Date = tdDate ' Calculate the date of the closest next Friday Do While ldFriday.DayOfWeek < DayOfWeek.Friday ldFriday = ldFriday.AddDays(1) Loop Return ldFriday End Function '=================================================================================================================================== Albeit I can't imagine what you need it for - care to explain? To Andrzejek: this works, RE: Date in the MaskedTextBoxWhat I and Andy and strongm were trying to get to was that you need a TEXT value to be entered into your masked textbox not a NUMERIC value. Two totally different animals. Skip, RE: Date in the MaskedTextBoxIn your GetNextFridayDate, do you really need Parameter's validation since you accept tdDate As Date? CODEDim dtMyDate As Date dtMyDate = Nothing Debug.Print(Format(dtMyDate, "MM/dd/yyyy hh:mm:ss")) gives you: 01/01/0001 at midnight, still a 'valid' date ---- Andy There is a great need for a sarcasm font. RE: Date in the MaskedTextBox(OP) To Andrzejek: old habit, colleague, old habit. HANW everybody! Red Flag SubmittedThank you for helping keep Tek-Tips Forums free from inappropriate posts. |
Join | Advertise
Copyright © 1998-2021 engineering.com, Inc. All rights reserved.
Unauthorized reproduction or linking forbidden without expressed written permission. Registration on or use of this site constitutes acceptance of our Privacy Policy.
Join Tek-Tips® Today!
Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.
Here's Why Members Love Tek-Tips Forums:
-
Talk To Other Members - Notification Of Responses To Questions
- Favorite Forums One Click Access
- Keyword Search Of All Posts, And More...
Register now while it's still free!
Already a member? Close this window and log in.
Join Us Close
Visual Basic How to Display Date in Textbox
Source: https://www.tek-tips.com/viewthread.cfm?qid=1802217
Just traded in my OLD subtlety...
0 Response to "Visual Basic How to Display Date in Textbox"
Post a Comment