-
Make Label Format Time 9:59:59
:wave: Hello. I am doing some work for a visual basic class and needed a little help. We are designing the GUI of a microwave where a user can hit the numeric buttons 0-9 and create the time they want their item to cook. I have everything complete and ready to be submitted, but the only thing left is getting the label that displays the entered time to look like it is in a clock format. :blush:
Right now you enter the digits and it puts them like this: 95959
I am trying to get it to always enter it like this: 9:59:59
Any help with a code would be awesome! Thanks! :thumb:
-
Re: Make Label Format Time 9:59:59
This looks to be a simple issue but your code is required here.
How do you want your time to be set, from left to right or from right to left?
What i mean is:
9:00:00 -> 9:50:00 -> 9:59:00 -> 9:59:50 -> 9:59:59
or
0:00:09 -> 0:00:95 -> 0:09:59 -> 0:95:95 -> 9:59:59
Well, the second variant seems not like a good idea :)
-
Re: Make Label Format Time 9:59:59
What about 24 hour time format?
1:20:20 is not the same as 13:20:20
-
Re: Make Label Format Time 9:59:59
From what I understand he's doing a sample interface for a microwave oven. I doubt anyone would set his microwave for 13+ hours :)
-
Re: Make Label Format Time 9:59:59
Here is my Code:
vb Code:
Option Strict On
Public Class Form1
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
lblYellow.Show()
lblGray.Hide()
lblClock.Hide()
lblTime.Show()
Timer1.Enabled = True
Beep()
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
lblYellow.Hide()
lblGray.Show()
lblClock.Show()
lblTime.Text = ""
lblTime.Hide()
Timer1.Enabled = False
Beep()
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
lblYellow.Hide()
lblGray.Show()
If lblTime.Text > "0" Then
lblClock.Hide()
End If
If lblTime.Text = "DONE" Then
lblTime.Hide()
lblClock.Show()
lblTime.Text = ""
End If
Timer1.Enabled = False
Beep()
End Sub
Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
If lblTime.Text.Length >= 0 Then lblTime.Text += btn1.Text
Beep()
lblClock.Hide()
lblTime.Show()
End Sub
Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
If lblTime.Text.Length >= 0 Then lblTime.Text += btn2.Text
Beep()
lblClock.Hide()
lblTime.Show()
End Sub
Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click
If lblTime.Text.Length >= 0 Then lblTime.Text += btn3.Text
Beep()
lblClock.Hide()
lblTime.Show()
End Sub
Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click
If lblTime.Text.Length >= 0 Then lblTime.Text += btn4.Text
Beep()
lblClock.Hide()
lblTime.Show()
End Sub
Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click
If lblTime.Text.Length >= 0 Then lblTime.Text += btn5.Text
Beep()
lblClock.Hide()
lblTime.Show()
End Sub
Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click
If lblTime.Text.Length >= 0 Then lblTime.Text += btn6.Text
Beep()
lblClock.Hide()
lblTime.Show()
End Sub
Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click
If lblTime.Text.Length >= 0 Then lblTime.Text += btn7.Text
Beep()
lblClock.Hide()
lblTime.Show()
End Sub
Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click
If lblTime.Text.Length >= 0 Then lblTime.Text += btn8.Text
Beep()
lblClock.Hide()
lblTime.Show()
End Sub
Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click
If lblTime.Text.Length >= 0 Then lblTime.Text += btn9.Text
Beep()
lblClock.Hide()
lblTime.Show()
End Sub
Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click
If lblTime.Text.Length >= 0 Then lblTime.Text += btn0.Text
Beep()
lblClock.Hide()
lblTime.Show()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim A As Integer
Dim B As Integer
If lblTime.Text > "0" Then
Timer1.Enabled = True
A = CInt(lblTime.Text)
B = 1
lblTime.Text = CStr(A - B)
ElseIf lblTime.Text = "" Then
Timer1.Enabled = False
End If
If lblTime.Text = "0" Then
Beep()
lblTime.Text = "DONE"
Timer1.Enabled = False
lblYellow.Hide()
lblGray.Show()
End If
If lblTime.Text = "" Then
Timer1.Enabled = False
lblYellow.Hide()
lblGray.Show()
End If
End Sub
Private Sub btnClock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClock.Click
If lblTime.Text = "" Or Timer1.Enabled = False Then
lblClock.Show()
lblTime.Hide()
lblYellow.Hide()
lblGray.Show()
Timer2.Enabled = True
Timer1.Enabled = False
End If
Beep()
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
lblClock.Text = CStr(TimeOfDay)
End Sub
End Class
I want it to be in the format you listed: "0:00:09 -> 0:00:95 -> 0:09:59 -> 0:95:95 -> 9:59:59"
Just like you would have the cook time appear when you typed it in on your own microwave at home.
The max is 9 hours, 59 min, 59 sec.
-
Re: Make Label Format Time 9:59:59
Try this. Set your form's KeyPreview property to True and drop a Label to it (named Label1) then paste this code in. Now run it and try to type some values using the keyboard.
Code:
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
Dim curTxt As String = Label1.Text.Replace(":", "")
If curTxt.Length < 6 Then
Dim ch As Char = e.KeyChar
If Char.IsNumber(ch) Then
curTxt &= ch
If curTxt.Length > 2 Then
For i As Integer = curTxt.Length - 2 To 1 Step -2
curTxt = curTxt.Insert(i, ":")
Next
End If
Label1.Text = curTxt
Else
Beep()
End If
Else
Beep()
End If
End Sub
-
Re: Make Label Format Time 9:59:59
Allright, but some validation might be in order. What if I dial 9:99:99?
-
Re: Make Label Format Time 9:59:59
Quote:
Originally Posted by
cicatrix
Allright, but some validation might be in order. What if I dial 9:99:99?
The part for the time in the book states: "The user should be able to enter a number of hours no greater than 9, a number of minutes no greater than 59 and a number of seconds no greater than 59; otherwise, the invalid cook time will be set to zero."
-
Re: Make Label Format Time 9:59:59
Quote:
Originally Posted by
stanav
Try this. Set your form's KeyPreview property to True and drop a Label to it (named Label1) then paste this code in. Now run it and try to type some values using the keyboard.
Code:
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
Dim curTxt As String = Label1.Text.Replace(":", "")
If curTxt.Length < 6 Then
Dim ch As Char = e.KeyChar
If Char.IsNumber(ch) Then
curTxt &= ch
If curTxt.Length > 2 Then
For i As Integer = curTxt.Length - 2 To 1 Step -2
curTxt = curTxt.Insert(i, ":")
Next
End If
Label1.Text = curTxt
Else
Beep()
End If
Else
Beep()
End If
End Sub
I tried this, but call me a newbie, I dont know how to set my form's KeyPreview property to True...
-
Re: Make Label Format Time 9:59:59
Quote:
Originally Posted by
cicatrix
Allright, but some validation might be in order. What if I dial 9:99:99?
Actually, that's a valid value for microwaves (at least with the ones I've been using)... They don't automatically change 90 seconds to 1:30.
-
Re: Make Label Format Time 9:59:59
Quote:
Originally Posted by
stanav
Actually, that's a valid value for microwaves (at least with the ones I've been using)... They don't automatically change 90 seconds to 1:30.
Yeah, but I gotta follow the books direction, not basic logic unfortunately... lol
-
Re: Make Label Format Time 9:59:59
Quote:
Originally Posted by
EiNST3iN
I tried this, but call me a newbie, I dont know how to set my form's KeyPreview property to True...
In the designer, if you click on the form's title bar to select it, then go to the property window (where you set the properties for the current selected control in the designer), look for the KeyPreview property and change its value to True.
-
Re: Make Label Format Time 9:59:59
Quote:
Originally Posted by
stanav
In the designer, if you click on the form's title bar to select it, then go to the property window (where you set the properties for the current selected control in the designer), look for the KeyPreview property and change its value to True.
Thanks, I will try that again now...
-
Re: Make Label Format Time 9:59:59
Quote:
Originally Posted by
stanav
Try this. Set your form's KeyPreview property to True and drop a Label to it (named Label1) then paste this code in. Now run it and try to type some values using the keyboard.
Code:
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
Dim curTxt As String = Label1.Text.Replace(":", "")
If curTxt.Length < 6 Then
Dim ch As Char = e.KeyChar
If Char.IsNumber(ch) Then
curTxt &= ch
If curTxt.Length > 2 Then
For i As Integer = curTxt.Length - 2 To 1 Step -2
curTxt = curTxt.Insert(i, ":")
Next
End If
Label1.Text = curTxt
Else
Beep()
End If
Else
Beep()
End If
End Sub
Okay, this did display in time format like I want which is AWESOME! How do I get it to accept from the 0-9 keypad built into the GUI I made and not the keyboard?
As well when I type it wont hide the clock and display the lblText Label where the input is.
-
Re: Make Label Format Time 9:59:59
1. If the digit entered is 7, 8 or 9 - it can be either hours, single minutes or single seconds
2. If the digit entered is 6 it can be either hours or single minutes
3. If the digit entered is 1, 2, 3, 4, 5 - it can be anything
If the first digit is, say 9, then it can be either 9 hours or 9 minutes or 9 seconds
so what should we display: 0:00:09, 0:09:00 or 9:00:00?
Logic suggest that we display 0:00:09, but what if the user presses 5 afterwards?
Should we switch to 9:50:00? And then we should continue from the 0 that comes immediately after 5.
This turned out to be more difficult than I anticipated :D
-
Re: Make Label Format Time 9:59:59
Quote:
Originally Posted by
cicatrix
1. If the digit entered is 7, 8 or 9 - it can be either hours, single minutes or single seconds
2. If the digit entered is 6 it can be either hours or single minutes
3. If the digit entered is 1, 2, 3, 4, 5 - it can be anything
If the first digit is, say 9, then it can be either 9 hours or 9 minutes or 9 seconds
so what should we display: 0:00:09, 0:09:00 or 9:00:00?
Logic suggest that we display 0:00:09, but what if the user presses 5 afterwards?
Should we switch to 9:50:00? And then we should continue from the 0 that comes immediately after 5.
This turned out to be more difficult than I anticipated :D
I agree with the difficult part...
Off the books 'guidelines' I am going to guess that if the user doesnt enter a format that doesnt follow the time rules, then it will need to change the time back to 0 when they hit Start.
So there is no entering 90 if you really want 1:30... That keeps it kinda simple I think...
-
Re: Make Label Format Time 9:59:59
Resetting wouldn't help, by the way.
If you want to enter 9:59:42, the first digit would be 9:
1. 9 -> 0:00:09
2. 5 -> 0:00:95 -> simple validation would fail at this point and the display be reset to all zeroes.
Instead it should be something like this:
2. 5 -> 0:09:50
3. 9 -> 0:09:59
4. 4 -> 9:59:40
5. 2 -> 9:59:42
And on the real microwave display there must be some blinking of the digit position being active at the moment.
-
Re: Make Label Format Time 9:59:59
So the way I interpret it like this:
- The user can enter a maximum of 5 digits
- 1st digit can be 0-9
- 2nd digit can be 0-5
- 3rd digit can be 0-9
- 4th digit can be 0-5
- 5th digit can be 0-9
If the user enter in any digit out of its range, the clock resets to 0:00:00.
There you go. You just have to keep track of which digit is being entered and test it against its range, if it's out of range, reset the clock; otherwise, append the digit to the input string, format it (inserting ":" at proper location) then assign it to the label.text.
-
Re: Make Label Format Time 9:59:59
:D
I know, I'm being boring but... about the third digit:
I want to set a time of 0:01:47 (so I press 1, 4, 7)
My microwave does this with a dial you can turn clockwise or counterclockwise thus changing the time on the display.
-
Re: Make Label Format Time 9:59:59
Quote:
Originally Posted by
cicatrix
Resetting wouldn't help, by the way.
If you want to enter 9:59:42, the first digit would be 9:
1. 9 -> 0:00:09
2. 5 -> 0:00:95 -> simple validation would fail at this point and the display be reset to all zeroes.
Instead it should be something like this:
2. 5 -> 0:09:50
3. 9 -> 0:09:59
4. 4 -> 9:59:40
5. 2 -> 9:59:42
And on the real microwave display there must be some blinking of the digit position being active at the moment.
No, there is a Start button on my GUI, so you can enter :95 and it wont clear that as wrong until you hit the Start button.
Its only considered a wrong entry in the display if the number is in the wrong time format when you hit the Start button.
So basically I just need a way to enter numbers in that time format, but if the user falls out of the 9:59:59 limit boundary, then it will display 0 and not do anything when they hit Start.
-
Re: Make Label Format Time 9:59:59
Any other help with a code to just get that label to accept time format?
-
Re: Make Label Format Time 9:59:59
So you only validate the entered time when the user presses the Start button? That would make it easier.
In the start button click event handler, you take the label's text and split it at the ":" this will gives you an array of string. You will convert each array element to an integer and test its value. For example
Code:
Dim parts() as string = label1.text.split(":"c)
Dim hr as Integer = CInt(parts(0))
Dim min As Integer = CInt(parts(1))
Dim sec as Integer = CInt(parts(2))
If hr > 9 OrElse min > 59 OrElse sec > 59 Then
'Invalid time.... Reset Clock
EndIf
-
Re: Make Label Format Time 9:59:59
-
Re: Make Label Format Time 9:59:59
I think u can do like this
add a timer and a label
add this to the timer
Code:
Label1.Text = Timeofday
and make sure the timer is enabled
It will have like this 10:12:55 PM
And if u want that the timer should not go above 9:59:59
go in the label_textCHanged property
add this
Code:
If Label1.Text = "9:59:59 AM" Then
Timer1.Stop()
ElseIf Label1.Text = "9:59:59 PM" Then
Timer1.Stop()
End if
or make a textbox and add in the textbox_TextChanged property
Code:
If TextBox1.Text = "9:59:59 AM" Then
Timer1.Stop()
ElseIf TextBox1.Text = "9:59:59 PM" Then
Timer1.Stop()
End if
-
Re: Make Label Format Time 9:59:59
Yeah, but that does NOT do anything about making the INPUT TIME from the keypad on the GUI in that time format. All that does it makes a real clock time count down from its default setting.
-
Re: Make Label Format Time 9:59:59
Here is the GUI of my program if it helps.
http://i124.photobucket.com/albums/p...Doan/Image.png
I need to be able to have the user type in their time using the keypad I have put on the GUI.
I am having trouble getting the inputted number to turn into a time format.
For example:
If the user inputs 130
I need the display to countdown from: 1:30 and display it in that format.
The max that can be entered is 9:59:59.
The BIGGEST part I need help with is getting the input number to go into time format. HH:MM:SS
Here is the code I have if it helps:
Code:
Option Strict On
Public Class Form1
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
lblYellow.Show()
lblGray.Hide()
lblClock.Hide()
lblTime.Show()
Timer1.Enabled = True
Beep()
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
lblYellow.Hide()
lblGray.Show()
lblClock.Show()
lblTime.Text = ""
lblTime.Hide()
Timer1.Enabled = False
Beep()
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
lblYellow.Hide()
lblGray.Show()
If lblTime.Text > "0" Then
lblClock.Hide()
End If
If lblTime.Text = "DONE!" Then
lblTime.Hide()
lblClock.Show()
lblTime.Text = ""
End If
Timer1.Enabled = False
Beep()
End Sub
Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
If lblTime.Text = "DONE!" Then
lblTime.Text = ""
End If
If lblTime.Text.Length >= 0 Then lblTime.Text += btn1.Text
Beep()
lblClock.Hide()
lblTime.Show()
End Sub
Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
If lblTime.Text = "DONE!" Then
lblTime.Text = ""
End If
If lblTime.Text.Length >= 0 Then lblTime.Text += btn2.Text
Beep()
lblClock.Hide()
lblTime.Show()
End Sub
Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click
If lblTime.Text = "DONE!" Then
lblTime.Text = ""
End If
If lblTime.Text.Length >= 0 Then lblTime.Text += btn3.Text
Beep()
lblClock.Hide()
lblTime.Show()
End Sub
Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click
If lblTime.Text = "DONE!" Then
lblTime.Text = ""
End If
If lblTime.Text.Length >= 0 Then lblTime.Text += btn4.Text
Beep()
lblClock.Hide()
lblTime.Show()
End Sub
Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click
If lblTime.Text = "DONE!" Then
lblTime.Text = ""
End If
If lblTime.Text.Length >= 0 Then lblTime.Text += btn5.Text
Beep()
lblClock.Hide()
lblTime.Show()
End Sub
Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click
If lblTime.Text = "DONE!" Then
lblTime.Text = ""
End If
If lblTime.Text.Length >= 0 Then lblTime.Text += btn6.Text
Beep()
lblClock.Hide()
lblTime.Show()
End Sub
Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click
If lblTime.Text = "DONE!" Then
lblTime.Text = ""
End If
If lblTime.Text.Length >= 0 Then lblTime.Text += btn7.Text
Beep()
lblClock.Hide()
lblTime.Show()
End Sub
Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click
If lblTime.Text = "DONE!" Then
lblTime.Text = ""
End If
If lblTime.Text.Length >= 0 Then lblTime.Text += btn8.Text
Beep()
lblClock.Hide()
lblTime.Show()
End Sub
Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click
If lblTime.Text = "DONE!" Then
lblTime.Text = ""
End If
If lblTime.Text.Length >= 0 Then lblTime.Text += btn9.Text
Beep()
lblClock.Hide()
lblTime.Show()
End Sub
Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click
If lblTime.Text = "DONE!" Then
lblTime.Text = ""
End If
If lblTime.Text.Length >= 1 Then lblTime.Text += btn0.Text
Beep()
lblClock.Hide()
lblTime.Show()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim A As Integer
Dim B As Integer
If lblTime.Text > "0" Then
Timer1.Enabled = True
A = CInt(lblTime.Text)
B = 1
lblTime.Text = CStr(A - B)
End If
If lblTime.Text = "0" Then
Beep()
lblTime.Text = "DONE!"
Timer1.Enabled = False
lblYellow.Hide()
lblGray.Show()
End If
If lblTime.Text = "" Then
Timer1.Enabled = False
lblYellow.Hide()
lblGray.Show()
End If
End Sub
Private Sub btnClock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClock.Click
If lblTime.Text = "" Or Timer1.Enabled = False Then
lblClock.Show()
lblTime.Hide()
lblYellow.Hide()
lblGray.Show()
Timer2.Enabled = True
Timer1.Enabled = False
End If
Beep()
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
lblClock.Text = CStr(TimeOfDay)
End Sub
End Class
-
Re: Make Label Format Time 9:59:59
Help! Please! Its due this week... And this is the last thing I need to do.
-
Re: Make Label Format Time 9:59:59