Results 1 to 18 of 18

Thread: DateAdd user inputs the date

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    11

    DateAdd user inputs the date

    DateAdd(DateInterval.Hour, -9, #_ _ :_ _ :_ _ #)

    i want to use the DateAdd function but instead of adding to a specified time, i want the user to input a time(with a text box)

    i am fairly new to this so the solution is probably obvious.

    if you are curious im doing a time zone program(to work out the time in a different time zone)

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: DateAdd user inputs the date

    Welcome to the forums.

    You have stated what you want, but, what is the question?

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    11

    Re: DateAdd user inputs the date

    instead of adding to a specified time how do i use one the user has entered into a textbox (im doing this for school and my teacher isnt good at explaining)

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: DateAdd user inputs the date

    You mean this?
    Code:
    Private Sub Command1_Click()
    Text2.Text = DateAdd("h", Text1.Text, Time)
    End Sub

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    11

    Re: DateAdd user inputs the date

    also ive used a random time to add to(instead of what the user enters), just to see if it works, but its saying compile error:range has no values when i Dim DateAdd(dateInterval.Hour, -9, #9:00:00 PM#)(if thats what im supposed to do)

    any suggestions? am i on the right track?

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    11

    Re: DateAdd user inputs the date

    the user doesnt enter wat they want added to the time, but wat time the hour/s will be added to. they enter the time themselves from which the program will add -9 hours and display the result.

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: DateAdd user inputs the date

    Quote Originally Posted by Charlie94 View Post
    but wat time the hour/s will be added to. they enter the time themselves from which the program will add -9 hours and display the result.
    Ok...so just move the text1.text line to the end instead of in the middle.

  8. #8

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    11

    Re: DateAdd user inputs the date

    tried that

    here is the relevent code:can u tell me whats wrong, why and how to fix it
    Code:
    Dim dteTime As Date
    
    Private Sub cmdTimeDifference_Click()
        lblItaly(CbDate) = DateAdd("h", -9, txtHours)
    End Sub
    
    Private Sub Form_Load()
        txtHours(CbDate) = dteTime
    End Sub
    I get 'runtime error 450'
    Last edited by Hack; Mar 17th, 2009 at 03:36 PM. Reason: Added Code Tags

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: DateAdd user inputs the date

    What is the verbage for the error and what line gets highlighted when it happens?

  10. #10

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    11

    Re: DateAdd user inputs the date

    wrong number of arguments or invalid property assignment

    lblItaly(CbDate) = DateAdd("h", -9, txtHours) gets highlighted

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: DateAdd user inputs the date

    Yeah, I had feeling it was going to be that line, and the wrong number of arguments is coming from this
    Code:
    lblItaly(CbDate)
    First, is lblItaly in a label array?

    Second, if it is, then it is expecting a number, not a built in VB function.

  12. #12

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    11

    Re: DateAdd user inputs the date

    yes to the array, dont know about the second one, i just added (CbDate) cause it stopped another error

  13. #13

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    11

    Re: DateAdd user inputs the date

    also instead of just the time ill use the date too(so if the user enters 1 am it will go back to the previous date)

  14. #14

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    11

    Re: DateAdd user inputs the date

    wait sorry no its not in an array, ive had errors involving arrays though

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

    Re: DateAdd user inputs the date

    1) If you use dateadd and it goes back to the previous day then you need to format it to just grab the time.

    For example

    Code:
    Format(DateAdd("h", -9, Time), "hh:mm:ss")
    blItaly(CbDate) = DateAdd("h", -9, txtHours) gets highlighted
    2) What is the value of "txtHours" and what is the value of "CbDate"
    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

  16. #16

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    11

    Re: DateAdd user inputs the date

    i just added (CbDate) cause it stopped another error

    Private Sub Form_Load()
    txtHours(CbDate) = dteTime
    End Sub

    i put that there so they edit the 12:00:00 AM to their time

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

    Re: DateAdd user inputs the date

    i just added (CbDate) cause it stopped another error
    You just cannot add anything to anything to stop errors

    What Hack initially suggested and I re-emphasized in post 15 is that you need to use it like this

    Code:
    Format(DateAdd("h", -9, Time), "hh:mm:ss")
    If you want to store it in a label then do this

    Code:
    Label1.Caption = Format(DateAdd("h", -9, Time), "hh:mm:ss")
    If you want the user to enter the time then do this

    Code:
    Label1.Caption = Format(DateAdd("h", -9, TxtHours), "hh:mm:ss")
    Ensure that the value of TxtHours is a valid timevalue. For example, the textbox should have a value of 00:00:00 (in the format of hh:mm:ss)
    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

  18. #18

    Thread Starter
    New Member
    Join Date
    Mar 2009
    Posts
    11

    Re: DateAdd user inputs the date

    okay but what if i wanted the user to enter the day of the week and the time. i believe the code is
    "dddd hh:mm am/pm" (not sure abot the am/pm though)

    i want it so the user enters the day and time in that format and then the label shows it in that format

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