|
-
Mar 17th, 2009, 01:52 AM
#1
Thread Starter
New Member
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)
-
Mar 17th, 2009, 05:52 AM
#2
Re: DateAdd user inputs the date
Welcome to the forums. 
You have stated what you want, but, what is the question?
-
Mar 17th, 2009, 06:37 AM
#3
Thread Starter
New Member
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)
-
Mar 17th, 2009, 06:43 AM
#4
Re: DateAdd user inputs the date
You mean this?
Code:
Private Sub Command1_Click()
Text2.Text = DateAdd("h", Text1.Text, Time)
End Sub
-
Mar 17th, 2009, 06:46 AM
#5
Thread Starter
New Member
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?
-
Mar 17th, 2009, 06:52 AM
#6
Thread Starter
New Member
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.
-
Mar 17th, 2009, 07:17 AM
#7
Re: DateAdd user inputs the date
 Originally Posted by Charlie94
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.
-
Mar 17th, 2009, 03:17 PM
#8
Thread Starter
New Member
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
-
Mar 17th, 2009, 03:34 PM
#9
Re: DateAdd user inputs the date
What is the verbage for the error and what line gets highlighted when it happens?
-
Mar 17th, 2009, 03:48 PM
#10
Thread Starter
New Member
Re: DateAdd user inputs the date
wrong number of arguments or invalid property assignment
lblItaly(CbDate) = DateAdd("h", -9, txtHours) gets highlighted
-
Mar 17th, 2009, 03:53 PM
#11
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 thisFirst, is lblItaly in a label array?
Second, if it is, then it is expecting a number, not a built in VB function.
-
Mar 17th, 2009, 04:01 PM
#12
Thread Starter
New Member
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
-
Mar 17th, 2009, 04:05 PM
#13
Thread Starter
New Member
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)
-
Mar 17th, 2009, 04:12 PM
#14
Thread Starter
New Member
Re: DateAdd user inputs the date
wait sorry no its not in an array, ive had errors involving arrays though
-
Mar 17th, 2009, 04:13 PM
#15
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
-
Mar 17th, 2009, 04:20 PM
#16
Thread Starter
New Member
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
-
Mar 17th, 2009, 04:28 PM
#17
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
-
Mar 18th, 2009, 12:40 AM
#18
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|