Results 1 to 8 of 8

Thread: [RESOLVED] calculating dates

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2007
    Posts
    108

    Resolved [RESOLVED] calculating dates

    Dear Friends,

    i am using Vb 6

    and i have 2 text box on a form and both are dates

    and the code is :

    Code:
    Public date1 As Date
    Public date2 As Date
    
    Private Sub Form_Load()
    
    
    Text1.Text = Format(Date, "dd-mmm-yy")
    Text2.Text = Format(Date + 2, "dd-mmm-yy")
    
    End Sub
    
    Private Sub Text1_LostFocus()
    date2 = Format(date1, "dd-mmm-yy") + 2
    Text2.Text = date2
       
    End Sub

    actully what i want is, that IF Text1Box change the date Text2Box should add 1 day into it!

    thanks

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: calculating dates

    Convert the date in Text1 by using the CDate function (i.e., date2=CDate(Text1.Text). Then add 2 to that. Note: CDate will fail if the data in text1 is not a valid date format.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: calculating dates

    Use a datepicker control instead of a textbox

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2007
    Posts
    108

    Re: calculating dates

    thanks
    how?? datepicker

    can u pls upload any sample file?

    regards,

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: calculating dates

    Quote Originally Posted by skaswani
    actully what i want is, that IF Text1Box change the date Text2Box should add 1 day into it!

    thanks
    This is one way of doing it...

    vb Code:
    1. Private Sub Text1_AfterUpdate()
    2.     Dim TEMP As String
    3.     TEMP = Format(Text1.Text, "dd-mmm-yy")
    4.     Text2.Text = Format((Val(Left(TEMP, 2)) + 1), "00") & Mid(TEMP, 3, Len(TEMP) - 2)
    5. End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Oct 2007
    Posts
    108

    Re: calculating dates

    thank you dears
    but i think its really better to use date picker..
    can anyone upload sample file

    thanks

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: calculating dates

    They are simple, you shouldn't need a sample file - you should be able to do what you need from the article What controls can I use to input a date/time? from our Classic VB FAQs (in the FAQ forum, which is shown near the top of our home page)

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Oct 2007
    Posts
    108

    Re: calculating dates

    thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width