Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: Gandalf on February 07, 2004, 11:02 PM

Title: Whats wrong with this?
Post by: Gandalf on February 07, 2004, 11:02 PM
Private Function ReturnDHMS(iSec1 As Single) As String
   
   Dim iMin As Single
   Dim iHrs As Single
   Dim iDay As Single
   Dim iSec As Single
   
   iSec = iSec1
   
   iHrs = (iMin \ 60)
   iMin = (iSec \ 60)
   iSec = (iSec Mod 60)
   
   If iHrs >= 24 Then
       iDay = iHrs \ 24
       iHrs = iHrs Mod 24
   End If
   
   ReturnDHMS = "Day:" & Str(iDay) & "  Hrs:" & Str(iHrs) & "  Min: " & Str(iMin) & "  Sec: " & Str(iSec)
   
End Function
Title: Re:Whats wrong with this?
Post by: UserLoser. on February 07, 2004, 11:04 PM
Isn't necessarly bot related, and you posted this somewhere else
Title: Re:Whats wrong with this?
Post by: Gandalf on February 07, 2004, 11:08 PM
Quote from: UserLoser. on February 07, 2004, 11:04 PM
Isn't necessarly bot related, and you posted this somewhere else
Well, im sure this can help some people doing some stuff related with bots and 2nd, if this isnt a Bot Related Topic why did u bother answering, if u going to answer u could help instead of telling people that they wrong. (When u get your own Forum Running i will do what u want me to do, but sorry this is not ur forum.)
Title: Re:Whats wrong with this?
Post by: Grok on February 07, 2004, 11:19 PM
Quote from: Gandalf on February 07, 2004, 11:02 PM
Private Function ReturnDHMS(iSec1 As Single) As String
   
   Dim iMin As Single
   Dim iHrs As Single
   Dim iDay As Single
   Dim iSec As Single
   
   iSec = iSec1
   
   iHrs = (iMin \ 60)
   iMin = (iSec \ 60)
   iSec = (iSec Mod 60)
   
   If iHrs >= 24 Then
       iDay = iHrs \ 24
       iHrs = iHrs Mod 24
   End If
   
   ReturnDHMS = "Day:" & Str(iDay) & "  Hrs:" & Str(iHrs) & "  Min: " & Str(iMin) & "  Sec: " & Str(iSec)
   
End Function

Why are you using integer division with Single operands?  Plus, what's your question?  You didn't state a problem.

Nevermind, I see the problem.  The value of iMin is still 0 when you're calculating iHrs.  Those lines are upside down.


Private Function ReturnDHMS(iSec1 As Single) As String
   
   Dim d As Long, h As Long, m As Long, s As Long
   
   s = iSec1 Mod 60&
   iSec1 = iSec1 - s
   m = (iSec1 Mod 3600&) \ 60&
   iSec1 = iSec1 - 60& * m
   h = (iSec1 Mod 86400) \ 3600&
   iSec1 = iSec1 - 3600& * h
   d = iSec1 \ 86400
   
   ReturnDHMS = "Days: " & Str(d) & "  Hrs:" & Str(h) & "  Min: " & Str(m) & "  Sec: " & Str(s)
   
End Function
Title: Re:Whats wrong with this?
Post by: iago on February 07, 2004, 11:50 PM
Quote from: Gandalf on February 07, 2004, 11:08 PM
Quote from: UserLoser. on February 07, 2004, 11:04 PM
Isn't necessarly bot related, and you posted this somewhere else
Well, im sure this can help some people doing some stuff related with bots and 2nd, if this isnt a Bot Related Topic why did u bother answering, if u going to answer u could help instead of telling people that they wrong. (When u get your own Forum Running i will do what u want me to do, but sorry this is not ur forum.)

you'll find you get more help if your polite.  Although he doesn't run the forum, UserLoser is a fairly respected regular here and knows the ropes.
Title: Re:Whats wrong with this?
Post by: MyndFyre on February 08, 2004, 02:42 AM
Two suggestions.

First, this code was already in another topic.  You only need to ask once; most of us who are here regularly read up on each topic when it's new -- at least glancing at it.

Second, when you post code, use the [ code ] and [ / code ] brackets to make it monotype and a different color:


Private Function ReturnDHMS(iSec1 As Single) As String
   
   Dim d As Long, h As Long, m As Long, s As Long
   
   s = iSec1 Mod 60&
   iSec1 = iSec1 - s
   m = (iSec1 Mod 3600&) \ 60&
   iSec1 = iSec1 - 60& * m
   h = (iSec1 Mod 86400) \ 3600&
   iSec1 = iSec1 - 3600& * h
   d = iSec1 \ 86400
   
   ReturnDHMS = "Days: " & Str(d) & "  Hrs:" & Str(h) & "  Min: " & Str(m) & "  Sec: " & Str(s)
   
End Function

(Grok's correct code)

I believe these guidelines are in the forum rules, and it's more or less courteous and customary to post this way.

Anyway, if you want to continue to take advantage of the expertise and willingness to help here, I'd suggest you follow suit.  As iago pointed out, people like UserLoser, who really know what they're doing, are much more apt to really help you out if you follow the guidelines set forth by the people who run the forums.

And - to complete UserLoser's suggestion - this would be a really great topic for the Visual Basic forum.

Cheers
Title: Re:Whats wrong with this?
Post by: Grok on February 08, 2004, 04:39 AM
This also works:


Private Function ReturnDHMS(iSec1 As Single) As String
   
   Dim d As Long, h As Long, m As Long, s As Long
   
   s = iSec1 Mod 60&
   m = (iSec1 \ 60) Mod 60
   h = (iSec1 \ 3600) Mod 24
   d = iSec1 \ 86400
   
   ReturnDHMS = "Days: " & Str(d) & "  Hrs:" & Str(h) & "  Min: " & Str(m) & "  Sec: " & Str(s)
   
End Function
Title: Re:Whats wrong with this?
Post by: Gandalf on February 08, 2004, 08:55 AM
Well,  sorry, i wont post any not related post in this topic, and thnx for the code.