Android Question [SOLVED] Trying to convert seconds into minutes.

LWGShane

Well-Known Member
Licensed User
Longtime User
I'm creating an app that deals with converting seconds into minutes, for Pikmin 3's Mission Mode.

Basically, I take a score, subtract the default score of a level then divide by 30 points per second to get the time remaining in seconds.

Ex: The top score for the "Tropical Forest" level is 8800. It's The level's default score is 2110. 8800 - 2110 is 6690. 6690 divided by 30 points per second is 223 seconds, which turns out to be 3 minutes and 43 seconds.

I cannot seem to convert 223 to 3 minutes and 43 seconds. Below is my code.

B4X:
Sub CalculateTime (Score As String, Level As String)

    'Declares neccessary components.
    Dim TimeBonus As String
    Dim FinalScore As String
    Dim BeatIn As String  
  
    If Score = "" Then
        Msgbox ("Please enter a score!", "Error: Empty Score")
        Log("Empty Score Detected")
    Else If Level = "" Then
        Msgbox ("Please select a level!", "Error: Empty Level")
        Log("No Level Selected")
    End If

    If Level = "Tropical Forest" Then
        If Score < 2110 Then
            Msgbox ("Score is too low", "Score Error")
            Log("Too low of a score detected")
        Else
            FinalScore = Score - 2110
            TimeBonus = FinalScore / 30
            BeatIn = TimeBonus / 60
            If TimeBonus Mod 60 > 0 Then
                BeatIn = BeatIn + 1
                Msgbox (BeatIn, "Beat Tropical Forest In")
            End If
            Log("Calculated time needed to beat level")
        End If
    End If

End Sub

Thanks for the help!
 

udg

Expert
Licensed User
Longtime User
Hi,

maybe you can try this:
B4X:
Dim minutes as Int
minutes = TimeBonus / 60 
if TimeBonus mod 60 >0 then minutes = minutes +1
BeatIn = minutes

Umberto
 
Upvote 0

LWGShane

Well-Known Member
Licensed User
Longtime User
@udg :
Thanks!

@sirjo66 :
Thanks for the code. It does exactly what I want it to do! Now off to make my code more efficient.

Once again, thanks for the wonderful help! This is an extremely helpful community.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…