Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, I have a question how can I convert the result of a multiplication into hh:mm:ss? This is the code
Public Class Form9
    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
        Dim nmpts As Integer
        If IsNumeric(nmpts) = True Then
            nmpts = TextBox1.Text
            If nmpts > 0 <= 6 Then
                Label5.Text = nmpts * 25
            ElseIf nmpts = 0 Then
                MsgBox("Only number! from 1 to 6", MessageBoxButtons.OK)
            End If
        End If
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Label5.Text = Label5.Text - 1
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Timer1.Start()
        Label5.Text = String.Format(Label5.Text, "hh\\:mm\\:ss")
    End Sub

    Private Sub Form9_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
End Class


What I have tried:

I tried this one
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      Timer1.Start()
      Label5.Text = String.Format(Label5.Text, "hh\\:mm\\:ss")
  End Sub
Posted
Updated 9-Jan-22 20:17pm

1 solution

OK. The first things is that you don't want to store a value in the textbox that you intend to use as a calculation - that's just a bad way to do things.
Instead, treat your "multiplication result" separate as hold it as an numeric value i.e. an Integer instead. That will be the "number of seconds" that you display from.

Then it's simple to display that number as hours, minutes and seconds: just use Modulus and Integer Divide.
VB
Private Function SecondsToHMS(ByVal value As Integer) As String
    Dim seconds As Integer = value Mod 60
    value = value \ 60
    Dim minutes As Integer = value Mod 60
    value = value \ 60
    Dim hours As Integer = value
    Return $"{hours:00}:{minutes:00}:{seconds:00}"
End Function
 
Share this answer
 
Comments
MXwell8 10-Jan-22 16:50pm    
For make the timer tick, do I need to put 3 timer and let that the first timer handle also the other two? because hours, minutes and second have a different intervals of time.
OriginalGriff 10-Jan-22 17:39pm    
Do you need three watches in order to tell the time?
No. If you count seconds, your can generate the minutes and hours from that: 61 seconds is 1 min and 1 sec, and so on...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900