none
Time only field data entry field RRS feed

  • Question

  • I have created a form for managers to schedule employees in two week intervals. The user is asked to input the start time and Number of hours for each day in the two week schedule. I tried Time picker but it wants to default to the current time. I have been told that's the way DTP are. I am trying to figure out a way to do it without a DTP. I have been researching this online for about a week and most of the posts are talking about a time only DTP. The field on the database is Nullable TIME(0) so it will not store a date.  Really they will most likely be inputting time in hours and 15 intervals. I thought about a masked textbox, and even two combo boxes for hours and minutes. I am kind of stuck and want to ask the experts before I paint myself into a corner or take the long way around.

    Friday, October 27, 2017 8:45 PM

Answers

  • You seems to misunderstand me. I'm telling this from real live experience for end users. 

    Some persons want a blank data time controlbox if the end user has not used it. It is impossible to do, because the control set it always to default value as I already wrote.  

    However, I forgot that I've a solution for you on our website. 

    http://www.vb-tips.com/DataBindingEvents.aspx

    Your problem is how to set with this the checkbox to false, but I think you can manage that yourself. 


    Success
    Cor

    Tuesday, November 7, 2017 3:59 PM

All replies

  • "I tried Time picker but it wants to default to the current time."

    Maybe I dont understand what you mean but cant you just set the dtp.value to the date and time you want?

    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            dtp.Format = DateTimePickerFormat.Time
            dtp.ShowUpDown = True
            dtp.Value = New DateTime(2017, 10, 26, 5, 33, 13)
        End Sub
    End Class

    Friday, October 27, 2017 9:52 PM
  • I have created a form for managers to schedule employees in two week intervals. The user is asked to input the start time and Number of hours for each day in the two week schedule. I tried Time picker but it wants to default to the current time. I have been told that's the way DTP are. I am trying to figure out a way to do it without a DTP. I have been researching this online for about a week and most of the posts are talking about a time only DTP. The field on the database is Nullable TIME(0) so it will not store a date.  Really they will most likely be inputting time in hours and 15 intervals. I thought about a masked textbox, and even two combo boxes for hours and minutes. I am kind of stuck and want to ask the experts before I paint myself into a corner or take the long way around.

    Hi

    Here is some skeleton code that uses a DateTimePicker and Comboboxes to enter the data into the series of 14 TextBoxes (Start) and 28 ComboBoxes (Times) - also needs a DataTimePicker1 in the Panel.

    *

    It has no error checking for particular exceptions that may crop up.

    It uses a bare bones Form with controls as listed at top of code and looks like this.

    *

    This code deals with TABBING based on the TabIndex of the various controls and tabs in the correct order (start then time worked)

    Here is the code (stand alone example)

    ' Form1 with Panel1 containing
    ' TextBoxes 1 through 14 for Start Time and
    ' ComboBoxes 1 through 28 for Hours/Min
    ' and DateTimePicker1

    ' NOTE: to enable useful TABBING, set the TabIndex for
    ' each control according to your needs. I have used groups
    ' of 3 to TAB between the Start time and the Hours/Min.
    ' eg 1 2 3 then 4 5 6 etc ......

    Option Strict On
    Option Explicit On
    Public Class Form1
        Dim hours, min As New List(Of String)
        Dim ctb As TextBox
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
            With DateTimePicker1
                .Format = DateTimePickerFormat.Custom
                .CustomFormat = "HH:mm"
                .BringToFront()
                .Visible = False
                .TabStop = False
                .ShowUpDown = True
                .Value = CDate(Now.Date & " 00:00")
            End With
            For Each c As Control In Panel1.Controls
                If c.GetType() Is GetType(TextBox) Then
                    With DirectCast(c, TextBox)
                        .TextAlign = HorizontalAlignment.Center
                        .Text = "00:00"
                        .BackColor = Color.White
                        AddHandler .MouseClick, AddressOf TextBox_Click
                    End With
                End If
            Next

            hours.AddRange({"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14"})
            min.AddRange({"00", "15", "30", "45"})
            For Each c As Control In Panel1.Controls
                If c.GetType() Is GetType(ComboBox) Then
                    With DirectCast(c, ComboBox)
                        Dim a(24) As String
                        Select Case CInt(c.Name.Replace("ComboBox", Nothing)) Mod 2 > 0
                            Case True
                                Array.Copy(hours.ToArray, a, hours.Count)
                                .DataSource = a.ToList
                            Case Else
                                Array.Copy(min.ToArray, a, min.Count)
                                .DataSource = a.ToList
                        End Select
                        AddHandler .GotFocus, AddressOf ComboBox_GotFocus
                    End With
                End If
            Next
            Panel1.Select()
        End Sub
        Private Sub DateTimePicker1_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles DateTimePicker1.Validating
            ctb.Text = DateTimePicker1.Value.ToString("HH:mm")
            For Each control As Control In Panel1.Controls
                If control.TabIndex = ctb.TabIndex + 1 Then
                    control.Select()
                End If
            Next
        End Sub
        Private Sub ComboBox_GotFocus(sender As Object, e As EventArgs)
            Dim cb As ComboBox = DirectCast(sender, ComboBox)
            DateTimePicker1.Visible = False
            cb.DroppedDown = True
        End Sub
        Private Sub TextBox_Click(sender As Object, e As EventArgs)
            Dim tb As TextBox = DirectCast(sender, TextBox)
            If Not ctb Is Nothing Then
                Dim d As DateTime
                If DateTime.TryParse(Now.Date & " " & tb.Text, d) Then DateTimePicker1.Value = d
            End If
            With DateTimePicker1
                .Size = tb.ClientSize
                .Location = New Point(tb.Location.X + 2, tb.Location.Y + 1)
                .Visible = True
                ctb = tb
            End With
        End Sub
    End Class


    NOTE: the name/order of the TextBoxes and Comboboxes are important


    Regards Les, Livingston, Scotland







    • Edited by leshay Sunday, October 29, 2017 11:31 AM
    Saturday, October 28, 2017 2:32 AM
  • I guess you never will get an answer on your question as it seems delibertaly incomplete. 

    You don't tell what database you are using. Microsoft at least has no databases where a "Time" column field exist. 

    Here are VB users, they use Microsoft software where the time is placed in a "DateTime" field. 

    The problem with your kind of solutions is that at 23:55 hour the next time is 00:00 on the next day. 

    Be aware that Nullable in a database does not mean the same as Nullable in computer memory. It means in a database a column item which is not available, while it is in memory an existing item which is not initialized. 


    Success
    Cor


    • Edited by Cor Ligthert Saturday, October 28, 2017 11:37 AM
    Saturday, October 28, 2017 11:36 AM
  • Hi Seeler,

    According to your description, you don't want to use DateTimePicker control to display time value, I suggest you to use ComboBox control to display time value and you can set 15 minutes interval, like this:

    Dim datetime1 As DateTime = "00:00"
            Dim datetime2 As DateTime = "23:50"
            Dim interval As Integer = 15
            Dim list As New List(Of String)
            Dim i As DateTime = datetime1
            While i < datetime2
                list.Add(i.ToString("HH:mm tt"))
                i = i.AddMinutes(interval)
            End While
            ComboBox1.DataSource = list

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 30, 2017 2:58 AM
    Moderator
  • Thanks for your reply Tom. The point is the value can be nothing as in they don't work that day. In that case the data would be Null So I think a date time picker isn't the right control.  
    Monday, October 30, 2017 5:49 PM
  • Leshay, This answer may be the best answer so far. Its a lot of code but I actually thought about it. I am now leaning towards creating a custom user control that works similar to the DateTime picker but without all the initialization and default logic. Since I am so new I am not sure I will be able to actually create such a thing.      
    Monday, October 30, 2017 5:57 PM
  • Sorry for that lack of details, I am kind of new so not really sure what details are needed. I am using SQL Server 2008 with VS2010, there is a Time(7) field in SQL that I am using to store the data. And yes 12:00 PM would be 00:00 that's why if they are not working the field is set to Null.  
    Monday, October 30, 2017 6:01 PM
  • You are right, It is since version 2008, I did not know that one, so sorry and thank you for teaching me something.

    https://docs.microsoft.com/en-us/sql/t-sql/data-types/time-transact-sql

    It seems to be equal to the TimeSpan structure in .Net

    https://msdn.microsoft.com/en-us/library/bk8a3558(v=vs.110).aspx


    Success
    Cor

    Monday, October 30, 2017 6:24 PM
  • I locked myself in a hotel at Wizard Con this weekend and worked on this. Didn't get very far but considering my skill level its mediocre. I used Masked text box set to US Time. Then coded it like this.    

    Private Sub HoursTextBox_Validating(sender As System.Object, e As System.ComponentModel.CancelEventArgs) _ Handles D01_HoursTextBox.Validating, D02_HoursTextBox.Validating, D03_HoursTextBox.Validating, D04_HoursTextBox.Validating, D05_HoursTextBox.Validating, D06_HoursTextBox.Validating, D07_HoursTextBox.Validating, D08_HoursTextBox.Validating, D09_HoursTextBox.Validating, D10_HoursTextBox.Validating, D11_HoursTextBox.Validating, D12_HoursTextBox.Validating, D13_HoursTextBox.Validating, D14_HoursTextBox.Validating Dim Input As String = sender.Text If Input = " :" Then GoTo Exit_Validate End If Dim Hours As Integer = Mid(Input, 1, 2) Dim Minutes As Integer = Mid(Input, 4, 2) If Hours > 12 Then MsgBox("Hours must be between 0 & 12") ElseIf Minutes > 60 Then MsgBox("Minutes are invalid") End If Sum_Hours() Exit_Validate: End Sub

    

    Private Sub Sum_Hours()
    
            Dim TextBoxes As New List(Of MaskedTextBox)
            Dim TotalHours As Decimal
            Dim TotalMin As Decimal
    
            TextBoxes.Add(D01_HoursTextBox)
            TextBoxes.Add(D02_HoursTextBox)
            TextBoxes.Add(D03_HoursTextBox)
            TextBoxes.Add(D04_HoursTextBox)
            TextBoxes.Add(D05_HoursTextBox)
            TextBoxes.Add(D06_HoursTextBox)
            TextBoxes.Add(D07_HoursTextBox)
            TextBoxes.Add(D08_HoursTextBox)
            TextBoxes.Add(D09_HoursTextBox)
            TextBoxes.Add(D10_HoursTextBox)
            TextBoxes.Add(D11_HoursTextBox)
            TextBoxes.Add(D12_HoursTextBox)
            TextBoxes.Add(D13_HoursTextBox)
            TextBoxes.Add(D14_HoursTextBox)
    
            For Each TB As MaskedTextBox In TextBoxes
                If TB.Text = "  :" Then
                    Continue For
                Else
                    Dim Hours As Integer = Mid(TB.Text, 1, 2)
                    Dim Minutes As Integer = Mid(TB.Text, 4, 2)
                    TotalHours += Hours
                    TotalMin += Minutes
                End If
            Next
    
            Dim Scheduled_Hours As Decimal = TotalHours + (TotalMin / 60)
            Dim dsp_Hours As String = Int(Scheduled_Hours)
            Dim dsp_Minttes As String = (Scheduled_Hours - Int(Scheduled_Hours)) * 60
    
            HoursTextBox.Text = dsp_Hours & ":" & dsp_Minttes
    
        End Sub

     
    Monday, October 30, 2017 6:27 PM
  • I think this would do your job

     Dim TheTime As New TimeSpan(CInt(MaskedTextBox1.Text.Substring(0, 2)), CInt(MaskedTextBox1.Text.Substring(3, 2)), 0)
        End Sub
    I tested it and it did. The maskedtextbox was set to Time US


    Success
    Cor


    Monday, October 30, 2017 6:50 PM
  • Hi

    Using your new idea masked textboxes instead of DTP.

    Here is some code to assist.

    Here is layout I used

    and Code

    ' Form1 with Panel1 containing
    ' MaskedTextBoxes 1 through 28
    ' and Label1 for Total Time
    ' and Label2 just as a Label for Label1 value
    
    ' NOTE: to enable useful TABBING, set the TabIndex for
    ' each control according to your needs. 
    
    Option Strict On
    Option Explicit On
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
            For Each c As Control In Panel1.Controls
                If c.GetType() Is GetType(MaskedTextBox) Then
                    With DirectCast(c, MaskedTextBox)
                        .TextAlign = HorizontalAlignment.Center
                        .Text = "00:00"
                        .PromptChar = "*"c
                        .BackColor = Color.White
                        AddHandler .MouseClick, AddressOf MaskedTextBox_Validated
                    End With
                End If
            Next
            Label1.Text = GetTotalHours()
            Panel1.Select()
        End Sub
        Private Sub MaskedTextBox_Validated(sender As Object, e As EventArgs)
            Label1.Text = GetTotalHours()
        End Sub
        Function GetTotalHours() As String
            Dim hrs As TimeSpan = Nothing
            For Each c As Control In Panel1.Controls
                If c.TabIndex Mod 2 = 0 Then
                    If c.GetType() Is GetType(MaskedTextBox) Then
                        Dim v1 As Integer = GetInteger(Split(Trim(c.Text), ":"c)(0))
                        Dim v2 As Integer = GetInteger(Split(Trim(c.Text), ":"c)(1))
                        c.ForeColor = Color.Black
                        If v1 + v2 / 60 > 12 Then
                            c.ForeColor = Color.Red
                        ElseIf v1 + v2 / 60 > 0 Then
                            c.ForeColor = Color.Green
                        End If
                        hrs = hrs.Add(New TimeSpan(GetInteger(Split(Trim(c.Text), ":"c)(0)), GetInteger(Split(Trim(c.Text), ":"c)(1)), 0))
                        End If
                End If
            Next
            Return (hrs.Days * 24 + hrs.Hours).ToString & hrs.ToString("\:mm")
        End Function
    Function GetInteger(s As String) As Integer Dim v As Integer = 0 If Integer.TryParse(s, v) Then Return v Return 0 End Function End Class


    Regards Les, Livingston, Scotland





    • Edited by leshay Monday, October 30, 2017 10:38 PM Reverted Prompt char to * as using 0 caused issues
    Monday, October 30, 2017 8:05 PM
  • I hit a little snag on the timespan solution. It appears as though one can set the null flag on the database to allow NULL values. But, One can't actually set the field to NULL after it has been changed because of the datatype edits say NULL is not a valid time. I was counting on Nulls for days not worked. Back to the drawing board. I am about the store this as a decimal. Date fields are just decimals with the integer part the date and the decimal the time? I am thinking I could even use the integer as the hours the decimal as the minutes since that's all I need. It means I will need a shit load of code to convert it to a display field and back to decimal when I save. Thanks everyone for your ideas I will let you know if\when I find a solution that works for all situations.  


    Monday, October 30, 2017 11:11 PM
  • Hi

    Just to keep the code I posted up to date. Here is a later version, still using TimeSpan, but with color coding for time exceeded and empty days etc.

    This version also uses a small Class to encompass Hours and Minutes as seperate entities.

    and the Code

    ' Form1 with Panel1 containing
    ' MaskedTextBoxes 1 through 28
    ' and Label1 for Total Time
    ' and Label2 just as a Label for Label1 value
    
    ' NOTE: to enable useful TABBING, set the TabIndex for
    ' each control according to your needs. 
    
    Option Strict On
    Option Explicit On
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
            For Each c As Control In Panel1.Controls
                If c.GetType() Is GetType(MaskedTextBox) Then
                    With DirectCast(c, MaskedTextBox)
                        .TextAlign = HorizontalAlignment.Center
                        .Text = "00:00"
                        .PromptChar = "*"c
                        .BackColor = Color.White
                        AddHandler .MouseClick, AddressOf MaskedTextBox_Validated
                    End With
                End If
            Next
            GetTotHours()
            Panel1.Select()
        End Sub
        Private Sub MaskedTextBox_Validated(sender As Object, e As EventArgs)
            GetTotHours()
        End Sub
        Sub GetTotHours()
            Dim tothrs As TotalWorked = GetTotalHours()
            Label1.ForeColor = Color.Black
            Label1.Text = tothrs.Hours.ToString("00:") & tothrs.Mins.ToString("00")
            If tothrs.Hours + tothrs.Mins / 60 > 80 Then
                Label1.ForeColor = Color.Red
            ElseIf tothrs.Hours + tothrs.Mins / 60 > 0 Then
                Label1.ForeColor = Color.Green
            End If
        End Sub
        Function GetTotalHours() As TotalWorked
            Dim hrs As TimeSpan = Nothing
            For Each c As Control In Panel1.Controls
                Dim v1 As Integer = GetInteger(Split(Trim(c.Text), ":"c)(0))
                Dim v2 As Integer = GetInteger(Split(Trim(c.Text), ":"c)(1))
                If c.TabIndex Mod 2 = 0 Then
                    If c.GetType() Is GetType(MaskedTextBox) Then
                        c.ForeColor = Color.Black
                        c.BackColor = Color.White
                        If v1 + v2 / 60 > 12 Then
                            c.ForeColor = Color.Red
                        ElseIf v1 + v2 / 60 > 0 Then
                            c.ForeColor = Color.Green
                        Else
                            c.BackColor = Color.LightGray
                        End If
                        hrs = hrs.Add(New TimeSpan(v1, v2, 0))
                    End If
                Else
                    c.BackColor = Color.LightGray
                    If v1 + v2 / 60 > 0 Then
                        c.BackColor = Color.White
                    End If
                End If
            Next
            Return New TotalWorked With {.Hours = hrs.Days * 24 + hrs.Hours, .Mins = hrs.Minutes}
        End Function
        Function GetInteger(s As String) As Integer
            Dim v As Integer = 0
            If Integer.TryParse(s, v) Then Return v
            Return 0
        End Function
        Class TotalWorked
            Property Hours As Integer
            Property Mins As Integer
        End Class
    End Class
    


    Regards Les, Livingston, Scotland

    Monday, October 30, 2017 11:23 PM
  • Les I am sure that will come in handy when I get this sorted. I was able to set a field back to null with a update query. Maybe LINQ instead of Datasets will work. I never figured this would be the final version. Once I have a prototype I planed to convert it the LINQ or Entity data model. Looks like your in the middle of a storm over there in Scotland. We've had some pretty bad storms here. Hope your staying safe and dry. Thanks Again


    Monday, October 30, 2017 11:26 PM
  • Hi Seeker,

    Have you solves your issue now? If yes, please remember to close your thread by marking the helpful post as answer, it is beneficial to other community members who face the same issue.

    Thanks for you understanding.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, October 31, 2017 2:00 AM
    Moderator
  • I am still having problems. I assumed it was not updating because of the timespan data type limits. The update indicates it updated but the database is not changed. Is there a way I could upload a small project to see if someone can help? I can post SQL to create the tables and my project code.

        Private Sub OkButton_Click(sender As System.Object, e As System.EventArgs) Handles OkButton.Click
            Try
                Me.Validate()
                Me.OperatorsBindingSource.EndEdit()
                Me.TableAdapterManager.UpdateAll(Me.Laser_Maint_DBDataSet)
    
                'OperatorsTableAdapter.Update(Laser_Maint_DBDataSet.Tables("Operators"))
    
    
                MsgBox("Update successful")
    
            Catch ex As Exception
                MsgBox("Update failed")
            End Try
        End Sub

    There are tons of problems shown here about not updating with a tableadapter. The solutions are simple but not related to the used value types. Better to create a new question than direct relate it to your current code. 


    Success
    Cor


    Tuesday, October 31, 2017 2:44 PM
  • Is there a way to post a sample database and project for people to look at?

    Hi

    You could place it on OneDrive (or similar) and post the link here. Thats what most folk do as there is no 'attachment' feature in these forums.


    Regards Les, Livingston, Scotland

    Tuesday, October 31, 2017 3:03 PM


  • Is there a way to post a sample database and project for people to look at?
    Why do you not want to create a new question. These forums are also made as a kind of knowledge base and now you spoil all things others have done for you. 

    Success
    Cor

    Tuesday, October 31, 2017 3:48 PM
  • Yea but it has probably to do with your settings of the table adapter and that has nothing to do with the original question. 

    Karen has written thousands of messages around that in this forum. 

    But you have already spoiled the thread.


    Success
    Cor

    Tuesday, October 31, 2017 5:06 PM
  • I think the issue is Visual Studio will not over write a field value with NULL. In order to determine this I first set a Time to 8:00 and updated it to the database. I then deleted the value in the control textbox and ran the program to the Update in debug. I viewed the data in the dataset before it is pushed to the database and found the field I changed still contained 8:00. This leads me to believe that the interface between the control and the dataset is not allowing the field to be blanked. It does this for Numeric type fields. In both cases it displayed the "Update Successful" message but did not change the database value. I then tried it on a true text control and it also would not save NULL, it saved """" to the field I blanked. So is this a problem with controls not allowing fields to be Nulled by blanking them? Further is there a way to change this behavior?

    Wednesday, November 1, 2017 3:31 PM
  • I think the issue is Visual Studio will not over write a field value with NULL. In order to determine this I first set a Time to 8:00 and updated it to the database. I then deleted the value in the control textbox and ran the program to the Update in debug. I viewed the data in the dataset before it is pushed to the database and found the field I changed still contained 8:00. This leads me to believe that the interface between the control and the dataset is not allowing the field to be blanked. It does this for Numeric type fields. In both cases it displayed the "Update Successful" message but did not change the database value. I then tried it on a true text control and it also would not save NULL, it saved """" to the field I blanked. So is this a problem with controls not allowing fields to be Nulled by blanking them? Further is there a way to change this behavior?

    Hi Seeker,

    You can  save NUll value into sql database using DBNull.Value.

    Private Sub loaddate()
    
            Dim Str As String = "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\C# and VB Support\Example(VB)\Demo\Data3.mdf;Integrated Security=True"
            Dim sql As String = "update Test9 set column1=@date where Id=3"
            Dim dt As New DataTable
            Using con As New SqlConnection(Str)
                con.Open()
                Using cmd As New SqlCommand(sql, con)
    
                    If TextBox1.Text = "" Then
                        cmd.Parameters.AddWithValue("@date", DBNull.Value)
                    Else
                        Dim time As DateTime = Convert.ToDateTime(TextBox1.Text)
                        cmd.Parameters.AddWithValue("@date", time.ToString("HH:mm:ss"))
                    End If
                    'cmd.Parameters(0).IsNullable = True
                    cmd.ExecuteNonQuery()
                End Using
            End Using

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, November 6, 2017 9:23 AM
    Moderator


  • Hi Seeker,

    I can save NUll value into sql database using DBNull.Value.

    Cherry, 

    Can you eloborate for us what this has to do with the question? I know that the most terrible thing which happens too Microsoft was that MSFT made searching for answers on Microsoft problems became impossible because all the strange replies they submitted to forums. But my perception was, it had stopped. 


    Success
    Cor


    Monday, November 6, 2017 10:11 AM


  • Hi Seeker,

    I can save NUll value into sql database using DBNull.Value.

    Cherry, 

    Can you eloborate for us what this has to do with the question? I know that the most terrible thing which happens too Microsoft was that MSFT made searching for answers on Microsoft problems became impossible because all the strange replies they submitted to forums. But my perception was, it had stopped. 


    Success
    Cor


    And then worst those who made the original question and marked it as answer to hide their impossibility to see the problem.

    Success
    Cor

    Monday, November 6, 2017 10:15 AM


  • Hi Seeker,

    I can save NUll value into sql database using DBNull.Value.

    Cherry, 

    Can you eloborate for us what this has to do with the question? I know that the most terrible thing which happens too Microsoft was that MSFT made searching for answers on Microsoft problems became impossible because all the strange replies they submitted to forums. But my perception was, it had stopped. 


    Success
    Cor


    And then worst those who made the original question and marked it as answer to hide their impossibility to see the problem.

    Success
    Cor

    The original question was about how best to work with time only values in windows forms, both as Time and hrs&min. The goal is to create a flexible employee two week schedule. How this effects that goal, 00:00 is midnight\12:00PM in the start time field this could cause confusion. At the very least eliminate someone starting at midnight. Null values show up as __:__ instead of 00:00 this could avoid user confusion and its easier to read. 00:00 could be ok in the hours but blank would be better, just to make it clear they don't work that day. I figured out how to use the time only fields but then when I NULL'd the values in the fields they did not update to the database. I thought it was binding issue but then was able to update a text field on the same form. Cherry I saw your answer but not sure how to implement it as I am very new to windows forms so this is a Dataset binding project. Much of the data updating is done in the background. I am trying to learn Linq and/or Data Entity model. If someone thinks this can be better achieved using one of those methods I would do it. I just didn't want to spend a few more weeks to find out its not possible. Cor thank you for policing the site I have spent days pouring over answers that were not really answers.



    Monday, November 6, 2017 2:02 PM
  • As someone else mentioned, and I agree, use ComboBoxes.  Here is some code that shows how that works.  There are two ComboBoxes on the form for this named cbTime1 and cbTime2

        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            SetupCombos(cbTime1, cbTime2) 'two ComboBoxes
        End Sub
    
        Private noEntry As String = "--:--"
        Private midNght As String = "Midnight"
        Private noon As String = "Noon"
    
        Public Sub SetupCombos(ParamArray Combos() As ComboBox)
            Dim ts As New TimeSpan(0, 15, 0)
            Dim interval As New TimeSpan(0, 15, 0)
            Dim noonts As New TimeSpan(12, 0, 0)
            Dim ets As New TimeSpan(24, 0, 0)
            Dim cbVals As New List(Of String)
            cbVals.Add(noEntry) 'nothing
            cbVals.Add(midNght)
            Do While ts < ets
                If ts <> noonts Then
                    cbVals.Add(ts.ToString("hh\:mm"))
                Else
                    cbVals.Add(noon)
                End If
                ts = ts.Add(interval)
            Loop
    
            For Each cb As ComboBox In Combos
                cb.DataSource = cbVals.ToArray
            Next
        End Sub
    
        Private Sub cbTime_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbTime1.SelectedIndexChanged, cbTime2.SelectedIndexChanged
            Dim whCB As ComboBox = DirectCast(sender, ComboBox)
            Dim theTime? As TimeSpan 'nullable
            If whCB.SelectedIndex >= 0 Then
                If whCB.SelectedValue.ToString = noEntry Then
                    'null, no value
                ElseIf whCB.SelectedValue.ToString = midNght Then
                    theTime = New TimeSpan(0, 0, 0)
                ElseIf whCB.SelectedValue.ToString = noon Then
                    theTime = New TimeSpan(12, 0, 0)
                Else
                    theTime = TimeSpan.Parse(whCB.SelectedValue.ToString)
                End If
            End If
            If theTime.HasValue Then
                Debug.WriteLine("{0} {1}", whCB.Name, theTime.ToString) 'put breakpoint here
            End If
        End Sub
    


    "Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it" - MSDN User JohnWein

    Monday, November 6, 2017 3:06 PM
  • I believe I have something useful to offer. Just need to put it through a few test. High level it's modeled after Microsoft Outlook appointments. Does not show (x hours) but just hours every 15 minutes

    Outlook

    My simple sample using ComboBox controls. It includes a method to set the time too.

    Code to implement

    Dim timeOperations As New TimeOperations
    timeOperations.ReadHours()
    ComboBox1.DataSource = timeOperations.TimeList
    ComboBox1.DisplayMember = "DisplayValue"
    ComboBox1.SelectedIndex = timeOperations.DefaultIndex
    
    ComboBox2.DataSource = timeOperations.TimeList
    ComboBox2.DisplayMember = "DisplayValue"
    ComboBox2.DataSource = timeOperations.CloneHours
    ComboBox2.SelectedIndex = timeOperations.DefaultIndex
    
    ComboBox3.DataSource = timeOperations.TimeList
    ComboBox3.DisplayMember = "DisplayValue"
    ComboBox3.DataSource = timeOperations.CloneHours
    ComboBox3.SelectedIndex = timeOperations.DefaultIndex

    As stated above need to run a few more test and perhaps add more functionality.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, November 6, 2017 3:38 PM
    Moderator
  • So I'm juggling things here and still working on this. Here is the implementation so far, still in a rough stage but all is working. What I'm working on to complete this is assertions. Have to go out for a while, will finish up later.

    Imports TimeDatabaseLibrary
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim timeOperations As New TimeOperations
    
            ' Read hours-minutes
            timeOperations.ReadHours()
    
            ' setup the start time ComboBox
            cboStartTime.DataSource = timeOperations.TimeList
            cboStartTime.DisplayMember = "DisplayValue"
            '
            ' Defaults to 8 AM (see code in TimeOperations)
            '
            cboStartTime.SelectedIndex = timeOperations.DefaultIndex
    
            ' setup the end time ComboBox
            cboEndTime.DataSource = timeOperations.TimeList
            cboEndTime.DisplayMember = "DisplayValue"
            cboEndTime.DataSource = timeOperations.CloneHours
            ' set to 1:15 PM
            cboEndTime.SelectedIndex = timeOperations.GetTimeIndex(9, 45)
    
            ' setup events to check selected values
            AddHandler cboStartTime.SelectedIndexChanged, AddressOf cboStartTime_SelectedIndexChanged
            AddHandler cboEndTime.SelectedIndexChanged, AddressOf cboEndTime_SelectedIndexChanged
    
        End Sub
    
        Private Sub cboStartTime_SelectedIndexChanged(sender As Object, e As EventArgs)
            ' similar logic to end time goes here
        End Sub
        Private Sub cboEndTime_SelectedIndexChanged(sender As Object, e As EventArgs)
            ' check to see if end time is less than start time
            ' currently WIP
            If cboEndTime.GetTimeHolder.IsSelectedTimeEarlier(cboStartTime.GetTimeHolder) Then
                Console.WriteLine("End time can not be prior to start time")
            End If
        End Sub
    End Class
    


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, November 6, 2017 6:54 PM
    Moderator
  • dbasnett, Thank you for your input. I tried your solution. You may have gotten it to work where I couldn't. I bound the two Combobox's, cbTime1 to D01Start and cbTime2 to D01Hours. I was able to set D01Start to 7:00 and D01Hours to 8:00. The problem came when I tried to set them back to Null. When I changed the value of the Combo box to --:--,Midnight or Noon. it locked the screen and I couldn't leave the control until I changed it to a valid time. This is similar to what happened before with a masked textbox. I believe it was because the control inherited some limitations from the timespan datatype of the dataset/database. The only way I found to get by this working is by using the NullableDateTimePicker (see the code below). The problem with that approach is although I was able to changed it on the form, it would not get changed in the dataset. Therefore never get to the database.

    Imports System.Globalization
    Imports System.Threading
    
    Public Class NullableDateTimePicker
        Inherits System.Windows.Forms.DateTimePicker
        ' true, when no date shall be displayed (empty DateTimePicker)
        Private _isNull As Boolean
    
        ' If _isNull = true, this value is shown in the DTP
        Private _nullValue As String
    
        ' The format of the DateTimePicker control
        Private _format As DateTimePickerFormat = DateTimePickerFormat.[Long]
    
        ' The custom format of the DateTimePicker control
        Private _customFormat As String
    
        ' The format of the DateTimePicker control as string
        Private _formatAsString As String
    
        Public Sub New()
            MyBase.New()
            MyBase.Format = DateTimePickerFormat.[Custom]
            NullValue = " "
            Format = DateTimePickerFormat.[Long]
        End Sub
    
        Public Shadows Property Value() As [Object]
            Get
                If _isNull Then
                    Return Nothing
                Else
                    Return MyBase.Value
                End If
            End Get
            Set(ByVal value As [Object])
                If value Is Nothing OrElse value Is DBNull.Value Then
                    SetToNullValue()
                Else
                    SetToDateTimeValue()
                    MyBase.Value = DirectCast(value, DateTime)
                End If
            End Set
        End Property
    
        Public Shadows Property Format() As DateTimePickerFormat
            Get
                Return _format
            End Get
            Set(ByVal value As DateTimePickerFormat)
                _format = value
                SetFormat()
                OnFormatChanged(EventArgs.Empty)
            End Set
        End Property
    
        Public Shadows Property CustomFormat() As [String]
            Get
                Return _customFormat
            End Get
            Set(ByVal value As [String])
                _customFormat = value
            End Set
        End Property
        Public Property NullValue() As [String]
            Get
                Return _nullValue
            End Get
            Set(ByVal value As [String])
                _nullValue = value
            End Set
        End Property
    
        Private Property FormatAsString() As String
            Get
                Return _formatAsString
            End Get
            Set(ByVal value As String)
                _formatAsString = value
                MyBase.CustomFormat = value
            End Set
        End Property
    
        Private Sub SetFormat()
            Dim ci As CultureInfo = Thread.CurrentThread.CurrentCulture
            Dim dtf As DateTimeFormatInfo = ci.DateTimeFormat
            Select Case _format
                Case DateTimePickerFormat.[Long]
                    FormatAsString = dtf.LongDatePattern
                    Exit Select
                Case DateTimePickerFormat.[Short]
                    FormatAsString = dtf.ShortDatePattern
                    Exit Select
                Case DateTimePickerFormat.Time
                    FormatAsString = dtf.ShortTimePattern
                    Exit Select
                Case DateTimePickerFormat.[Custom]
                    FormatAsString = Me.CustomFormat
                    Exit Select
            End Select
        End Sub
    
        Private Sub SetToNullValue()
            _isNull = True
            MyBase.CustomFormat = If((_nullValue Is Nothing OrElse _nullValue = [String].Empty), " ", "'" & _nullValue & "'")
        End Sub
    
        Private Sub SetToDateTimeValue()
            If _isNull Then
                SetFormat()
                _isNull = False
                MyBase.OnValueChanged(New EventArgs())
            End If
        End Sub
    
        Protected Overloads Overrides Sub OnCloseUp(ByVal e As EventArgs)
            If Control.MouseButtons = MouseButtons.None Then
                If _isNull Then
                    SetToDateTimeValue()
                    _isNull = False
                End If
            End If
            MyBase.OnCloseUp(e)
        End Sub
    
        Protected Overloads Overrides Sub OnKeyUp(ByVal e As KeyEventArgs)
            If e.KeyCode = Keys.Delete Then
                Me.Value = Nothing
                OnValueChanged(EventArgs.Empty)
            End If
            MyBase.OnKeyUp(e)
            Me.Refresh()
    
        End Sub
    End Class

    Here is some SQL to create a test database

    --Use TESTDB
    --GO 
    
    SET ANSI_NULLS ON
    GO
    
    SET QUOTED_IDENTIFIER ON
    GO
    
    SET ANSI_PADDING ON
    GO
    
    CREATE TABLE [dbo].[Operators3](
    	[Initials] [varchar](4) NOT NULL,
    	[UserId] [varchar](20) NULL,
    	[Name] [varchar](25) NULL,
    	[Hours] [decimal](5, 2) NULL,
    	[Shift] [tinyint] NULL,
    	[Active_Ind] [bit] NOT NULL,
    	[D01_start] [time](0) NULL,
    	[D01_Hours] [time](0) NULL,
     CONSTRAINT [OperINIT_PK] PRIMARY KEY NONCLUSTERED 
    (
    	[Initials] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    
    
    INSERT INTO [Operators3]
        (Initials,UserId,Name,Hours,Shift,Active_Ind,D01_start,D01_Hours) 
    VALUES 
    ('UKN','Unkown','Test',12.00,0,0,'07:00:00','08:00:00'),
    ('AL','ALuther','Arthor Luther',NULL,2,0,NULL,NULL),
    ('CM','CMcMillian','Chester McMillian',NULL,7,0,NULL,NULL),
    ('CN','CNguyen','Chris Nguyen',8.00,1,1,NULL,NULL);



    Monday, November 6, 2017 9:16 PM
  • Visual Studio solution

    Screenshots

    Solution, yes there is a lot of code but does not take much to set it up.

    Setup and calculations (optional)

    Imports TimeDatabaseLibrary
    
    Public Class WorkWeekForm
        Private timeOperations As TimeOperations
        Private WorkWeek1 As WorkWeek
        Private WorkWeek2 As WorkWeek
        Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            Dim ts As New TimeSpan(16, 45, 0) ' start at 4:45
    
            timeOperations = New TimeOperations(ts)
            timeOperations.ReadHours()
    
            week1GroupBox.Controls.OfType(Of ComboBox).ToList.ForEach(
                Sub(cbo)
                    cbo.DataSource = timeOperations.CloneHours
                    cbo.DisplayMember = "DisplayValue"
                    cbo.SelectedIndex = timeOperations.DefaultIndex
                End Sub)
    
    
            week2GroupBox.Controls.OfType(Of ComboBox).ToList.ForEach(
                Sub(cbo)
                    cbo.DataSource = timeOperations.CloneHours
                    cbo.DisplayMember = "DisplayValue"
                    cbo.SelectedIndex = timeOperations.DefaultIndex
                End Sub)
    
        End Sub
    
        Private Sub cmdResults_Click(sender As Object, e As EventArgs) Handles cmdResults.Click
            WorkWeek1 = New WorkWeek With
                {
                    .SundayHours = txtSun1.DoubleValue, .SundayStart = cboSun1.GetTimeHolder.TimeSpan,
                    .MondayHours = txtMon1.DoubleValue, .MondayStart = cboMon1.GetTimeHolder.TimeSpan,
                    .TuesdayHours = txtTue1.DoubleValue, .TuesdayStart = cboTue1.GetTimeHolder.TimeSpan,
                    .WednesdayHours = txtWed1.DoubleValue, .WednesdayStart = cboWed1.GetTimeHolder.TimeSpan,
                    .ThursdayHours = txtThu1.DoubleValue, .ThursdayStart = cboThu1.GetTimeHolder.TimeSpan,
                    .FridayHours = txtFri1.DoubleValue, .FridayStart = cboFri1.GetTimeHolder.TimeSpan,
                    .SatudayHours = txtSat1.DoubleValue, .SatudayStart = cboSat1.GetTimeHolder.TimeSpan
                }
    
            Dim Week1Hours = WorkWeek1.SundayHours +
                             WorkWeek1.MondayHours +
                             WorkWeek1.TuesdayHours +
                             WorkWeek1.WednesdayHours +
                             WorkWeek1.ThursdayHours +
                             WorkWeek1.FridayHours
    
            txtWeek1Hours.Text = Week1Hours.ToString
    
            WorkWeek2 = New WorkWeek With
                {
                    .SundayHours = txtSun2.DoubleValue, .SundayStart = cboSun2.GetTimeHolder.TimeSpan,
                    .MondayHours = txtMon2.DoubleValue, .MondayStart = cboMon2.GetTimeHolder.TimeSpan,
                    .TuesdayHours = txtTue2.DoubleValue, .TuesdayStart = cboTue2.GetTimeHolder.TimeSpan,
                    .WednesdayHours = txtWed2.DoubleValue, .WednesdayStart = cboWed2.GetTimeHolder.TimeSpan,
                    .ThursdayHours = txtThu2.DoubleValue, .ThursdayStart = cboThu2.GetTimeHolder.TimeSpan,
                    .FridayHours = txtFri2.DoubleValue, .FridayStart = cboFri2.GetTimeHolder.TimeSpan,
                    .SatudayHours = txtSat2.DoubleValue, .SatudayStart = cboSat2.GetTimeHolder.TimeSpan
                }
    
            Dim Week2Hours = WorkWeek2.SundayHours +
                             WorkWeek2.MondayHours +
                             WorkWeek2.TuesdayHours +
                             WorkWeek2.WednesdayHours +
                             WorkWeek2.ThursdayHours +
                             WorkWeek2.FridayHours
    
            txtWeek2Hours.Text = Week2Hours.ToString
    
        End Sub
    End Class
    TimeDatabaseLibrary, make sure to change the Framework version to your Framework version.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, November 6, 2017 11:40 PM
    Moderator
  • Thanks again Karen, I see you have ran into the same road block I did "timespans must contain a valid time". I like your idea of changing the shift hours to a decimal 8.5 = 8:30. My solution just ended up converting it to decimal summing the total hours then converting it back to HH:MM for display. The sticking point is how to set the value to Null in the dataset and ultimately in the database. The reason this is important is less confusion on the users part. Cherry indicated I can set the field to NULL using the code below. I am trying to figure out how to insert the logic using Dataset Binding. I have written some VB.net programs to import data into the database where I coded data binding in the program code. This is my first Windows form project. I am trying to convert a MS Access application to VB or C# and move the data to a SQL Server. My company is moving away from MS Office for developing applications. The reason behind the migration is many of our MS Access apps developed issues when we upgraded all our computers to WIN10. VB/C# appear to be more stable platforms.

    Private Sub loaddate()
    
            Dim Str As String = "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\C# and VB Support\Example(VB)\Demo\Data3.mdf;Integrated Security=True"
            Dim sql As String = "update Test9 set column1=@date where Id=3"
            Dim dt As New DataTable
            Using con As New SqlConnection(Str)
                con.Open()
                Using cmd As New SqlCommand(sql, con)
    
                    If TextBox1.Text = "" Then
                        cmd.Parameters.AddWithValue("@date", DBNull.Value)
                    Else
                        Dim time As DateTime = Convert.ToDateTime(TextBox1.Text)
                        cmd.Parameters.AddWithValue("@date", time.ToString("HH:mm:ss"))
                    End If
                    'cmd.Parameters(0).IsNullable = True
                    cmd.ExecuteNonQuery()
                End Using
            End Using

    Tuesday, November 7, 2017 2:36 PM
  • Thanks again Karen, I see you have ran into the same road block I did "timespans must contain a valid time". I like your idea of changing the shift hours to a decimal 8.5 = 8:30. My solution just ended up converting it to decimal summing the total hours then converting it back to HH:MM for display. The sticking point is how to set the value to Null in the dataset and ultimately in the database. The reason this is important is less confusion on the users part.


    I would not consider any of the code I did road blocks. In regards to setting a value to null, I don' see that being an issues especially if the field is set to allow null values.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, November 7, 2017 2:43 PM
    Moderator
  • Thanks Karen of course your code is not the roadblock. I would really like to see your code for setting the Start_time to Null. That's the only challenge I have left, after I have set a start time to a valid time changing it back to NULL. Say for instance when a employee changes shifts or in one case the employee wanted to work Sun-Thr instead of Mon-Fri. Actually happens as we are a 24 hour shop and try to be flexible with employee schedules.    
    Tuesday, November 7, 2017 2:59 PM
  • Of course you're not the first one looking for this. Although I never used the Time Column Item, I know this problem from the DateTime column type. 

    Be aware that if the database table column item has no value (Null) then every .Net date or time control with set it to its default value. In this case being 00:00

    Therefore what you are searching for currently will probably in real live with a million users save you probably 2Mb, not really something to search for in my perception in 2017.

    Therefore the change that you find a real also for the end user working solution for this is probably zero.  

    https://docs.microsoft.com/en-us/sql/t-sql/data-types/time-transact-sql

    In the SQL server it can be "Null" be aware that this is a word which has many meanings in computing. 

    In .Net is for this used the DateTime Struct which never can be Nothing (Null (but something else than Null in SQL) in C languages).

    https://msdn.microsoft.com/en-us/library/system.datetime(v=vs.110).aspx


    Success
    Cor



    Tuesday, November 7, 2017 3:03 PM
  • Thanks Karen of course your code is not the roadblock. I would really like to see your code for setting the Start_time to Null. That's the only challenge I have left, after I have set a start time to a valid time changing it back to NULL. Say for instance when a employee changes shifts or in one case the employee wanted to work Sun-Thr instead of Mon-Fri. Actually happens as we are a 24 hour shop and try to be flexible with employee schedules.    

    I would have to get back to you later as I'm at work now with no enough time to provide a decent code sample.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, November 7, 2017 3:36 PM
    Moderator
  • Cor, Thank you for your input. Not to undermine your opinion but now we have a real world situation where this is needed. The lack of flexibility in Timespans might explain why there aren't a lot of scheduling programs on this platform. Actually the first link you posted gave me an idea. It suggested for platforms without Timespan using VarChar or Integer which can be mapped to a timespan looking Control. Or in this case using Cherry\Karen's Combo box storing a integer which can be mapped to the value field of the combo box. I knew conversion from text was possible as I had used it in my first attempt where I am stringing together text fields to populate a HH:MM MaskedTextbox.

       Private Sub HoursTextBox_Validating(sender As System.Object, e As System.ComponentModel.CancelEventArgs) _
                    Handles D01_HoursTextBox.Validating, D02_HoursTextBox.Validating, D03_HoursTextBox.Validating, D04_HoursTextBox.Validating,
                    D05_HoursTextBox.Validating, D06_HoursTextBox.Validating, D07_HoursTextBox.Validating, D08_HoursTextBox.Validating,
                    D09_HoursTextBox.Validating, D10_HoursTextBox.Validating, D11_HoursTextBox.Validating, D12_HoursTextBox.Validating,
                    D13_HoursTextBox.Validating, D14_HoursTextBox.Validating
    
            Dim Input As String = sender.Text
    
            If Input = "  :" Then
                GoTo Exit_Validate
            End If
    
            Dim Hours As Integer = Mid(Input, 1, 2)
            Dim Minutes As Integer = Mid(Input, 4, 2)
    
            If Hours > 12 Then
                MsgBox("Hours must be between 0 & 12")
            ElseIf Minutes > 60 Then
                MsgBox("Minutes are invalid")
            End If
    
            Sum_Hours()
    
    Exit_Validate:
    
        End Sub
    
    
    
    
    Private Sub Sum_Hours()
    
            Dim TextBoxes As New List(Of MaskedTextBox)
            Dim TotalHours As Decimal
            Dim TotalMin As Decimal
    
            TextBoxes.Add(D01_HoursTextBox)
            TextBoxes.Add(D02_HoursTextBox)
            TextBoxes.Add(D03_HoursTextBox)
            TextBoxes.Add(D04_HoursTextBox)
            TextBoxes.Add(D05_HoursTextBox)
            TextBoxes.Add(D06_HoursTextBox)
            TextBoxes.Add(D07_HoursTextBox)
            TextBoxes.Add(D08_HoursTextBox)
            TextBoxes.Add(D09_HoursTextBox)
            TextBoxes.Add(D10_HoursTextBox)
            TextBoxes.Add(D11_HoursTextBox)
            TextBoxes.Add(D12_HoursTextBox)
            TextBoxes.Add(D13_HoursTextBox)
            TextBoxes.Add(D14_HoursTextBox)
    
            For Each TB As MaskedTextBox In TextBoxes
                If TB.Text = "  :" Then
                    Continue For
                Else
                    Dim Hours As Integer = Mid(TB.Text, 1, 2)
                    Dim Minutes As Integer = Mid(TB.Text, 4, 2)
                    TotalHours += Hours
                    TotalMin += Minutes
                End If
            Next
    
            Dim Scheduled_Hours As Decimal = TotalHours + (TotalMin / 60)
            Dim dsp_Hours As String = Int(Scheduled_Hours)
            Dim dsp_Minttes As String = (Scheduled_Hours - Int(Scheduled_Hours)) * 60
    
            HoursTextBox.Text = dsp_Hours & ":" & dsp_Minttes
    
        End Sub

      

    Tuesday, November 7, 2017 3:36 PM
  • You seems to misunderstand me. I'm telling this from real live experience for end users. 

    Some persons want a blank data time controlbox if the end user has not used it. It is impossible to do, because the control set it always to default value as I already wrote.  

    However, I forgot that I've a solution for you on our website. 

    http://www.vb-tips.com/DataBindingEvents.aspx

    Your problem is how to set with this the checkbox to false, but I think you can manage that yourself. 


    Success
    Cor

    Tuesday, November 7, 2017 3:59 PM