0

I have a textbox linked to a scrollbar so that when the scrollbar is scrolled to the right it scrolls from 0 to 1440(interval = 1), which is then converted from minutes to a timespan, this timespan is then displayed the textbox, strange thing is, I can only scroll up to 23:51(1431 scrollbar.value) according to the textbox.text

Also,

When I change the time in the textbox to 24:00 it changed it automatically to 0:0 which is not what I want as it is misleading. the time on the left side of the scrollbar is already 0:0. So I'd really prefer for it to say 24:00 instead.

This is the code im currently using. I'm assuming some of the problems are caused by the textbox triggering the scrollbar and the scrollbar triggering the textbox.

    'UPDATE TBtstsStart when scrollbar is used
Private Sub SBtstStart_ValueChanged(sender As Object, e As EventArgs) Handles SBtstStart.ValueChanged
    Dim time As TimeSpan = New TimeSpan(0, CInt(SBtstStart.Value), 0)
    TBtstStart.Text = time.Hours & ":" & time.Minutes
End Sub

'UPDATE SBtstStart when textbox is left
Private Sub TBtstStart_Leave(sender As Object, e As EventArgs) Handles TBtstStart.Leave
    Dim strarr() As String = TBtstStart.Text.Split(CChar(":"))
    SBtstStart.Value = (CInt(strarr(0)) * 60) + CInt(strarr(1))
End Sub
WouldBeNerd
  • 629
  • 11
  • 29
  • I did something similar recently trying to make a `TimeSpanUpDown` and the scrollbar was a nightmare to work with. the range needs to be -1431 to 0 so that up and down match the action. Increments were a pain as well as Large/Small change. For what you are asking though, 24h 0m == 1 Day so the TS rolls over. – Ňɏssa Pøngjǣrdenlarp Oct 23 '14 at 16:21
  • Thanks for the reply apparently I needed the max value of my horizontal scroll bar to be 1453 (I think its caused by the space that is taken up by the left and right controls on the scroll bar), this makes it so that I can scroll to 23:59 which is actually safer imo, stops people from selecting the morning of the same day by accident. They can still manually type 24:00 which will convert it to 00:00. I'm just going to live with it for now. I have DateTimePicker to set the date, so I might make that turn over to next day when someone enters 24:00 somehow. – WouldBeNerd Oct 24 '14 at 09:01
  • Instead of a scroll bar, you might want to use a TrackBar for this purpose. – Chris Dunaway Oct 24 '14 at 15:42

0 Answers0