|
-
Jan 12th, 2010, 04:47 PM
#1
Thread Starter
Junior Member
start time/ stop time
I am using VB 2008 and want to record a start date and time and then the stop date and time in a rich text box, i can get the start time into the box but so far can only stop the time instead of 2 seperate times, what i have is a drop down box with a list of computers 1-10 i was trying to get it so you picked a certain computer and that went into the text box then you started the timer and that was recorded, finally you stopped the timer and that was recorded but as i am a total newbie it does not work
here is the code i have.
Public Class Form1
Dim time2 As Date
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = System.DateTime.Now
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
rtxtbox.Text = System.DateTime.Now
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnstart.Click
Timer2.Enabled = True
rtxtbox.Text = rtxtbox.Text
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnend.Click
Timer2.Enabled = False
rtxtbox.Text = rtxtbox.Text
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbocomp.SelectedIndexChanged
rtxtbox.text = rtxtbox.text & cbocomp.selecteditem
End Sub
End Class
-
Jan 12th, 2010, 05:00 PM
#2
Re: start time/ stop time
I'm not sure I know exactly what you're asking for. Are you wanting to figure out how long the individual spent selecting items, or are you asking how to display the time when they began and then display it again when the end?
Also, please use the Code or Highlight tags when posting code.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jan 12th, 2010, 05:05 PM
#3
Re: start time/ stop time
This part is certainly wrong:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnstart.Click
Timer2.Enabled = True
rtxtbox.Text = rtxtbox.Text
End Sub
You are setting the text to the text, which does nothing. I would assume that you wanted to show the current time there, so perhaps this is just a simple typo.
My usual boring signature: Nothing
 
-
Jan 12th, 2010, 05:13 PM
#4
Thread Starter
Junior Member
Re: start time/ stop time
yes that shows how new to it i am normally if i spend enough time playing around i can figure it out but not this time.
what i am trying to do is i pick a computer from the drop down box and it goes into the text box.
2. i press start to record the start time and that goes into the box
3. i press end and that time goes into the box after that i will figure out how to calculate the time used hopefully.
-
Jan 12th, 2010, 05:17 PM
#5
Re: start time/ stop time
So don't you want something like this:
rtxtbox.Text = Date.now.Tostring
That would show the current date and time. It's not ideal, as you would also want to store the start time as a variable when the first button is pressed so that you can compare it to the time at the end. Since you would be putting the time into the textbox, you technically have it stored, but that would mean converting the date into a string to put it in the box, then converting the string back to a date. Not actually an issue, but not particularly efficient (though you would never notice the cost in speed).
My usual boring signature: Nothing
 
-
Jan 12th, 2010, 05:26 PM
#6
Thread Starter
Junior Member
Re: start time/ stop time
that worked i was trying the system date time now, when i try to put them into the text box in order each one just over rides the other meaning i press the computer from my drop down box that goes in then i add my start time that goes in the computer goes out and so on, i added chr (13) after them as i use this for my combo box to add a line break or is that also wrong.
well thxs shaggy your way gave me what i needed i added the code that i had in already and now i can get the computer in the box and the start and stop time the code i used is
rtxtbox.Text = rtxtbox.Text & Date.Now.ToString & Chr(13)
how hard would it be to work out the diff in time if it is really complicated ill leave it ill prob beback soon with another prob.
Last edited by jsssmith; Jan 12th, 2010 at 06:05 PM.
-
Jan 12th, 2010, 06:03 PM
#7
Re: start time/ stop time
rtxtbox.appendtext
Also look at environment.newline and stopwatch and timespan.
-
Jan 12th, 2010, 06:17 PM
#8
Thread Starter
Junior Member
Re: start time/ stop time
where would i put the rtxtbox.appendtext at the moment i have a start time and end time in the text box s othe start time would say 10pm and the end time 11:20pm how would i work that out would i need a seperate code adding.
-
Jan 12th, 2010, 06:50 PM
#9
Re: start time/ stop time
Code:
'an example
rtxtbox.Clear()
rtxtbox.AppendText(DateTime.Now.ToString)
rtxtbox.AppendText(Environment.NewLine)
rtxtbox.AppendText(DateTime.Now.AddMinutes(60).ToString)
rtxtbox.AppendText(Environment.NewLine)
-
Jan 12th, 2010, 07:23 PM
#10
Thread Starter
Junior Member
Re: start time/ stop time
would i add that into the form or the txtbox also how would i go about actually calculating the time diff i need to find the diff say it is 3 hours then i need to calculate a price.
if you know any good tutorial sites that would be helpful ( thats to everybody )
-
Jan 13th, 2010, 10:15 AM
#11
Re: start time/ stop time
Date math isn't difficult, but I deal with it so infrequently that I never remember it (I don't think I have even looked at it for about two years). I seem to remember questions about Date Add, DateAdd, or something like that, popping up every other month or so, so you might just search for one of those.
My usual boring signature: Nothing
 
-
Jan 13th, 2010, 10:50 AM
#12
Re: start time/ stop time
 Originally Posted by dbasnett
Code:
'an example
rtxtbox.Clear()
rtxtbox.AppendText(DateTime.Now.ToString)
rtxtbox.AppendText(Environment.NewLine)
rtxtbox.AppendText(DateTime.Now.AddMinutes(60).ToString)
rtxtbox.AppendText(Environment.NewLine)
You were doing this
rtxtbox.Text = rtxtbox.Text & Date.Now.ToString & Chr(13)
which replaces the contents. I thought you were trying to add text.
Code:
'SAMPLES
'
Dim Future As DateTime = #7/29/2010 9:12:34 AM#
Dim Present As DateTime = DateTime.Now
Dim theDiff As TimeSpan = Future - Present
'timespans do not have years
'theDiff.Days 'the days
'theDiff.Hours 'the hours
'theDiff.Minutes 'the minutes
'theDiff.Seconds 'the seconds
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
|