Adblock breaks this site

converting mins and secs

Discussion in 'Programming General' started by X Zero, Apr 13, 2007.

  1. X Zero

    X Zero Forum Addict

    Joined:
    Jan 21, 2007
    Posts:
    577
    Referrals:
    0
    Sythe Gold:
    0
    converting mins and secs

    ok how would i be able to convert 125 seconds into 2:05
     
  2. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    converting mins and secs

    Ill post how to do it in VB6, i think you should be able to convert it, or someone else here should be able to ;)

    do something like this with your timer: (yes....a timer :( )
    Code:
    Dim tMin As Single, tSec As Single
    
    Private Sub Timer1_Timer()
        Dim dSec As String, dMin As String
        tSec = tSec + 1
        If tSec = 60 Then
            tSec = 0
            tMin = tMin + 1
        End If
        If tSec < 10 Then
            dSec = 0 & tSec
        Else
            dSec = tSec
        End If
        If tMin < 10 Then
            dMin = 0 & tMin
        Else
            dMin = tMin
        End If
        Label1.Caption = dMin & ":" & dSec
    End Sub
     
  3. X Zero

    X Zero Forum Addict

    Joined:
    Jan 21, 2007
    Posts:
    577
    Referrals:
    0
    Sythe Gold:
    0
    converting mins and secs

    Yer, it helped but still not solve. It needs to count down

    and find how many minutes and seconds go into 125 seconds
     
  4. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    converting mins and secs

    hmm try this, its a shit way of doing it (once again in vb6).
    Create a form chuck a textbox and a command button on and add this code to the command button.
    Code:
    Dim Hold As String
        Dim tMin As Double
        Dim tHold As Double
        Dim tSec As Double
        Dim DisplaySeconds As String
        Dim DisplayMinutes As String
        Hold = Val(Text1)
        tMin = Round(Val(Hold) / 60, 3)
        tHold = Round(tMin, 0)
        If InStr(1, tSec, ".") = 0 Then
            tSec = 0
        Else
            tSec = Split(tMin, tHold)(1)
            tSec = Round(tSec * 60)
        End If
        If tSec < 10 Then
            DisplaySeconds = "0" & tSec
        Else
            DisplaySeconds = tSec
        End If
        If tHold < 10 Then
            DisplayMinutes = "0" & tHold
        Else
            DisplayMinutes = tHold
        End If
        Text1 = DisplayMinutes & ":" & DisplaySeconds
    It rounds up, so if you using a bug number like 10000, it may be off like 5 seconds or something. but you should be able to iron that out.
     
  5. dodge

    dodge Active Member
    Banned

    Joined:
    Mar 26, 2007
    Posts:
    125
    Referrals:
    1
    Sythe Gold:
    5
    converting mins and secs

    two things 125 secs is not 2:05 is 2:08 and this is how you would do it in .net

    Dim Interval As TimeSpan = New TimeSpan(125) '125 is the seconds you have
    Console.WriteLine(Interval.TotalMinutes())
     
  6. X Zero

    X Zero Forum Addict

    Joined:
    Jan 21, 2007
    Posts:
    577
    Referrals:
    0
    Sythe Gold:
    0
    converting mins and secs

    Wtf?????

    Thanks anyway
     
  7. Cheeter

    Cheeter Grand Master
    Cheetah Retired Global Moderator

    Joined:
    Jun 5, 2005
    Posts:
    3,851
    Referrals:
    1
    Sythe Gold:
    31
    Discord Unique ID:
    236215891849641985
    Discord Username:
    Charkel#8050
    Extreme Homosex Homosex
    converting mins and secs

    60 + 60 + 5 = 125?....
     
  8. X Zero

    X Zero Forum Addict

    Joined:
    Jan 21, 2007
    Posts:
    577
    Referrals:
    0
    Sythe Gold:
    0
    converting mins and secs

    WOO, got it
    Thank Guys and or girls :)

    Declarations
    Code:
     Dim tMin As Single, tSec As Single 
    The Converter

    Code:
            Dim total = 1000
            Dim Min = total \ 60
            Dim sec = total - (Min * 60)
    
            If sec < 10 Then
                sec = 0 & sec
            Else
                sec = sec
            End If
            If Min < 10 Then
                Min = 0 & Min
            Else
                Min = Min
            End If
            tSec = sec
            tMin = Min
    Count down

    Code:
            Dim dSec As String, dMin As String
            tSec = tSec - 1
            If tSec = 0 Then
                tSec = 59
                tMin = tMin - 1
            End If
            If tSec < 10 Then
                dSec = 0 & tSec
            Else
                dSec = tSec
            End If
            If tMin < 10 Then
                dMin = 0 & tMin
            Else
                dMin = tMin
            End If
            Label1.Text = dMin & ":" & dSec
     
  9. dodge

    dodge Active Member
    Banned

    Joined:
    Mar 26, 2007
    Posts:
    125
    Referrals:
    1
    Sythe Gold:
    5
    converting mins and secs

    too much code again NOT .net

    use this

    Dim Interval As TimeSpan = TimeSpan.FromSeconds(125)

    Console.WriteLine(Interval.Hours)
    Console.WriteLine(Interval.Minutes)
    Console.WriteLine(Interval.Seconds)
    Console.WriteLine(Interval.ToString())
     
< Need a prof help in C++ | Just a question new at this... >


 
 
Adblock breaks this site